Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theodolite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Commits
b95c89fa
Commit
b95c89fa
authored
5 years ago
by
Sören Henning
Browse files
Options
Downloads
Patches
Plain Diff
Fix code indentation
parent
b86ba381
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uc2-workload-generator/src/main/java/uc2/workloadGenerator/LoadGenerator.java
+83
-74
83 additions, 74 deletions
...or/src/main/java/uc2/workloadGenerator/LoadGenerator.java
with
83 additions
and
74 deletions
uc2-workload-generator/src/main/java/uc2/workloadGenerator/LoadGenerator.java
+
83
−
74
View file @
b95c89fa
...
...
@@ -18,90 +18,99 @@ import titan.ccp.models.records.ActivePowerRecord;
public
class
LoadGenerator
{
public
static
void
main
(
final
String
[]
args
)
throws
InterruptedException
,
IOException
{
public
static
void
main
(
final
String
[]
args
)
throws
InterruptedException
,
IOException
{
final
String
hierarchy
=
Objects
.
requireNonNullElse
(
System
.
getenv
(
"HIERARCHY"
),
"deep"
);
final
int
numNestedGroups
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"NUM_NESTED_GROUPS"
),
"1"
));
final
int
numSensor
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"NUM_SENSORS"
),
"1"
));
final
int
periodMs
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"PERIOD_MS"
),
"1000"
));
final
int
value
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"VALUE"
),
"10"
));
final
boolean
sendRegistry
=
Boolean
.
parseBoolean
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"SEND_REGISTRY"
),
"true"
));
final
int
threads
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"THREADS"
),
"4"
));
final
String
kafkaBootstrapServers
=
Objects
.
requireNonNullElse
(
System
.
getenv
(
"KAFKA_BOOTSTRAP_SERVERS"
),
"localhost:9092"
);
final
String
kafkaInputTopic
=
Objects
.
requireNonNullElse
(
System
.
getenv
(
"KAFKA_INPUT_TOPIC"
),
"input"
);
final
String
kafkaBatchSize
=
System
.
getenv
(
"KAFKA_BATCH_SIZE"
);
final
String
kafkaLingerMs
=
System
.
getenv
(
"KAFKA_LINGER_MS"
);
final
String
kafkaBufferMemory
=
System
.
getenv
(
"KAFKA_BUFFER_MEMORY"
);
final
String
hierarchy
=
Objects
.
requireNonNullElse
(
System
.
getenv
(
"HIERARCHY"
),
"deep"
);
final
int
numNestedGroups
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"NUM_NESTED_GROUPS"
),
"1"
));
final
int
numSensor
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"NUM_SENSORS"
),
"1"
));
final
int
periodMs
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"PERIOD_MS"
),
"1000"
));
final
int
value
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"VALUE"
),
"10"
));
final
boolean
sendRegistry
=
Boolean
.
parseBoolean
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"SEND_REGISTRY"
),
"true"
));
final
int
threads
=
Integer
.
parseInt
(
Objects
.
requireNonNullElse
(
System
.
getenv
(
"THREADS"
),
"4"
));
final
String
kafkaBootstrapServers
=
Objects
.
requireNonNullElse
(
System
.
getenv
(
"KAFKA_BOOTSTRAP_SERVERS"
),
"localhost:9092"
);
final
String
kafkaInputTopic
=
Objects
.
requireNonNullElse
(
System
.
getenv
(
"KAFKA_INPUT_TOPIC"
),
"input"
);
final
String
kafkaBatchSize
=
System
.
getenv
(
"KAFKA_BATCH_SIZE"
);
final
String
kafkaLingerMs
=
System
.
getenv
(
"KAFKA_LINGER_MS"
);
final
String
kafkaBufferMemory
=
System
.
getenv
(
"KAFKA_BUFFER_MEMORY"
);
final
MutableSensorRegistry
sensorRegistry
=
new
MutableSensorRegistry
(
"group_lvl_0"
);
if
(
hierarchy
.
equals
(
"deep"
))
{
MutableAggregatedSensor
lastSensor
=
sensorRegistry
.
getTopLevelSensor
();
for
(
int
lvl
=
1
;
lvl
<
numNestedGroups
;
lvl
++)
{
lastSensor
=
lastSensor
.
addChildAggregatedSensor
(
"group_lvl_"
+
lvl
);
}
for
(
int
s
=
0
;
s
<
numSensor
;
s
++)
{
lastSensor
.
addChildMachineSensor
(
"sensor_"
+
s
);
}
}
else
if
(
hierarchy
.
equals
(
"full"
))
{
addChildren
(
sensorRegistry
.
getTopLevelSensor
(),
numSensor
,
1
,
numNestedGroups
,
0
);
}
else
{
throw
new
IllegalStateException
();
}
final
MutableSensorRegistry
sensorRegistry
=
new
MutableSensorRegistry
(
"group_lvl_0"
);
if
(
hierarchy
.
equals
(
"deep"
))
{
MutableAggregatedSensor
lastSensor
=
sensorRegistry
.
getTopLevelSensor
();
for
(
int
lvl
=
1
;
lvl
<
numNestedGroups
;
lvl
++)
{
lastSensor
=
lastSensor
.
addChildAggregatedSensor
(
"group_lvl_"
+
lvl
);
}
for
(
int
s
=
0
;
s
<
numSensor
;
s
++)
{
lastSensor
.
addChildMachineSensor
(
"sensor_"
+
s
);
}
}
else
if
(
hierarchy
.
equals
(
"full"
))
{
addChildren
(
sensorRegistry
.
getTopLevelSensor
(),
numSensor
,
1
,
numNestedGroups
,
0
);
}
else
{
throw
new
IllegalStateException
();
}
final
List
<
String
>
sensors
=
sensorRegistry
.
getMachineSensors
().
stream
().
map
(
s
->
s
.
getIdentifier
())
.
collect
(
Collectors
.
toList
());
final
List
<
String
>
sensors
=
sensorRegistry
.
getMachineSensors
().
stream
().
map
(
s
->
s
.
getIdentifier
())
.
collect
(
Collectors
.
toList
());
if
(
sendRegistry
)
{
final
ConfigPublisher
configPublisher
=
new
ConfigPublisher
(
kafkaBootstrapServers
,
"configuration"
);
configPublisher
.
publish
(
Event
.
SENSOR_REGISTRY_CHANGED
,
sensorRegistry
.
toJson
());
configPublisher
.
close
();
System
.
out
.
println
(
"Configuration sent."
);
if
(
sendRegistry
)
{
final
ConfigPublisher
configPublisher
=
new
ConfigPublisher
(
kafkaBootstrapServers
,
"configuration"
);
configPublisher
.
publish
(
Event
.
SENSOR_REGISTRY_CHANGED
,
sensorRegistry
.
toJson
());
configPublisher
.
close
();
System
.
out
.
println
(
"Configuration sent."
);
System
.
out
.
println
(
"Now wait 30 seconds"
);
Thread
.
sleep
(
30_000
);
System
.
out
.
println
(
"And woke up again :)"
);
}
System
.
out
.
println
(
"Now wait 30 seconds"
);
Thread
.
sleep
(
30_000
);
System
.
out
.
println
(
"And woke up again :)"
);
}
final
Properties
kafkaProperties
=
new
Properties
();
// kafkaProperties.put("acks", this.acknowledges);
kafkaProperties
.
compute
(
ProducerConfig
.
BATCH_SIZE_CONFIG
,
(
k
,
v
)
->
kafkaBatchSize
);
kafkaProperties
.
compute
(
ProducerConfig
.
LINGER_MS_CONFIG
,
(
k
,
v
)
->
kafkaLingerMs
);
kafkaProperties
.
compute
(
ProducerConfig
.
BUFFER_MEMORY_CONFIG
,
(
k
,
v
)
->
kafkaBufferMemory
);
final
KafkaRecordSender
<
ActivePowerRecord
>
kafkaRecordSender
=
new
KafkaRecordSender
<>(
kafkaBootstrapServers
,
kafkaInputTopic
,
r
->
r
.
getIdentifier
(),
r
->
r
.
getTimestamp
(),
kafkaProperties
);
final
Properties
kafkaProperties
=
new
Properties
();
// kafkaProperties.put("acks", this.acknowledges);
kafkaProperties
.
compute
(
ProducerConfig
.
BATCH_SIZE_CONFIG
,
(
k
,
v
)
->
kafkaBatchSize
);
kafkaProperties
.
compute
(
ProducerConfig
.
LINGER_MS_CONFIG
,
(
k
,
v
)
->
kafkaLingerMs
);
kafkaProperties
.
compute
(
ProducerConfig
.
BUFFER_MEMORY_CONFIG
,
(
k
,
v
)
->
kafkaBufferMemory
);
final
KafkaRecordSender
<
ActivePowerRecord
>
kafkaRecordSender
=
new
KafkaRecordSender
<>(
kafkaBootstrapServers
,
kafkaInputTopic
,
r
->
r
.
getIdentifier
(),
r
->
r
.
getTimestamp
(),
kafkaProperties
);
final
ScheduledExecutorService
executor
=
Executors
.
newScheduledThreadPool
(
threads
);
final
Random
random
=
new
Random
();
final
ScheduledExecutorService
executor
=
Executors
.
newScheduledThreadPool
(
threads
);
final
Random
random
=
new
Random
();
for
(
final
String
sensor
:
sensors
)
{
final
int
initialDelay
=
random
.
nextInt
(
periodMs
);
executor
.
scheduleAtFixedRate
(()
->
{
kafkaRecordSender
.
write
(
new
ActivePowerRecord
(
sensor
,
System
.
currentTimeMillis
(),
value
));
},
initialDelay
,
periodMs
,
TimeUnit
.
MILLISECONDS
);
}
for
(
final
String
sensor
:
sensors
)
{
final
int
initialDelay
=
random
.
nextInt
(
periodMs
);
executor
.
scheduleAtFixedRate
(()
->
{
kafkaRecordSender
.
write
(
new
ActivePowerRecord
(
sensor
,
System
.
currentTimeMillis
(),
value
));
},
initialDelay
,
periodMs
,
TimeUnit
.
MILLISECONDS
);
}
System
.
out
.
println
(
"Wait for termination..."
);
executor
.
awaitTermination
(
30
,
TimeUnit
.
DAYS
);
System
.
out
.
println
(
"Will terminate now"
);
System
.
out
.
println
(
"Wait for termination..."
);
executor
.
awaitTermination
(
30
,
TimeUnit
.
DAYS
);
System
.
out
.
println
(
"Will terminate now"
);
}
}
private
static
int
addChildren
(
final
MutableAggregatedSensor
parent
,
final
int
numChildren
,
final
int
lvl
,
final
int
maxLvl
,
int
nextId
)
{
for
(
int
c
=
0
;
c
<
numChildren
;
c
++)
{
if
(
lvl
==
maxLvl
)
{
parent
.
addChildMachineSensor
(
"s_"
+
nextId
);
nextId
++;
}
else
{
final
MutableAggregatedSensor
newParent
=
parent
.
addChildAggregatedSensor
(
"g_"
+
lvl
+
'_'
+
nextId
);
nextId
++;
nextId
=
addChildren
(
newParent
,
numChildren
,
lvl
+
1
,
maxLvl
,
nextId
);
}
}
return
nextId
;
}
private
static
int
addChildren
(
final
MutableAggregatedSensor
parent
,
final
int
numChildren
,
final
int
lvl
,
final
int
maxLvl
,
int
nextId
)
{
for
(
int
c
=
0
;
c
<
numChildren
;
c
++)
{
if
(
lvl
==
maxLvl
)
{
parent
.
addChildMachineSensor
(
"s_"
+
nextId
);
nextId
++;
}
else
{
final
MutableAggregatedSensor
newParent
=
parent
.
addChildAggregatedSensor
(
"g_"
+
lvl
+
'_'
+
nextId
);
nextId
++;
nextId
=
addChildren
(
newParent
,
numChildren
,
lvl
+
1
,
maxLvl
,
nextId
);
}
}
return
nextId
;
}
}
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