Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
80c3581d
Commit
80c3581d
authored
May 09, 2019
by
Tobias Meuser
Browse files
Necessary extensions for remote control via REST
parent
a5d75bcd
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/scenario/DefaultConfigurator.java
View file @
80c3581d
...
...
@@ -37,6 +37,7 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
javax.sound.midi.Synthesizer
;
import
javax.xml.parsers.ParserConfigurationException
;
import
javax.xml.parsers.SAXParser
;
import
javax.xml.parsers.SAXParserFactory
;
...
...
@@ -282,9 +283,7 @@ public class DefaultConfigurator implements Configurator {
}
else
if
(
elem
.
getName
().
equals
(
Configurator
.
DEFAULT_TAG
))
{
configureDefaults
(
elem
);
}
else
{
if
(!
_parseOnly
)
{
configureComponent
(
elem
);
}
configureComponent
(
elem
);
}
}
}
...
...
@@ -321,7 +320,6 @@ public class DefaultConfigurator implements Configurator {
* @return configured component
*/
public
Object
configureComponent
(
Element
elem
)
{
String
name
=
elem
.
getName
();
if
(
Configurator
.
SPECIAL_IF_EQUAL_STR
.
equalsIgnoreCase
(
name
))
{
processIfEqualStr
(
elem
,
new
ToConfigureCallback
()
{
...
...
@@ -358,46 +356,55 @@ public class DefaultConfigurator implements Configurator {
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
DEBUG
,
"Configure component "
+
name
);
/*
* FIXED (BR) - if a component specifies a class-tag, do NOT reuse the
* old component for configuration. Instead, create a new component.
*/
// Constructor Attributes
Object
component
=
configurables
.
get
(
name
);
Set
<
String
>
consAttrs
=
new
HashSet
<
String
>();
String
clazz
=
getAttributeValue
(
elem
.
attribute
(
CLASS_TAG
));
if
(
clazz
!=
null
)
{
// Create component
component
=
createComponent
(
elem
,
consAttrs
);
}
// configure it
if
(
component
!=
null
)
{
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
INFO
,
"Configure component "
+
component
.
getClass
().
getSimpleName
()
+
" with element "
+
name
);
configureAttributes
(
component
,
elem
,
consAttrs
);
// configure subcomponents
if
(
component
instanceof
Builder
)
{
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
INFO
,
"Configure builder "
+
component
);
Builder
builder
=
(
Builder
)
component
;
builder
.
parse
(
elem
,
this
);
}
else
{
for
(
Iterator
iter
=
elem
.
elementIterator
();
iter
.
hasNext
();)
{
Element
child
=
(
Element
)
iter
.
next
();
if
(!
consAttrs
.
contains
(
child
.
getName
().
toLowerCase
()))
{
processChild
(
component
,
child
,
consAttrs
);
}
}
}
if
(!
_parseOnly
)
{
/*
* FIXED (BR) - if a component specifies a class-tag, do NOT reuse the
* old component for configuration. Instead, create a new component.
*/
// Constructor Attributes
Object
component
=
configurables
.
get
(
name
);
Set
<
String
>
consAttrs
=
new
HashSet
<
String
>();
String
clazz
=
getAttributeValue
(
elem
.
attribute
(
CLASS_TAG
));
if
(
clazz
!=
null
)
{
// Create component
component
=
createComponent
(
elem
,
consAttrs
);
}
// configure it
if
(
component
!=
null
)
{
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
INFO
,
"Configure component "
+
component
.
getClass
().
getSimpleName
()
+
" with element "
+
name
);
configureAttributes
(
component
,
elem
,
consAttrs
);
// configure subcomponents
if
(
component
instanceof
Builder
)
{
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
INFO
,
"Configure builder "
+
component
);
Builder
builder
=
(
Builder
)
component
;
builder
.
parse
(
elem
,
this
);
}
else
{
for
(
Iterator
iter
=
elem
.
elementIterator
();
iter
.
hasNext
();)
{
Element
child
=
(
Element
)
iter
.
next
();
if
(!
consAttrs
.
contains
(
child
.
getName
().
toLowerCase
()))
{
processChild
(
component
,
child
,
consAttrs
);
}
}
}
}
else
{
// component cannot be created and has not been registered
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
WARN
,
"Skip element "
+
name
);
}
return
component
;
}
else
{
// component cannot be created and has not been registered
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
WARN
,
"Skip element "
+
name
);
for
(
Iterator
iter
=
elem
.
elementIterator
();
iter
.
hasNext
();)
{
Element
child
=
(
Element
)
iter
.
next
();
processChild
(
null
,
child
,
null
);
}
return
null
;
}
return
component
;
}
private
Object
createComponent
(
Element
elem
,
Set
<
String
>
consAttrs
)
{
...
...
@@ -466,42 +473,44 @@ public class DefaultConfigurator implements Configurator {
Object
subcomponent
=
configureComponent
(
child
);
String
prefix
=
SET_METHOD_PREFIX_TAG
;
String
methodName
=
getMethodName
(
prefix
,
child
.
getName
());
Method
[]
methods
=
component
.
getClass
().
getMethods
();
Method
match
=
null
;
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
if
(
methodName
.
equals
(
methods
[
i
].
getName
()))
{
match
=
methods
[
i
];
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
DEBUG
,
"Match "
+
match
);
break
;
}
}
if
(
match
==
null
)
{
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
WARN
,
"Cannot set "
+
subcomponent
+
" as there is no method "
+
methodName
+
" declared in "
+
component
);
throw
new
ConfigurationException
(
"Cannot set "
+
subcomponent
+
" as there is no method "
+
methodName
+
" declared in "
+
component
);
}
else
{
Class
[]
types
=
match
.
getParameterTypes
();
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
DEBUG
,
"Param types"
+
Arrays
.
asList
(
types
));
if
(
types
.
length
==
1
)
{
try
{
match
.
invoke
(
component
,
types
[
0
].
cast
(
subcomponent
));
}
catch
(
Exception
e
)
{
throw
new
ConfigurationException
(
"Failed to configure "
+
methodName
+
" in "
+
component
+
" with "
+
subcomponent
,
e
);
}
}
else
{
throw
new
ConfigurationException
(
"Wrong number of params for "
+
methodName
+
" in "
+
component
);
}
if
(!
_parseOnly
)
{
String
prefix
=
SET_METHOD_PREFIX_TAG
;
String
methodName
=
getMethodName
(
prefix
,
child
.
getName
());
Method
[]
methods
=
component
.
getClass
().
getMethods
();
Method
match
=
null
;
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
if
(
methodName
.
equals
(
methods
[
i
].
getName
()))
{
match
=
methods
[
i
];
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
DEBUG
,
"Match "
+
match
);
break
;
}
}
if
(
match
==
null
)
{
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
WARN
,
"Cannot set "
+
subcomponent
+
" as there is no method "
+
methodName
+
" declared in "
+
component
);
throw
new
ConfigurationException
(
"Cannot set "
+
subcomponent
+
" as there is no method "
+
methodName
+
" declared in "
+
component
);
}
else
{
Class
[]
types
=
match
.
getParameterTypes
();
Monitor
.
log
(
DefaultConfigurator
.
class
,
Level
.
DEBUG
,
"Param types"
+
Arrays
.
asList
(
types
));
if
(
types
.
length
==
1
)
{
try
{
match
.
invoke
(
component
,
types
[
0
].
cast
(
subcomponent
));
}
catch
(
Exception
e
)
{
throw
new
ConfigurationException
(
"Failed to configure "
+
methodName
+
" in "
+
component
+
" with "
+
subcomponent
,
e
);
}
}
else
{
throw
new
ConfigurationException
(
"Wrong number of params for "
+
methodName
+
" in "
+
component
);
}
}
}
}
...
...
@@ -739,6 +748,9 @@ public class DefaultConfigurator implements Configurator {
if
(
staticMethod
==
null
)
{
Constructor
[]
cs
=
forName
.
getConstructors
();
Constructor
currentConstructor
=
null
;
String
[]
usedArgs
=
null
;
Object
[]
parameters
=
null
;
for
(
Constructor
<?>
c
:
cs
)
{
XMLConfigurableConstructor
a
=
c
...
...
@@ -789,16 +801,23 @@ public class DefaultConfigurator implements Configurator {
}
if
(!
incompatible
)
{
component
=
c
.
newInstance
(
consArgs
);
for
(
String
consAttr
:
cArgs
)
{
consAttrs
.
add
(
consAttr
.
toLowerCase
());
}
break
;
if
(
currentConstructor
==
null
||
parameters
.
length
<
consArgs
.
length
)
{
currentConstructor
=
c
;
parameters
=
consArgs
;
usedArgs
=
cArgs
;
}
}
}
}
if
(
currentConstructor
!=
null
)
{
component
=
currentConstructor
.
newInstance
(
parameters
);
for
(
String
consAttr
:
usedArgs
)
{
consAttrs
.
add
(
consAttr
.
toLowerCase
());
}
}
if
(
component
==
null
)
component
=
forName
.
newInstance
();
...
...
src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
View file @
80c3581d
...
...
@@ -25,6 +25,7 @@ import java.util.HashMap;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
javax.persistence.EntityManager
;
...
...
@@ -32,11 +33,13 @@ import javax.persistence.EntityManagerFactory;
import
javax.persistence.Persistence
;
import
org.apache.commons.math3.analysis.function.Exp
;
import
org.hibernate.Criteria
;
import
org.hibernate.HibernateException
;
import
org.hibernate.Session
;
import
org.hibernate.SessionFactory
;
import
org.hibernate.boot.registry.StandardServiceRegistryBuilder
;
import
org.hibernate.cfg.Configuration
;
import
org.hibernate.criterion.Restrictions
;
import
org.hibernate.service.ServiceRegistry
;
import
org.omg.CORBA.CustomMarshal
;
...
...
@@ -186,7 +189,7 @@ public class DAO {
if
(!
WebConfigurationManager
.
isActive
())
{
database
=
pDatabase
;
}
else
{
database
=
WebConfigurationManager
.
getConfig
().
getOptions
().
getDatabase
();
database
=
WebConfigurationManager
.
getConfig
().
getOptions
().
getDatabase
()
.
getDatabase
()
;
}
}
...
...
@@ -194,7 +197,7 @@ public class DAO {
if
(!
WebConfigurationManager
.
isActive
())
{
username
=
pUsername
;
}
else
{
username
=
WebConfigurationManager
.
getConfig
().
getOptions
().
getUsername
();
username
=
WebConfigurationManager
.
getConfig
().
getOptions
().
getDatabase
().
getUsername
();
}
}
...
...
@@ -202,7 +205,7 @@ public class DAO {
if
(!
WebConfigurationManager
.
isActive
())
{
password
=
pPassword
;
}
else
{
password
=
WebConfigurationManager
.
getConfig
().
getOptions
().
getPassword
();
password
=
WebConfigurationManager
.
getConfig
().
getOptions
().
getDatabase
().
getPassword
();
}
}
...
...
@@ -313,13 +316,14 @@ public class DAO {
DAO
.
session
.
remove
();
}
public
static
List
<
Object
>
retrieve
(
Class
<?>
pClass
)
{
begin
();
List
<
Object
>
objects
=
getSession
().
createCriteria
(
pClass
).
list
();
commit
();
public
static
<
T
extends
Object
>
List
<
T
>
retrieve
(
Class
<
T
>
pClass
)
{
begin
();
Criteria
criteria
=
getSession
().
createCriteria
(
pClass
);
List
<
T
>
objects
=
criteria
.
list
();
commit
();
return
objects
;
}
return
objects
;
}
/**
* Persist the given POJO directly to the DB. Should be make, if it exists
...
...
src/de/tud/kom/p2psim/impl/util/db/dao/metric/ExperimentDAO.java
View file @
80c3581d
...
...
@@ -25,6 +25,10 @@ import java.util.LinkedHashMap;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.hibernate.Criteria
;
import
org.hibernate.criterion.Restrictions
;
import
de.tud.kom.p2psim.impl.simengine.Simulator
;
import
de.tud.kom.p2psim.impl.util.db.dao.DAO
;
...
...
@@ -85,6 +89,22 @@ public class ExperimentDAO extends DAO {
return
experiment
;
}
public
static
Experiment
retrieveExperiment
(
long
pSeed
,
Map
<
String
,
String
>
pVariables
)
{
begin
();
Criteria
criteria
=
getSession
().
createCriteria
(
Experiment
.
class
);
criteria
=
criteria
.
add
(
Restrictions
.
eq
(
"seed"
,
pSeed
));
for
(
Entry
<
String
,
String
>
entry
:
pVariables
.
entrySet
())
{
criteria
=
criteria
.
add
(
Restrictions
.
like
(
"workload"
,
"%"
+
entry
.
getKey
()
+
"="
+
entry
.
getValue
()
+
"%"
));
}
List
<
Experiment
>
experiments
=
criteria
.
list
();
commit
();
if
(
experiments
.
size
()
>
0
)
{
return
experiments
.
get
(
experiments
.
size
()
-
1
);
}
return
null
;
}
/** Called by the {@link Time} when the simulation is shut down. */
public
static
void
simulationFinished
()
{
// If there is no experiment object, no measurements have been made,
...
...
src/de/tud/kom/p2psim/impl/util/db/dao/metric/MetricDAO.java
View file @
80c3581d
package
de.tud.kom.p2psim.impl.util.db.dao.metric
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.hibernate.Criteria
;
import
org.hibernate.criterion.Restrictions
;
import
de.tud.kom.p2psim.impl.util.Tuple
;
import
de.tud.kom.p2psim.impl.util.db.dao.DAO
;
import
de.tud.kom.p2psim.impl.util.db.metric.Experiment
;
import
de.tud.kom.p2psim.impl.util.db.metric.Metric
;
import
de.tud.kom.p2psim.impl.util.db.metric.MetricDescription
;
...
...
@@ -53,6 +59,21 @@ public class MetricDAO extends DAO {
}
}
public
static
List
<
Metric
>
getMetricsForExperiment
(
int
pExperimentID
)
{
begin
();
Criteria
criteria
=
getSession
().
createCriteria
(
Experiment
.
class
);
if
(
pExperimentID
!=
-
1
)
{
criteria
=
criteria
.
add
(
Restrictions
.
eq
(
"experimentID"
,
pExperimentID
));
}
List
<
Metric
>
metrics
=
criteria
.
list
();
commit
();
return
metrics
;
}
public
List
<
Metric
>
getMetrics
()
{
return
getMetricsForExperiment
(-
1
);
}
/** Retrieve a {@link Metric} object for the given MetricDescription
* for single value metrics.
*
...
...
@@ -62,7 +83,7 @@ public class MetricDAO extends DAO {
public
static
Metric
lookupSingleMetric
(
MetricDescription
metricDesc
)
{
return
lookupMetric
(
metricDesc
,
MetricType
.
SINGLE
);
}
/** Retrieve a {@link Metric} object for the given MetricDescription
* for spatial value metrics.
*
...
...
@@ -86,7 +107,7 @@ public class MetricDAO extends DAO {
/**
* Retrieve a {@link Metric} object for the given MetricDescription for pair
* list metrics.
*
*
* If there is no matching Metric object, it is created, persisted, and
* cached automatically.
*/
...
...
src/de/tud/kom/p2psim/impl/util/db/metric/Metric.java
View file @
80c3581d
...
...
@@ -152,6 +152,14 @@ public class Metric {
return
true
;
}
public
String
getName
()
{
return
name
;
}
public
String
getComment
()
{
return
comment
;
}
@Override
public
String
toString
()
{
return
"Metric{"
+
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment