Commit ee321959 authored by Marta Różańska's avatar Marta Różańska
Browse files

Merge branch 'metasolver/156-add-operation-mode-2' into 'morphemic-rc2.0'

MetaSolver: Implementing feature "156 Manually switch from/to...

See merge request !124
parents e90e4d54 f05dc6c5
Pipeline #19203 passed with stages
in 64 minutes and 25 seconds
......@@ -8,8 +8,9 @@
FROM java:8-alpine
VOLUME /tmp
ADD meta-solver.jar meta-solver.jar
RUN /bin/sh -c "apk add --no-cache bash"
ADD meta-solver.jar meta-solver.jar
RUN bash -c 'touch /meta-solver.jar'
COPY ./run.sh .
......
......@@ -11,6 +11,7 @@ package eu.melodic.upperware.metasolver;
import eu.melodic.models.commons.NotificationResult;
import eu.melodic.models.commons.NotificationResultImpl;
import eu.melodic.models.interfaces.metaSolver.*;
import eu.melodic.upperware.metasolver.properties.MetaSolverProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
......@@ -212,6 +213,27 @@ public class MetaSolverController {
return metricsNamesResponse;
}
@GetMapping("/getOperationMode")
public MetaSolverProperties.OperationMode getOperationMode(@RequestHeader(name = HttpHeaders.AUTHORIZATION) String jwtToken) {
setAuthenticationToken(jwtToken);
log.info("Received request for getting operation mode: ");
MetaSolverProperties.OperationMode mode = coordinator.getMetaSolverProperties().getOperationMode();
log.info("Current operation mode: {}", mode);
return mode;
}
@GetMapping("/setOperationMode/{mode}")
public void setOperationMode(@PathVariable("mode") MetaSolverProperties.OperationMode mode,
@RequestHeader(name = HttpHeaders.AUTHORIZATION) String jwtToken) {
setAuthenticationToken(jwtToken);
log.info("Received request for setting operation mode: {}", mode);
MetaSolverProperties.OperationMode prevMode = coordinator.getMetaSolverProperties().getOperationMode();
log.info("Previous operation mode: {}", prevMode);
coordinator.getMetaSolverProperties().setOperationMode(mode);
log.info("New operation mode: {}", mode);
}
@RequestMapping(value = "/health", method = GET)
public void health() {
}
......
......@@ -10,6 +10,7 @@ package eu.melodic.upperware.metasolver.metricvalue;
import com.google.gson.Gson;
import eu.melodic.upperware.metasolver.Coordinator;
import eu.melodic.upperware.metasolver.properties.MetaSolverProperties;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
......@@ -30,8 +31,9 @@ public class MetricValueListener implements MessageListener {
private MetricValueRegistry<Object> registry;
private Gson gson;
private Coordinator coordinator;
private MetaSolverProperties metaSolverProperties;
public MetricValueListener(Coordinator coordinator, Topic topic, TopicType type, MetricValueRegistry<Object> registry, boolean isPrediction) throws JMSException {
public MetricValueListener(Coordinator coordinator, Topic topic, TopicType type, MetricValueRegistry<Object> registry, boolean isPrediction, MetaSolverProperties metaSolverProperties) throws JMSException {
log.debug("MetricValueListener.<init>: type={}", type);
this.coordinator = coordinator;
this.topic = topic;
......@@ -41,6 +43,7 @@ public class MetricValueListener implements MessageListener {
this.isPrediction = isPrediction;
this.reconfigurationProbabilityThreshold = coordinator.getMetaSolverProperties().getReconfigurationProbabilityThreshold();
gson = new Gson();
this.metaSolverProperties = metaSolverProperties;
}
public void onMessage(Message message) {
......@@ -104,15 +107,28 @@ public class MetricValueListener implements MessageListener {
// ...using MetricValueEvent
log.debug("Listener of topic {}: Converting event payload to MetricValueEvent instance...", topicName);
MetricValueEvent event = gson.fromJson(payload, MetricValueEvent.class);
MetaSolverProperties.OperationMode operationMode = metaSolverProperties.getOperationMode();
log.debug("Listener of topic {}: MetricValueEvent instance: {}", topicName, event);
if (!isPrediction) {
// check operation mode
if (operationMode==MetaSolverProperties.OperationMode.PREDICTED_ONLY) {
log.debug(" Operation-Mode is {}. Ignoring MVV event due to actual metric: topic={}, payload={}", operationMode, metricName, payload);
return;
}
// Cache Metric Value in registry
log.debug("Listener of topic {}: Metric registry values BEFORE update: {}", topicName, registry);
registry.setMetricValue(metricName, event.getMetricValue());
log.info("Metric Value set: name='{}', value='{}', topic={}", metricName, event.getMetricValue(), topicName);
log.debug("Listener of topic {}: Metric registry values AFTER update: {}", topicName, registry);
} else {
// check operation mode
if (operationMode==MetaSolverProperties.OperationMode.ACTUAL_ONLY) {
log.debug(" Operation-Mode is {}. Ignoring MVV event due to predicted metric: topic={}, payload={}", operationMode, metricName, payload);
return;
}
// Get predictionTime
long predictionTime = getPredictionTime(event, metricName, payload);
......@@ -134,10 +150,23 @@ public class MetricValueListener implements MessageListener {
protected void processScaleEvent(@NonNull String metricName, @NonNull String payload) {
try {
log.debug("Listener of topic {}: Calling coordinator to start Scaling process...", topicName);
MetaSolverProperties.OperationMode operationMode = metaSolverProperties.getOperationMode();
if (!isPrediction) {
// check operation mode
if (operationMode==MetaSolverProperties.OperationMode.PREDICTED_ONLY) {
log.debug(" Operation-Mode is {}. Ignoring SCALE event due to actual metric: topic={}, payload={}", operationMode, metricName, payload);
return;
}
// Start reconfiguration with the actual metric values set in CP model
coordinator.requestReconfigurationStart(false);
} else {
// check operation mode
if (operationMode==MetaSolverProperties.OperationMode.ACTUAL_ONLY) {
log.debug(" Operation-Mode is {}. Ignoring SCALE event due to predicted metric: topic={}, payload={}", operationMode, metricName, payload);
return;
}
// Extract key-value pairs from message payload
// ...using MetricValueEvent
log.debug("Listener of topic {}: Converting event payload to MetricValueEvent instance...", topicName);
......
......@@ -228,7 +228,7 @@ public class MetricValueMonitorBean implements ApplicationContextAware {
}
private MessageListener getListener(Topic topic, TopicType type, boolean isPrediction) throws JMSException {
MessageListener listener = new MetricValueListener(coordinator, topic, type, registry, isPrediction);
MessageListener listener = new MetricValueListener(coordinator, topic, type, registry, isPrediction, properties);
return listener;
}
......
......@@ -60,6 +60,9 @@ public class MetaSolverProperties {
private DebugEvent debugEvents = new DebugEvent();
public enum OperationMode {ACTUAL_AND_PREDICTED, ACTUAL_ONLY, PREDICTED_ONLY}
private OperationMode operationMode = OperationMode.ACTUAL_AND_PREDICTED;
// --------------------------------------------------------------
@Data
......
......@@ -85,5 +85,8 @@ reconfigurationProbabilityThreshold = 0.5
#preventConcurrentReconfigurations = false
#preventConcurrentReconfigurationsTimeout = -1L
# Default operation mode. Allowed values: ACTUAL_AND_PREDICTED (default), ACTUAL_ONLY, PREDICTED_ONLY
#operationMode = ACTUAL_AND_PREDICTED
### logback configuration ###
logging.config=file:${MELODIC_CONFIG_DIR}/logback-conf/logback-spring.xml
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment