Commit 9092cb24 authored by I Patini's avatar I Patini
Browse files

EMS: Translator, config: Removed @Value annotations from...

EMS: Translator, config: Removed @Value annotations from 'CamelToEplTranslatorProperties' and 'RuleTemplateProperties' classes and renamed fields when needed. Changed corresponding settings in 'eu.melodic.event.translator.properties' (renamed settings where needed). Changed ModelAnalyzer, RuleGenerator and GraphTransformer classes into Spring Components and updated code accordingly. Fixed a bug in ModelAnalyzer that caused NPE.
parent 5bbeb094
Pipeline #20868 failed with stages
in 105 minutes and 36 seconds
......@@ -16,26 +16,26 @@ translator.full-name-pattern={TYPE}__{CAMEL}__{MODEL}__{ELEM}__{COUNT}
translator.formula-check-enabled=true
#XXX:TODO: put the correct MMS annotation (Ask Marcin and Kyriakos)
translator.sensor-config-annotation=ApplicationPlacementModel.iaas.processing
translator.sensor-configuration-annotation=ApplicationPlacementModel.iaas.processing
translator.sensor-min-interval=1
translator.sensor-default-interval=60
# Print results and export switches
#translator.print-results=true
dag.export-to-dot.enabled=false
dag.export-to-file.enabled=false
translator.dag.export-to-dot-enabled=false
translator.dag.export-to-file-enabled=false
# Graph rendering parameters
dag.export.path=${LOGS_DIR:${MELODIC_CONFIG_DIR}/../logs}/exports
#dag.export.formats=png,svg,xdot
dag.export.formats=png,svg
#dag.export.formats=png,svg,xdot,ps,json,plain,plain_ext
dag.export.image-width=600
translator.dag.export-path=${LOGS_DIR:${MELODIC_CONFIG_DIR}/../logs}/exports
#translator.dag.export-formats=png,svg,xdot
translator.dag.export-formats=png,svg
#translator.dag.export-formats=png,svg,xdot,ps,json,plain,plain_ext
translator.dag.export-image-width=600
## Active sinks (list)
#active-sinks=JMS
#translator.active-sinks=JMS
#
## Sink configurations
#sink-config.JMS.jms.broker=failover:(tcp://localhost:61616)?initialReconnectDelay=1000&warnAfterReconnectAttempts=10
#sink-config.JMS.jms.topic.selector=de.uniulm.omi.cloudiator.visor.reporting.jms.MetricNameTopicSelector
#sink-config.JMS.jms.message.format=de.uniulm.omi.cloudiator.visor.reporting.jms.MelodicJsonEncoding
#translator.sink-config.JMS.jms.broker=failover:(tcp://localhost:61616)?initialReconnectDelay=1000&warnAfterReconnectAttempts=10
#translator.sink-config.JMS.jms.topic.selector=de.uniulm.omi.cloudiator.visor.reporting.jms.MetricNameTopicSelector
#translator.sink-config.JMS.jms.message.format=de.uniulm.omi.cloudiator.visor.reporting.jms.MelodicJsonEncoding
......@@ -30,7 +30,7 @@ import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import java.util.*;
......@@ -41,13 +41,13 @@ import java.util.stream.Collectors;
@NoArgsConstructor
public class CamelToEplTranslator implements Translator {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private CamelToEplTranslatorProperties properties;
@Autowired
private RuleTemplateProperties ruleTemplatesRegistry;
@Value("${translator.leaf-node-grouping}")
private String leafGrouping;
private CDOClientX cdoClient;
public CamelToEplTranslator(CDOClientX client) {
......@@ -106,19 +106,19 @@ public class CamelToEplTranslator implements Translator {
// analyze scalability rules and metric expressions
log.debug("CamelToEplTranslator.translate(): Analyzing models...");
ModelAnalyzer modelAnalyzer = new ModelAnalyzer();
modelAnalyzer.analyzeModel(_TC, leafGrouping, camelModel, properties);
ModelAnalyzer modelAnalyzer = applicationContext.getBean(ModelAnalyzer.class);
modelAnalyzer.analyzeModel(_TC, camelModel);
log.debug("CamelToEplTranslator.translate(): Analyzing models... done");
// transform graph
log.debug("CamelToEplTranslator.translate(): Transforming DAG...");
GraphTransformer transformer = new GraphTransformer();
transformer.transformGraph(_TC.DAG, properties);
GraphTransformer transformer = applicationContext.getBean(GraphTransformer.class);
transformer.transformGraph(_TC.DAG);
log.debug("CamelToEplTranslator.translate(): Transforming DAG... done");
// generate EPL rules
log.debug("CamelToEplTranslator.translate(): Generating EPL rules...");
RuleGenerator generator = new RuleGenerator(ruleTemplatesRegistry);
RuleGenerator generator = applicationContext.getBean(RuleGenerator.class);
generator.generateRules(_TC);
log.debug("CamelToEplTranslator.translate(): Generating EPL rules... done");
......@@ -146,7 +146,7 @@ public class CamelToEplTranslator implements Translator {
// Print DAG
String dot = null;
if (properties.isExportToDotEnabled()) {
if (properties.getDag().isExportToDotEnabled()) {
log.info("Decomposition Graph:\n{}", _TC.DAG);
log.info("*********************************************************");
try {
......@@ -157,14 +157,14 @@ public class CamelToEplTranslator implements Translator {
}
}
// Export DAG to files
if (properties.isExportToFileEnabled()) {
if (properties.getDag().isExportToFileEnabled()) {
log.info("*********************************************************");
log.info("Decomposition Graph export to file(s)");
try {
// Get graph export configuration
String exportPath = properties.getExportPath();
String[] exportFormats = properties.getExportFormats();
int imageWidth = properties.getExportImageWidth();
String exportPath = properties.getDag().getExportPath();
String[] exportFormats = properties.getDag().getExportFormats();
int imageWidth = properties.getDag().getExportImageWidth();
// Get base name and path of export files
if (exportPath == null) exportPath = "";
......
......@@ -12,7 +12,7 @@ package eu.melodic.event.translate.analyze;
import camel.constraint.*;
import camel.core.*;
import camel.data.Data;
import camel.deployment.Component;
//import camel.deployment.Component;
import camel.metric.*;
import camel.metric.Sensor;
import camel.metric.impl.MetricVariableImpl;
......@@ -28,11 +28,14 @@ import eu.melodic.event.translate.properties.CamelToEplTranslatorProperties;
import eu.melodic.models.interfaces.ems.*;
import eu.melodic.event.translate.model.tools.metadata.CamelMetadata;
import eu.melodic.event.translate.model.tools.metadata.CamelMetadataTool;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.emf.common.util.EList;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.List;
......@@ -40,18 +43,20 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
@Component
@RequiredArgsConstructor
public class ModelAnalyzer {
private CamelToEplTranslatorProperties properties;
private final CamelToEplTranslatorProperties properties;
private List<Sink> EMS_SINKS;
// ================================================================================================================
// Model analysis methods
public void analyzeModel(TranslationContext _TC, String leafGrouping, CamelModel camelModel, CamelToEplTranslatorProperties properties) {
public void analyzeModel(TranslationContext _TC, CamelModel camelModel) {
log.debug("ModelAnalyzer.analyzeModel(): Analyzing models...");
this.properties = properties;
String leafGrouping = properties.getLeafNodeGrouping();
// set full-name pattern in _TC, for full-name generation
_TC.setFullNamePattern(properties.getFullNamePattern());
......@@ -158,7 +163,7 @@ public class ModelAnalyzer {
variables.forEach(mv -> {
// get component metrics
EList<Metric> componentMetrics = mv.getComponentMetrics();
Component component = mv.getComponent();
camel.deployment.Component component = mv.getComponent();
log.info(" Metric-Variable: {}.{}.{} :: component-metrics={}, component={}", camelModel.getName(), mm.getName(), mv.getName(), getListElementNames(componentMetrics), getElementName(component));
// update _TC.MVV set
......@@ -183,7 +188,7 @@ public class ModelAnalyzer {
//XXX:Improve this method (probably pre-process metric models to avoid multiple scans of the model)
private static MetricVariable _findMatchingVar(MetricVariable mvar, CamelModel camelModel) {
CamelMetadata type = CamelMetadataTool.findVariableType((MetricVariableImpl) mvar);
Component comp = mvar.getComponent();
camel.deployment.Component comp = mvar.getComponent();
if (type==null || comp==null) {
log.warn(" _findMatchingVar: type or component is null: type={}, component={}", type, comp);
return null;
......@@ -468,7 +473,7 @@ public class ModelAnalyzer {
MetricTemplate template = mv.getMetricTemplate();
boolean isCurrConfig = mv.isCurrentConfiguration();
boolean isOnNodeCand = mv.isOnNodeCandidates();
Component component = mv.getComponent();
camel.deployment.Component component = mv.getComponent();
String formula = mv.getFormula();
List<Metric> componentMetrics = ListUtils.emptyIfNull(mv.getComponentMetrics());
boolean containsMetrics = ! componentMetrics.isEmpty();
......@@ -764,7 +769,7 @@ public class ModelAnalyzer {
MetricTemplate template = mvar.getMetricTemplate();
boolean currentConfig = mvar.isCurrentConfiguration();
boolean nodeCandidates = mvar.isOnNodeCandidates();
Component component = mvar.getComponent();
camel.deployment.Component component = mvar.getComponent();
String formula = mvar.getFormula();
EList<Metric> metrics = mvar.getComponentMetrics();
log.info(" _decomposeMetricVariable(): {} :: template={}, current-config={}, on-node-candidates={}, component={}, formula={}, component-metrics={}",
......@@ -943,7 +948,7 @@ public class ModelAnalyzer {
log.debug(" _initializeSinks(): Sink type configurations: {}", properties.getSinkConfig());
List<Sink> sinks = new ArrayList<>();
for (String sinkType : properties.getSinks()) {
for (String sinkType : CollectionUtils.emptyIfNull(properties.getSinks())) {
log.trace(" _initializeSinks(): Processing sink type: {}", sinkType);
Sink.TypeType sinkTypeType = Sink.TypeType.valueOf(sinkType);
Map<String,String> configMap = properties.getSinkConfig().get(sinkType);
......@@ -1286,7 +1291,7 @@ public class ModelAnalyzer {
private String getComponentName(ObjectContext objContext) {
if (objContext == null) return null;
Component comp = objContext.getComponent();
camel.deployment.Component comp = objContext.getComponent();
Data data = objContext.getData();
if (comp != null && data != null)
throw new ModelAnalysisException("Invalid Object Context: properties Component and Data cannot be not null at the same time: " + objContext.getName());
......
......@@ -15,7 +15,7 @@ import camel.constraint.LogicalConstraint;
import camel.constraint.MetricConstraint;
import camel.core.NamedElement;
import camel.data.Data;
import camel.deployment.Component;
//import camel.deployment.Component;
import camel.metric.*;
import camel.metric.impl.MetricVariableImpl;
import camel.requirement.OptimisationRequirement;
......@@ -25,12 +25,13 @@ import camel.scalability.NonFunctionalEvent;
import camel.scalability.UnaryEventPattern;
import eu.melodic.event.brokercep.cep.MathUtil;
import eu.melodic.event.translate.TranslationContext;
import eu.melodic.event.translate.properties.CamelToEplTranslatorProperties;
import eu.melodic.event.translate.properties.RuleTemplateProperties;
import eu.melodic.event.translate.model.tools.metadata.CamelMetadataTool;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.emf.common.util.EList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.dialect.SpringStandardDialect;
......@@ -44,15 +45,18 @@ import java.util.Set;
import java.util.stream.Collectors;
@Slf4j
@Service
@Component
public class RuleGenerator {
@Autowired
private CamelToEplTranslatorProperties properties;
@Autowired
private RuleTemplateProperties ruleTemplatesRegistry;
private SpringTemplateEngine templateEngine;
public RuleGenerator(RuleTemplateProperties ruleTemplatesRegistry) {
public RuleGenerator(CamelToEplTranslatorProperties properties, RuleTemplateProperties ruleTemplatesRegistry) {
this.properties = properties;
this.ruleTemplatesRegistry = ruleTemplatesRegistry;
initTemplateEngine();
}
......@@ -463,7 +467,7 @@ public class RuleGenerator {
MetricVariable mvar = (MetricVariable) elem;
boolean isCurrConfig = mvar.isCurrentConfiguration();
boolean isOnNodeCand = mvar.isOnNodeCandidates();
Component comp = mvar.getComponent();
camel.deployment.Component comp = mvar.getComponent();
String compName = comp != null ? comp.getName() : null;
String formula = mvar.getFormula();
EList<Metric> _componentMetrics = mvar.getComponentMetrics();
......@@ -619,7 +623,7 @@ public class RuleGenerator {
if (mc != null) {
ObjectContext objCtx = mc.getObjectContext();
if (objCtx != null) {
Component comp = objCtx.getComponent();
camel.deployment.Component comp = objCtx.getComponent();
Data data = objCtx.getData();
compName = comp != null ? comp.getName() : null;
dataName = data != null ? data.getName() : null;
......
......@@ -9,9 +9,10 @@
package eu.melodic.event.translate.properties;
import eu.melodic.event.util.EmsConstant;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
......@@ -21,48 +22,46 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Data
@Validated
@Configuration
@ConfigurationProperties
@Slf4j
@ConfigurationProperties(prefix = EmsConstant.EMS_PROPERTIES_PREFIX + "translator")
@PropertySource("file:${MELODIC_CONFIG_DIR}/eu.melodic.event.translator.properties")
public class CamelToEplTranslatorProperties {
public class CamelToEplTranslatorProperties implements InitializingBean {
@Override
public void afterPropertiesSet() {
log.debug("CamelToEplTranslatorProperties: {}", this);
}
// Translator parameters
@Value("${translator.sensor-config-annotation}")
private String sensorConfigurationAnnotation;
@Value("${translator.sensor-min-interval}")
private long sensorMinInterval;
@Value("${translator.sensor-default-interval}")
private long sensorDefaultInterval;
@Value("${translator.prune-mvv:true}")
private boolean pruneMvv;
@Value("${translator.add-top-level-metrics:true}")
private boolean addTopLevelMetric;
@Value("${translator.full-name-pattern}")
private String leafNodeGrouping;
private boolean pruneMvv = true;
private boolean addTopLevelMetrics = true;
private String fullNamePattern;
@Value("${translator.formula-check-enabled:true}")
private boolean formulaCheckEnabled;
private boolean formulaCheckEnabled = true;
// Translation Results & Graph print/export Switches
@Value("${translator.print-results:true}")
private boolean printResults;
@Value("${dag.export-to-dot.enabled:true}")
private boolean exportToDotEnabled;
@Value("${dag.export-to-file.enabled:true}")
private boolean exportToFileEnabled;
private boolean printResults = true;
private Dag dag = new Dag();
@Data
public static class Dag {
// Graph rendering/export
private boolean exportToDotEnabled = true;
private boolean exportToFileEnabled = true;
// Graph rendering parameters
@Value("${dag.export.path:}")
private String exportPath;
@Value("${dag.export.formats:}")
private String[] exportFormats;
@Value("${dag.export.image-width:-1}")
private int exportImageWidth;
// Graph rendering parameters
private String exportPath;
private String[] exportFormats;
private int exportImageWidth = -1;
}
// Active sink types
@Value("${active-sinks:}")
private List<String> sinks;
// Sink type configurations
......
......@@ -9,9 +9,10 @@
package eu.melodic.event.translate.properties;
import eu.melodic.event.util.EmsConstant;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
......@@ -22,14 +23,18 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
@Slf4j
@Data
@Validated
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "generator")
@Slf4j
public class RuleTemplateProperties {
@Value("${generator.language:}")
@ConfigurationProperties(prefix = EmsConstant.EMS_PROPERTIES_PREFIX + "generator")
public class RuleTemplateProperties implements InitializingBean {
@Override
public void afterPropertiesSet() {
log.debug("RuleTemplateProperties: {}", this);
}
private String language;
private Map<String, Map<String, List<String>>> ruleTemplates;
......
......@@ -17,16 +17,20 @@ import eu.melodic.event.translate.analyze.DAG;
import eu.melodic.event.translate.analyze.DAGNode;
import eu.melodic.event.translate.analyze.Grouping;
import eu.melodic.event.translate.properties.CamelToEplTranslatorProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;
import java.util.Set;
@Slf4j
@Component
@RequiredArgsConstructor
public class GraphTransformer {
private CamelToEplTranslatorProperties properties;
private final CamelToEplTranslatorProperties properties;
public void transformGraph(DAG dag, CamelToEplTranslatorProperties properties) {
public void transformGraph(DAG dag) {
log.debug("GraphTransformer.transformGraph(): Transforming DAG...");
if (properties.isPruneMvv()) {
removeMVV(dag, dag.getRootNode());
......@@ -34,7 +38,7 @@ public class GraphTransformer {
log.debug("GraphTransformer.transformGraph(): MVV pruning from DAG is disabled");
}
if (properties.isAddTopLevelMetric()) {
if (properties.isAddTopLevelMetrics()) {
addTopLevelMetrics(dag);
} else {
log.debug("GraphTransformer.transformGraph(): Adding Metric for Top-Level Metric Contexts in DAG is disabled");
......
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