"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "moskito-webui/src/main/java/net/anotheria/moskito/webui/dashboards/api/DashboardAPIImpl.java" between
moskito-moskito-2.8.9.tar.gz and moskito-moskito-2.9.0.tar.gz

About: MoSKito (Monitoring System Kit) is a framework for java application monitoring. Sources.

DashboardAPIImpl.java  (moskito-moskito-2.8.9):DashboardAPIImpl.java  (moskito-moskito-2.9.0)
skipping to change at line 38 skipping to change at line 38
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* Implementation of the DashboardAPI. * Implementation of the DashboardAPI.
* *
* @author lrosenberg * @author lrosenberg
* @since 08.04.15 12:46 * @since 08.04.15 12:46
*/ */
public class DashboardAPIImpl extends AbstractMoskitoAPIImpl implements Dashboar dAPI{ public class DashboardAPIImpl extends AbstractMoskitoAPIImpl implements Dashboar dAPI {
/** /**
* GaugeAPI. * GaugeAPI.
*/ */
private GaugeAPI gaugeAPI; private GaugeAPI gaugeAPI;
/** /**
* ThresholdAPI. * ThresholdAPI.
*/ */
private ThresholdAPI thresholdAPI; private ThresholdAPI thresholdAPI;
/** /**
skipping to change at line 66 skipping to change at line 66
gaugeAPI = APIFinder.findAPI(GaugeAPI.class); gaugeAPI = APIFinder.findAPI(GaugeAPI.class);
thresholdAPI = APIFinder.findAPI(ThresholdAPI.class); thresholdAPI = APIFinder.findAPI(ThresholdAPI.class);
accumulatorAPI = APIFinder.findAPI(AccumulatorAPI.class); accumulatorAPI = APIFinder.findAPI(AccumulatorAPI.class);
} }
@Override @Override
public String getDefaultDashboardName() { public String getDefaultDashboardName() {
MoskitoConfiguration config = MoskitoConfigurationHolder.getConfi guration(); MoskitoConfiguration config = MoskitoConfigurationHolder.getConfi guration();
DashboardsConfig dashboardsConfig = config.getDashboardsConfig(); DashboardsConfig dashboardsConfig = config.getDashboardsConfig();
if (dashboardsConfig == null || dashboardsConfig.getDashboards() == null ||dashboardsConfig.getDashboards().length == 0) if (dashboardsConfig == null || dashboardsConfig.getDashboards() == null || dashboardsConfig.getDashboards().length == 0)
return null; return null;
return dashboardsConfig.getDashboards()[0].getName(); return dashboardsConfig.getDashboards()[0].getName();
} }
@Override @Override
public DashboardConfig getDashboardConfig(String name) throws APIExceptio n { public DashboardConfig getDashboardConfig(String name) throws APIExceptio n {
if (name == null) if (name == null)
return null; return null;
DashboardsConfig dashboardsConfig = getConfiguration().getDashboa rdsConfig(); DashboardsConfig dashboardsConfig = getConfiguration().getDashboa rdsConfig();
if (dashboardsConfig==null || dashboardsConfig.getDashboards()==n ull || dashboardsConfig.getDashboards().length ==0){ if (dashboardsConfig == null || dashboardsConfig.getDashboards() == null || dashboardsConfig.getDashboards().length == 0) {
return null; return null;
} }
for (DashboardConfig dc : dashboardsConfig.getDashboards()){ for (DashboardConfig dc : dashboardsConfig.getDashboards()) {
if (dc.getName()!=null && dc.getName().equals(name)){ if (dc.getName() != null && dc.getName().equals(name)) {
return dc; return dc;
} }
} }
return null; return null;
} }
@Override @Override
public void createDashboard(String dashboardName) throws APIException { public void createDashboard(String dashboardName) throws APIException {
if (StringUtils.isEmpty(dashboardName)) if (StringUtils.isEmpty(dashboardName))
skipping to change at line 119 skipping to change at line 119
@Override @Override
public void removeDashboard(String dashboardName) throws APIException { public void removeDashboard(String dashboardName) throws APIException {
if (StringUtils.isEmpty(dashboardName)) if (StringUtils.isEmpty(dashboardName))
return; return;
MoskitoConfiguration config = MoskitoConfigurationHolder.getConfi guration(); MoskitoConfiguration config = MoskitoConfigurationHolder.getConfi guration();
DashboardsConfig dashboardsConfig = config.getDashboardsConfig(); DashboardsConfig dashboardsConfig = config.getDashboardsConfig();
DashboardConfig[] dashboards = dashboardsConfig.getDashboards(); DashboardConfig[] dashboards = dashboardsConfig.getDashboards();
List<DashboardConfig> newConfigList = new ArrayList<>(); List<DashboardConfig> newConfigList = new ArrayList<>();
if (dashboards == null) if (dashboards == null)
throw new APIException("Dashboard "+dashboardName+" not f ound."); throw new APIException("Dashboard " + dashboardName + " n ot found.");
for (DashboardConfig dashboard : dashboards) { for (DashboardConfig dashboard : dashboards) {
if (!dashboardName.equals(dashboard.getName())) { if (!dashboardName.equals(dashboard.getName())) {
newConfigList.add(dashboard); newConfigList.add(dashboard);
} }
} }
if (newConfigList.size() == dashboards.length) if (newConfigList.size() == dashboards.length)
throw new APIException("Dashboard "+dashboardName+" not f ound."); throw new APIException("Dashboard " + dashboardName + " n ot found.");
dashboardsConfig.setDashboards(newConfigList.toArray(new Dashboar dConfig[0])); dashboardsConfig.setDashboards(newConfigList.toArray(new Dashboar dConfig[0]));
} }
@Override @Override
public void addGaugeToDashboard(String dashboardName, String gaugeName) t hrows APIException { public void addGaugeToDashboard(String dashboardName, String gaugeName) t hrows APIException {
DashboardConfig config = getDashboardConfig(dashboardName); DashboardConfig config = getDashboardConfig(dashboardName);
if (config == null) if (config == null)
return; return;
if (StringUtils.isEmpty(gaugeName)) if (StringUtils.isEmpty(gaugeName))
return; return;
String[] cc_array = config.getGauges(); String[] cc_array = config.getGauges();
int newSize = cc_array == null ? 1 : cc_array.length + 1; int newSize = cc_array == null ? 1 : cc_array.length + 1;
String[] new_cc_array = new String[newSize]; String[] new_cc_array = new String[newSize];
if (cc_array != null) if (cc_array != null)
System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength); System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength);
new_cc_array[new_cc_array.length-1] = gaugeName; new_cc_array[new_cc_array.length - 1] = gaugeName;
config.setGauges(new_cc_array); config.setGauges(new_cc_array);
} }
@Override @Override
public void removeGaugeFromDashboard(String dashboardName, String gaugeNa me) throws APIException { public void removeGaugeFromDashboard(String dashboardName, String gaugeNa me) throws APIException {
DashboardConfig config = getDashboardConfig(dashboardName); DashboardConfig config = getDashboardConfig(dashboardName);
if (config == null) if (config == null)
return; return;
if (StringUtils.isEmpty(gaugeName)) if (StringUtils.isEmpty(gaugeName))
skipping to change at line 169 skipping to change at line 169
String[] cc_array = config.getGauges(); String[] cc_array = config.getGauges();
int gaugeIndex = -1; int gaugeIndex = -1;
int count = 0; int count = 0;
for (String name : cc_array) { for (String name : cc_array) {
if (name.equals(gaugeName)) { if (name.equals(gaugeName)) {
gaugeIndex = count; gaugeIndex = count;
break; break;
} }
count++; count++;
} }
if (gaugeIndex==-1){ if (gaugeIndex == -1) {
return; return;
} }
if (cc_array == null || cc_array.length<gaugeIndex+1) if (cc_array == null || cc_array.length < gaugeIndex + 1)
return; return;
String[] new_cc_array = new String[cc_array.length-1]; String[] new_cc_array = new String[cc_array.length - 1];
if (cc_array.length == 1){ if (cc_array.length == 1) {
//source had only one element //source had only one element
config.setGauges(new_cc_array); config.setGauges(new_cc_array);
return; return;
} }
removeElementFromArray(cc_array, new_cc_array, gaugeIndex); removeElementFromArray(cc_array, new_cc_array, gaugeIndex);
config.setGauges(new_cc_array); config.setGauges(new_cc_array);
} }
@Override @Override
skipping to change at line 198 skipping to change at line 198
if (config == null) if (config == null)
return; return;
if (StringUtils.isEmpty(thresholdName)) if (StringUtils.isEmpty(thresholdName))
return; return;
String[] cc_array = config.getThresholds(); String[] cc_array = config.getThresholds();
int newSize = cc_array == null ? 1 : cc_array.length + 1; int newSize = cc_array == null ? 1 : cc_array.length + 1;
String[] new_cc_array = new String[newSize]; String[] new_cc_array = new String[newSize];
if (cc_array != null) if (cc_array != null)
System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength); System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength);
new_cc_array[new_cc_array.length-1] = thresholdName; new_cc_array[new_cc_array.length - 1] = thresholdName;
config.setThresholds(new_cc_array); config.setThresholds(new_cc_array);
} }
@Override @Override
public void removeThresholdFromDashboard(String dashboardName, String thr esholdName) throws APIException { public void removeThresholdFromDashboard(String dashboardName, String thr esholdName) throws APIException {
DashboardConfig config = getDashboardConfig(dashboardName); DashboardConfig config = getDashboardConfig(dashboardName);
if (config == null) if (config == null)
return; return;
if (StringUtils.isEmpty(thresholdName)) if (StringUtils.isEmpty(thresholdName))
skipping to change at line 221 skipping to change at line 221
String[] cc_array = config.getThresholds(); String[] cc_array = config.getThresholds();
int index = -1; int index = -1;
int count = 0; int count = 0;
for (String name : cc_array) { for (String name : cc_array) {
if (name.equals(thresholdName)) { if (name.equals(thresholdName)) {
index = count; index = count;
break; break;
} }
count++; count++;
} }
if (index==-1){ if (index == -1) {
return; return;
} }
if (cc_array == null || cc_array.length<index+1) if (cc_array == null || cc_array.length < index + 1)
return; return;
String[] new_cc_array = new String[cc_array.length-1]; String[] new_cc_array = new String[cc_array.length - 1];
if (cc_array.length == 1){ if (cc_array.length == 1) {
//source had only one element //source had only one element
config.setThresholds(new_cc_array); config.setThresholds(new_cc_array);
return; return;
} }
removeElementFromArray(cc_array, new_cc_array, index); removeElementFromArray(cc_array, new_cc_array, index);
config.setThresholds(new_cc_array); config.setThresholds(new_cc_array);
} }
@Override @Override
public void addChartToDashboard(String dashboardName, String[] accNames) throws APIException { public void addChartToDashboard(String dashboardName, String caption, Str ing[] accNames) throws APIException {
DashboardConfig config = getDashboardConfig(dashboardName); DashboardConfig config = getDashboardConfig(dashboardName);
if (config == null) if (config == null)
return; return;
if (accNames == null || accNames.length == 0) if (accNames == null || accNames.length == 0)
return; return;
ChartConfig[] cc_array = config.getCharts(); ChartConfig[] cc_array = config.getCharts();
int newSize = cc_array == null ? 1 : cc_array.length + 1; int newSize = cc_array == null ? 1 : cc_array.length + 1;
ChartConfig[] new_cc_array = new ChartConfig[newSize]; ChartConfig[] new_cc_array = new ChartConfig[newSize];
if (cc_array != null) if (cc_array != null)
System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength); System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength);
ChartConfig newChartConfig = new ChartConfig(); ChartConfig newChartConfig = new ChartConfig();
newChartConfig.setAccumulators(accNames); newChartConfig.setAccumulators(accNames);
new_cc_array[new_cc_array.length-1] = newChartConfig; newChartConfig.setCaption(caption);
new_cc_array[new_cc_array.length - 1] = newChartConfig;
config.setCharts(new_cc_array); config.setCharts(new_cc_array);
} }
@Override @Override
public void removeChartFromDashboard(String dashboardName, String[] accNa mes) throws APIException { public void removeChartFromDashboard(String dashboardName, String[] accNa mes) throws APIException {
DashboardConfig config = getDashboardConfig(dashboardName); DashboardConfig config = getDashboardConfig(dashboardName);
if (config == null) if (config == null)
return; return;
if (accNames == null || accNames.length == 0) if (accNames == null || accNames.length == 0)
skipping to change at line 280 skipping to change at line 281
int index = -1; int index = -1;
int count = 0; int count = 0;
for (ChartConfig cc : cc_array) { for (ChartConfig cc : cc_array) {
String caption = cc.buildCaption(); String caption = cc.buildCaption();
if (caption.equals(accCaption)) { if (caption.equals(accCaption)) {
index = count; index = count;
break; break;
} }
count++; count++;
} }
if (index==-1){ if (index == -1) {
return; return;
} }
if (cc_array == null || cc_array.length<index+1) if (cc_array == null || cc_array.length < index + 1)
return; return;
ChartConfig[] new_cc_array = new ChartConfig[cc_array.length-1]; ChartConfig[] new_cc_array = new ChartConfig[cc_array.length - 1]
if (cc_array.length == 1){ ;
if (cc_array.length == 1) {
//source had only one element //source had only one element
config.setCharts(new_cc_array); config.setCharts(new_cc_array);
return; return;
} }
removeElementFromArray(cc_array, new_cc_array, index); removeElementFromArray(cc_array, new_cc_array, index);
config.setCharts(new_cc_array); config.setCharts(new_cc_array);
} }
@Override @Override
skipping to change at line 317 skipping to change at line 318
String[] new_cc_array = new String[newSize]; String[] new_cc_array = new String[newSize];
if (cc_array != null) { if (cc_array != null) {
System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength); System.arraycopy(cc_array, 0, new_cc_array, 0, cc_array.l ength);
} }
new_cc_array[new_cc_array.length - 1] = producerName; new_cc_array[new_cc_array.length - 1] = producerName;
config.setProducers(new_cc_array); config.setProducers(new_cc_array);
} }
@Override @Override
public void removeProducerFromDashboard(String dashboardName, String produce public void removeProducerFromDashboard(String dashboardName, String prod
rName) throws APIException { ucerName) throws APIException {
DashboardConfig config = getDashboardConfig(dashboardName); DashboardConfig config = getDashboardConfig(dashboardName);
if (config == null) if (config == null)
return; return;
if (StringUtils.isEmpty(producerName)) if (StringUtils.isEmpty(producerName))
return; return;
String[] cc_array = config.getProducers();
int index = -1;
int count = 0;
for (String producer : cc_array) {
if (producerName.equals(producer)) {
index = count;
break;
}
count++;
}
if (index==-1){
return;
}
if (cc_array == null || cc_array.length<index+1)
return;
String[] new_cc_array = new String[cc_array.length-1];
if (cc_array.length == 1){
//source had only one element
config.setProducers(new_cc_array);
return;
}
removeElementFromArray(cc_array, new_cc_array, index);
config.setProducers(new_cc_array);
}
private static <T> T removeElementFromArray(T sourceArray[], T destArray, String[] cc_array = config.getProducers();
int index){ int index = -1;
int count = 0;
for (String producer : cc_array) {
if (producerName.equals(producer)) {
index = count;
break;
}
count++;
}
if (index == -1) {
return;
}
if (cc_array == null || cc_array.length < index + 1)
return;
String[] new_cc_array = new String[cc_array.length - 1];
if (cc_array.length == 1) {
//source had only one element
config.setProducers(new_cc_array);
return;
}
removeElementFromArray(cc_array, new_cc_array, index);
config.setProducers(new_cc_array);
}
private static <T> T removeElementFromArray(T sourceArray[], T destArray,
int index) {
//last element //last element
if (sourceArray.length==index+1){ if (sourceArray.length == index + 1) {
System.arraycopy(sourceArray, 0, destArray, 0, sourceArra System.arraycopy(sourceArray, 0, destArray, 0, sourceArra
y.length-1); y.length - 1);
return destArray; return destArray;
} }
if (index==0){ if (index == 0) {
System.arraycopy(sourceArray, 1, destArray, 0, sourceArra System.arraycopy(sourceArray, 1, destArray, 0, sourceArra
y.length-1); y.length - 1);
return destArray; return destArray;
} }
System.arraycopy(sourceArray, 0, destArray, 0, index+1); System.arraycopy(sourceArray, 0, destArray, 0, index + 1);
System.arraycopy(sourceArray, index+1, destArray, index, sourceAr System.arraycopy(sourceArray, index + 1, destArray, index, source
ray.length-index-1); Array.length - index - 1);
return destArray; return destArray;
} }
@Override @Override
public List<DashboardDefinitionAO> getDashboardDefinitions() throws APIEx ception { public List<DashboardDefinitionAO> getDashboardDefinitions() throws APIEx ception {
MoskitoConfiguration config = getConfiguration(); MoskitoConfiguration config = getConfiguration();
DashboardsConfig dashboardsConfig = config.getDashboardsConfig(); DashboardsConfig dashboardsConfig = config.getDashboardsConfig();
if (dashboardsConfig == null || dashboardsConfig.getDashboards() == null ||dashboardsConfig.getDashboards().length == 0) if (dashboardsConfig == null || dashboardsConfig.getDashboards() == null || dashboardsConfig.getDashboards().length == 0)
return Collections.emptyList(); return Collections.emptyList();
LinkedList<DashboardDefinitionAO> ret = new LinkedList<DashboardD efinitionAO>(); LinkedList<DashboardDefinitionAO> ret = new LinkedList<DashboardD efinitionAO>();
for (DashboardConfig dashboardConfig : dashboardsConfig.getDashbo ards()){ for (DashboardConfig dashboardConfig : dashboardsConfig.getDashbo ards()) {
DashboardDefinitionAO ao = new DashboardDefinitionAO(); DashboardDefinitionAO ao = new DashboardDefinitionAO();
ao.setName(dashboardConfig.getName()); ao.setName(dashboardConfig.getName());
if (dashboardConfig.getGauges()!=null) if (dashboardConfig.getGauges() != null)
ao.setGauges(Arrays.asList(dashboardConfig.getGau ges())); ao.setGauges(Arrays.asList(dashboardConfig.getGau ges()));
if (dashboardConfig.getThresholds()!=null) if (dashboardConfig.getThresholds() != null)
ao.setThresholds(Arrays.asList(dashboardConfig.ge tThresholds())); ao.setThresholds(Arrays.asList(dashboardConfig.ge tThresholds()));
if (dashboardConfig.getCharts()!=null){ if (dashboardConfig.getCharts() != null) {
for (ChartConfig dcc : dashboardConfig.getCharts( for (ChartConfig dcc : dashboardConfig.getCharts(
)){ )) {
DashboardChartDefinitionAO dccAO = new Da shboardChartDefinitionAO(); DashboardChartDefinitionAO dccAO = new Da shboardChartDefinitionAO();
dccAO.setCaption(dcc.getCaption()); dccAO.setCaption(dcc.getCaption());
if (dcc.getAccumulators()!=null) if (dcc.getAccumulators() != null)
dccAO.setAccumulatorNames(Arrays. asList(dcc.getAccumulators())); dccAO.setAccumulatorNames(Arrays. asList(dcc.getAccumulators()));
ao.addChart(dccAO); ao.addChart(dccAO);
} }
} }
ret.add(ao); ret.add(ao);
} }
return ret; return ret;
} }
@Override @Override
public DashboardAO getDashboard(String name) throws APIException { public DashboardAO getDashboard(String name) throws APIException {
DashboardsConfig dashboardsConfig = getConfiguration().getDashboa rdsConfig(); DashboardsConfig dashboardsConfig = getConfiguration().getDashboa rdsConfig();
if (dashboardsConfig == null) if (dashboardsConfig == null)
throw new APIException("Dashboards are not configured"); throw new APIException("Dashboards are not configured");
if (dashboardsConfig.getDashboards()==null || dashboardsConfig.ge tDashboards().length==0) if (dashboardsConfig.getDashboards() == null || dashboardsConfig. getDashboards().length == 0)
throw new APIException("There are no dashboards"); throw new APIException("There are no dashboards");
DashboardConfig config = null; DashboardConfig config = null;
for (DashboardConfig aConfig : dashboardsConfig.getDashboards()){ for (DashboardConfig aConfig : dashboardsConfig.getDashboards())
if (aConfig.getName().equals(name)){ {
if (aConfig.getName().equals(name)) {
config = aConfig; config = aConfig;
break; break;
} }
} }
if (config == null) if (config == null)
throw new APIException("Dashboard "+name+" not found."); throw new APIException("Dashboard " + name + " not found. ");
DashboardAO ret = new DashboardAO(); DashboardAO ret = new DashboardAO();
ret.setName(config.getName()); ret.setName(config.getName());
if (config.getGauges()!=null && config.getGauges().length>0){ if (config.getGauges() != null && config.getGauges().length > 0) {
ret.setGauges(gaugeAPI.getGauges(config.getGauges())); ret.setGauges(gaugeAPI.getGauges(config.getGauges()));
} }
if (config.getThresholds()!=null && config.getThresholds().length >0){ if (config.getThresholds() != null && config.getThresholds().leng th > 0) {
ret.setThresholds(thresholdAPI.getThresholdStatuses(confi g.getThresholds())); ret.setThresholds(thresholdAPI.getThresholdStatuses(confi g.getThresholds()));
} }
List<String> producers = new LinkedList<String>(); List<String> producers = new LinkedList<String>();
if (config.getProducers() != null && config.getProducers().length > 0) { if (config.getProducers() != null && config.getProducers().length > 0) {
producers.addAll(Arrays.asList(config.getProducers())); producers.addAll(Arrays.asList(config.getProducers()));
} }
if (config.getProducerNamePatterns() != null && config.getProduce rNamePatterns().length > 0) { if (config.getProducerNamePatterns() != null && config.getProduce rNamePatterns().length > 0) {
List<IStatsProducer> IStatsProducers = new ProducerRegist ryAPIFactory().createProducerRegistryAPI().getAllProducers(); List<IStatsProducer> IStatsProducers = new ProducerRegist ryAPIFactory().createProducerRegistryAPI().getAllProducers();
for (Pattern pattern : config.getPatterns()) { for (Pattern pattern : config.getPatterns()) {
for (IStatsProducer isp : IStatsProducers) { for (IStatsProducer isp : IStatsProducers) {
if (pattern.matcher(isp.getProducerId()). matches()) { if (pattern.matcher(isp.getProducerId()). matches()) {
producers.add(isp.getProducerId() ); producers.add(isp.getProducerId() );
} }
} }
} }
} }
if(!producers.isEmpty()){ if (!producers.isEmpty()) {
ret.setProducers(Arrays.asList(producers.toArray(new Stri ng[producers.size()]))); ret.setProducers(Arrays.asList(producers.toArray(new Stri ng[producers.size()])));
} }
//// CHARTS ////// //// CHARTS //////
List<ChartConfig> charts = new LinkedList<>(); List<ChartConfig> charts = new LinkedList<>();
if (config.getCharts() != null && config.getCharts().length > 0) { if (config.getCharts() != null && config.getCharts().length > 0) {
charts.addAll(Arrays.asList(config.getCharts())); charts.addAll(Arrays.asList(config.getCharts()));
} }
if (config.getChartPatterns() != null && config.getChartPatterns( ).length > 0) { if (config.getChartPatterns() != null && config.getChartPatterns( ).length > 0) {
List<Accumulator> accumulators = AccumulatorRepository.ge tInstance().getAccumulators(); List<Accumulator> accumulators = AccumulatorRepository.ge tInstance().getAccumulators();
for (ChartPattern chartPattern : config.getChartPatterns( )) { for (ChartPattern chartPattern : config.getChartPatterns( )) {
List<String> matchedAccumulators = new LinkedList <>(); List<String> matchedAccumulators = new LinkedList <>();
if (chartPattern.getPatterns()!=null) { if (chartPattern.getPatterns() != null) {
for (Pattern pattern : chartPattern.getPa tterns()) { for (Pattern pattern : chartPattern.getPa tterns()) {
for (Accumulator accumulator : ac cumulators) { for (Accumulator accumulator : ac cumulators) {
if (pattern.matcher(accum ulator.getName()).matches()) { if (pattern.matcher(accum ulator.getName()).matches()) {
matchedAccumulato rs.add(accumulator.getName()); matchedAccumulato rs.add(accumulator.getName());
} }
} }
} }
}else{ } else {
log.warn("Probable misconfiguration in da log.warn("Probable misconfiguration in da
shboard "+name+", chartPattern '"+chartPattern.getCaption()+"' has no actual acc shboard " + name + ", chartPattern '" + chartPattern.getCaption() + "' has no ac
umulator patterns, "+chartPattern.toString()); tual accumulator patterns, " + chartPattern.toString());
} }
if (matchedAccumulators.size() > 0) { if (matchedAccumulators.size() > 0) {
if (chartPattern.getMode() == null) { if (chartPattern.getMode() == null) {
chartPattern.setMode(AccumulatorS etMode.COMBINED); chartPattern.setMode(AccumulatorS etMode.COMBINED);
} }
switch (chartPattern.getMode()) { switch (chartPattern.getMode()) {
case COMBINED: case COMBINED:
default: default:
skipping to change at line 504 skipping to change at line 505
chartConfig.setCa ption(StringUtils.trimString(chartConfig.buildCaption(), "", 50)); chartConfig.setCa ption(StringUtils.trimString(chartConfig.buildCaption(), "", 50));
charts.add(chartC onfig); charts.add(chartC onfig);
} }
break; break;
} }
} }
} }
} }
if (!charts.isEmpty()){ if (!charts.isEmpty()) {
LinkedList<DashboardChartAO> chartBeans = new LinkedList< DashboardChartAO>(); LinkedList<DashboardChartAO> chartBeans = new LinkedList< DashboardChartAO>();
for (ChartConfig cc : charts){ for (ChartConfig cc : charts) {
DashboardChartAO bean = new DashboardChartAO(); DashboardChartAO bean = new DashboardChartAO();
if (cc.getCaption()!=null){ if (cc.getCaption() != null) {
bean.setCaption(cc.getCaption()); bean.setCaption(cc.getCaption());
} else{ } else {
bean.setCaption(StringUtils.trimString(cc bean.setCaption(StringUtils.trimString(cc
.buildCaption(),"", 50)); .buildCaption(), "", 50));
} }
LinkedList<String> chartIds = new LinkedList<Stri ng>(); LinkedList<String> chartIds = new LinkedList<Stri ng>();
for (String cName : cc.getAccumulators()){ for (String cName : cc.getAccumulators()) {
try{ try {
AccumulatorAO accumulatorAO = acc umulatorAPI.getAccumulatorByName(cName); AccumulatorAO accumulatorAO = acc umulatorAPI.getAccumulatorByName(cName);
if (accumulatorAO!=null) if (accumulatorAO != null)
chartIds.add(accumulatorA O.getId()); chartIds.add(accumulatorA O.getId());
}catch(IllegalArgumentException e){ } catch (IllegalArgumentException e) {
//this exception is thrown if the re is no accumulator with this name registered (yet). //this exception is thrown if the re is no accumulator with this name registered (yet).
//we just skip it here, because w e don't want the whole screen to crash. //we just skip it here, because w e don't want the whole screen to crash.
if (log.isDebugEnabled()) if (log.isDebugEnabled())
log.debug("attempted to a ccess non existing accumulator with name "+cName); log.debug("attempted to a ccess non existing accumulator with name " + cName);
} }
} }
if (chartIds.size()==0){ if (chartIds.size() == 0) {
log.warn("Couldn't retrieve any chart ids log.warn("Couldn't retrieve any chart ids
for chart "+cc.toString()+", skipping this bean"); for chart " + cc.toString() + ", skipping this bean");
}else { } else {
MultilineChartAO chartAO = accumulatorAPI .getCombinedAccumulatorGraphData(chartIds); MultilineChartAO chartAO = accumulatorAPI .getCombinedAccumulatorGraphData(chartIds);
bean.setChart(chartAO); bean.setChart(chartAO);
chartBeans.add(bean); chartBeans.add(bean);
} }
} }
ret.setCharts(chartBeans); ret.setCharts(chartBeans);
} }
return ret; return ret;
} }
@Override @Override
public List<String> getDashboardNames() throws APIException { public List<String> getDashboardNames() throws APIException {
MoskitoConfiguration config = MoskitoConfigurationHolder.getConfi guration(); MoskitoConfiguration config = MoskitoConfigurationHolder.getConfi guration();
DashboardsConfig dashboardsConfig = config.getDashboardsConfig(); DashboardsConfig dashboardsConfig = config.getDashboardsConfig();
DashboardConfig[] dashboards = dashboardsConfig.getDashboards(); DashboardConfig[] dashboards = dashboardsConfig.getDashboards();
if (dashboards == null || dashboards.length==0) if (dashboards == null || dashboards.length == 0)
return Collections.emptyList(); return Collections.emptyList();
List<String> dashboardNames = new ArrayList<>(dashboards.length); List<String> dashboardNames = new ArrayList<>(dashboards.length);
for (DashboardConfig dc : dashboards){ for (DashboardConfig dc : dashboards) {
dashboardNames.add(dc.getName()); dashboardNames.add(dc.getName());
} }
return dashboardNames; return dashboardNames;
} }
@Override
public String getDashboardNamesWhichDoNotIncludeThisGauge(String gaugeNam
e) throws APIException {
StringBuilder ret = new StringBuilder();
for (DashboardConfig dashboardConfig : getConfiguredDashboards())
{
if (!dashboardConfig.containsGauge(gaugeName)) {
if (ret.length() > 0)
ret.append(',');
ret.append(dashboardConfig.getName());
}
}
return ret.toString();
}
@Override
public String getDashboardNamesWhichDoNotIncludeThisThreshold(String thre
sholdName) throws APIException {
StringBuilder ret = new StringBuilder();
for (DashboardConfig dashboardConfig : getConfiguredDashboards())
{
if (!dashboardConfig.containsThreshold(thresholdName)) {
if (ret.length() > 0)
ret.append(',');
ret.append(dashboardConfig.getName());
}
}
return ret.toString();
}
@Override
public String getDashboardNamesWhichDoNotIncludeThisChart(String chartNam
e) throws APIException {
StringBuilder ret = new StringBuilder();
for (DashboardConfig dashboardConfig : getConfiguredDashboards())
{
if (!dashboardConfig.containsChart(chartName)) {
if (ret.length() > 0)
ret.append(',');
ret.append(dashboardConfig.getName());
}
}
return ret.toString();
}
private DashboardConfig[] getConfiguredDashboards(){
MoskitoConfiguration config = MoskitoConfigurationHolder.getConfi
guration();
DashboardsConfig dashboardsConfig = config.getDashboardsConfig();
DashboardConfig[] dashboards = dashboardsConfig.getDashboards();
return dashboards;
}
} }
 End of changes. 50 change blocks. 
105 lines changed or deleted 161 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)