private void calculateAndDeliverAggregationValue(final AggregationVariableSet variables) { final double aggregationValue; final NamedDoubleTimeSeriesPoint tsPoint; synchronized (this) { final int listSize = variables.getAggregationList().size(); final double[] a = new double[listSize]; for (int i = 0; i < listSize; i++) { a[i] = variables.getAggregationList().get(i).getValue(); } aggregationValue = this.aggregationMethod.getAggregationValue(a); tsPoint = new NamedDoubleTimeSeriesPoint(variables.getLastTimestampInCurrentInterval(), aggregationValue, variables.getAggregationList().get(0).getName()); // use name of first element (any will do) variables.getAggregationList().clear(); } super.deliver(OUTPUT_PORT_NAME_AGGREGATED_TSPOINT, tsPoint); }
/** * Represents the input port for measurements. * * @param input * Incoming measurements */ @InputPort(eventTypes = { NamedDoubleTimeSeriesPoint.class }, name = ForecastingFilter.INPUT_PORT_NAME_TSPOINT) public void inputEvent(final NamedDoubleTimeSeriesPoint input) { if (this.checkInitialization(input.getName())) { this.processInput(input, input.getTime(), input.getName()); } else { // Initialization of the forecasting variables for a new application this.applicationForecastingWindow.put(input.getName(), new TimeSeries<Double>(input.getTime(), super.recordsTimeUnitFromProjectContext, this.deltat.get(), this.timeSeriesWindowCapacity.get())); this.processInput(input, input.getTime(), input.getName()); } }
private synchronized void processInputVariableScope(final NamedDoubleTimeSeriesPoint input) { // NOPMD (AvoidSynchronizedAtMethodLevel) final long currentTime = input.getTime(); final String appname = input.getName(); final AggregationVariableSet variables = this.aggregationVariables.get(appname); final long startOfTimestampsInterval = this.computeFirstTimestampInInterval(currentTime, variables); final long endOfTimestampsInterval = this.computeLastTimestampInInterval(currentTime, variables); if (this.recentWindow.getWindowEnd() != endOfTimestampsInterval) { this.recentWindow = new AggregationWindow(startOfTimestampsInterval, endOfTimestampsInterval); super.deliver(OUTPUT_PORT_NAME_AGGREGATION_WINDOW, this.recentWindow); } // check if interval is omitted if (endOfTimestampsInterval > variables.getLastTimestampInCurrentInterval()) { if (variables.getFirstTimestampInCurrentInterval() >= 0) { // don't do this for the first record (only used for initialization of variables) this.calculateAndDeliverAggregationValue(variables); long numIntervalsElapsed = 1; // refined below numIntervalsElapsed = (endOfTimestampsInterval - variables.getLastTimestampInCurrentInterval()) / this.aggregationSpan; if (numIntervalsElapsed > 1) { for (int i = 1; i < numIntervalsElapsed; i++) { super.deliver(OUTPUT_PORT_NAME_AGGREGATED_TSPOINT, new NamedDoubleTimeSeriesPoint(variables.getLastTimestampInCurrentInterval() + (i * this.aggregationSpan), Double.NaN, // Note: Count filter should use 0.0 appname)); } } } variables.setFirstTimestampInCurrentInterval(startOfTimestampsInterval); variables.setLastTimestampInCurrentInterval(endOfTimestampsInterval); variables.getAggregationList().clear(); } variables.getAggregationList().add(input); }
controller); listReader.addObject(new NamedDoubleTimeSeriesPoint(1L, 3.0, OP_SIGNATURE_A)); listReader.addObject(new NamedDoubleTimeSeriesPoint(13L, 13.0, OP_SIGNATURE_A)); listReader.addObject(new NamedDoubleTimeSeriesPoint(16L, 16.0, OP_SIGNATURE_A)); Assert.assertEquals(5L, sinkPlugin.getList().get(0).getTime()); Assert.assertEquals(10L, sinkPlugin.getList().get(1).getTime()); Assert.assertEquals(15L, sinkPlugin.getList().get(2).getTime()); Assert.assertEquals(Double.NaN, sinkPlugin.getList().get(1).getDoubleValue(), 0.001d);
theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(1L, 1000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(5L, 1000.0, OP_SIGNATURE_C)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(5L, 1000.0, OP_SIGNATURE_D)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(8L, 2000.0, OP_SIGNATURE_B)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(10L, 2000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(11L, 3000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(12L, 4000.0, OP_SIGNATURE_B)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(18L, 5000.0, OP_SIGNATURE_C)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(18L, 5000.0, OP_SIGNATURE_D)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(18L, 5000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(28L, 6000.0, OP_SIGNATURE_B)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(10L, 7000.0, OP_SIGNATURE_C)); // should be ignored by the filter theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(17L, 7000.0, OP_SIGNATURE_B)); // should be ignored by the filter theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(48L, 7000.0, OP_SIGNATURE_C)); Assert.assertEquals(OP_SIGNATURE_A, sinkList.get(0).getName()); Assert.assertEquals(1500.0, sinkList.get(0).getDoubleValue(), EPSILON); Assert.assertEquals(1000.0, sinkList.get(1).getDoubleValue(), EPSILON); Assert.assertEquals(1000.0, sinkList.get(2).getDoubleValue(), EPSILON); this.assertAppNames(sinkList, 1, 2); Assert.assertEquals(OP_SIGNATURE_B, sinkList.get(3).getName()); Assert.assertEquals(3000.0, sinkList.get(3).getDoubleValue(), EPSILON); Assert.assertEquals(OP_SIGNATURE_A, sinkList.get(4).getName()); Assert.assertEquals(4000.0, sinkList.get(4).getDoubleValue(), EPSILON); Assert.assertEquals(5000.0, sinkList.get(5).getDoubleValue(), EPSILON);
private NamedDoubleTimeSeriesPoint calculateAggregationValueOfCurrentInterval(final AggregationVariableSet variables, final String name) { final double aggregationValue; final NamedDoubleTimeSeriesPoint tsPoint; final long firstTimestampInCurrentInterval = variables.getFirstTimestampInCurrentInterval(); final long lastTimestampInCurrentInterval = variables.getLastTimestampInCurrentInterval(); synchronized (this) { final int listSize = variables.getAggregationList().size(); if (listSize <= 0) { tsPoint = new NamedDoubleTimeSeriesPoint(lastTimestampInCurrentInterval, Double.NaN, name); } else { final double[] a = new double[listSize]; for (int i = 0; i < listSize; i++) { a[i] = variables.getAggregationList().get(i).getValue(); } aggregationValue = this.aggregationMethod.getAggregationValue(a); tsPoint = new NamedDoubleTimeSeriesPoint(lastTimestampInCurrentInterval, aggregationValue, name); variables.getAggregationList().clear(); } variables.setFirstTimestampInCurrentInterval(firstTimestampInCurrentInterval + this.aggregationSpan); variables.setLastTimestampInCurrentInterval(lastTimestampInCurrentInterval + this.aggregationSpan); } return tsPoint; }
/** * Test the extraction of the data from ResponseTimeDoubleRecords. * * @throws InterruptedException * If interrupted */ @Test public void testResponsetimeOnly() throws InterruptedException { final AnalysisControllerThread thread = new AnalysisControllerThread(this.controller); thread.start(); Thread.sleep(2000); thread.terminate(); Assert.assertEquals(3, this.sinkPlugin.getList().size()); // Test on the timestamp conversion (here as configured to milliseconds Assert.assertEquals(1369127, this.sinkPlugin.getList().get(0).getTime(), 0); Assert.assertEquals(1369128, this.sinkPlugin.getList().get(1).getTime(), 0); Assert.assertEquals(1369129, this.sinkPlugin.getList().get(2).getTime(), 0); // Test on the extracted values Assert.assertEquals(10341.94, this.sinkPlugin.getList().get(0).getDoubleValue(), 0); Assert.assertEquals(8341.00, this.sinkPlugin.getList().get(1).getDoubleValue(), 0); Assert.assertEquals(78.26, this.sinkPlugin.getList().get(2).getDoubleValue(), 0); } }
theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(664L, 1000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(665L, 2000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(664L, 1000.0, OP_SIGNATURE_C)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(668L, 5500.0, OP_SIGNATURE_C)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(674L, 2000.0, OP_SIGNATURE_B)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(674L, 3000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(684L, 4000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(674L, 2000.0, OP_SIGNATURE_C)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(684L, 5000.0, OP_SIGNATURE_B)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(687L, 1000.0, OP_SIGNATURE_B)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(714L, 6000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(724L, 7000.0, OP_SIGNATURE_A)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(694L, 5000.0, OP_SIGNATURE_B)); theReaderAggregator.addObject(new NamedDoubleTimeSeriesPoint(714L, 5000.0, OP_SIGNATURE_B)); Assert.assertEquals(Double.valueOf(1500), Double.valueOf(sinkPlugin.getList().get(0).getDoubleValue())); Assert.assertEquals(Double.valueOf(3000), Double.valueOf(sinkPlugin.getList().get(1).getDoubleValue())); Assert.assertEquals(Double.valueOf(3250), Double.valueOf(sinkPlugin.getList().get(2).getDoubleValue())); Assert.assertEquals(Double.valueOf(2000), Double.valueOf(sinkPlugin.getList().get(3).getDoubleValue())); Assert.assertEquals(Double.valueOf(4000), Double.valueOf(sinkPlugin.getList().get(4).getDoubleValue())); Assert.assertEquals(Double.NaN, sinkPlugin.getList().get(5).getDoubleValue(), 0.0000001d); Assert.assertEquals(Double.NaN, sinkPlugin.getList().get(6).getDoubleValue(), 0.0000001d);
private NamedDoubleTimeSeriesPoint createNDTSP(final String signature, final double value) { return new NamedDoubleTimeSeriesPoint(System.currentTimeMillis(), value, signature); }
private void assertAppNames(final List<NamedDoubleTimeSeriesPoint> sinkList, final int firstIndex, final int secondIndex) throws AssertionError { // the order of the app names varies from execution to execution since the aggregation filter uses an unsorted map final String firstAppName = sinkList.get(firstIndex).getName(); final String secondAppName = sinkList.get(secondIndex).getName(); if (OP_SIGNATURE_D.equals(firstAppName)) { Assert.assertEquals(OP_SIGNATURE_C, secondAppName); } else if (OP_SIGNATURE_C.equals(firstAppName)) { Assert.assertEquals(OP_SIGNATURE_D, secondAppName); } else { throw new AssertionError("Unexpected app name: " + firstAppName); } } }
private void addNewTsPoint(final Map<Long, List<NamedDoubleTimeSeriesPoint>> orderedTsPoints, final NamedDoubleTimeSeriesPoint newTsPoint) { final long newTsPointTimestamp = newTsPoint.getTime(); if (!orderedTsPoints.containsKey(newTsPointTimestamp)) { orderedTsPoints.put(newTsPointTimestamp, new ArrayList<NamedDoubleTimeSeriesPoint>()); } final List<NamedDoubleTimeSeriesPoint> tsPointList = orderedTsPoints.get(newTsPointTimestamp); tsPointList.add(newTsPoint); }
public double getDoubleValue() { return this.getValue(); }
private synchronized void processInputVariableScope(final NamedDoubleTimeSeriesPoint input) { // NOPMD (AvoidSynchronizedAtMethodLevel) final long currentTime = input.getTime(); final String appname = input.getName(); final AggregationVariableSet variables = this.aggregationVariables.get(appname); final long startOfTimestampsInterval = this.computeFirstTimestampInInterval(currentTime, variables); final long endOfTimestampsInterval = this.computeLastTimestampInInterval(currentTime, variables); if (this.recentWindow.getWindowEnd() != endOfTimestampsInterval) { this.recentWindow = new AggregationWindow(startOfTimestampsInterval, endOfTimestampsInterval); super.deliver(OUTPUT_PORT_NAME_AGGREGATION_WINDOW, this.recentWindow); } // check if interval is omitted if (endOfTimestampsInterval > variables.getLastTimestampInCurrentInterval()) { if (variables.getFirstTimestampInCurrentInterval() >= 0) { // don't do this for the first record (only used for initialization of variables) this.calculateAndDeliverAggregationValue(variables); long numIntervalsElapsed = 1; // refined below numIntervalsElapsed = (endOfTimestampsInterval - variables.getLastTimestampInCurrentInterval()) / this.aggregationSpan; if (numIntervalsElapsed > 1) { for (int i = 1; i < numIntervalsElapsed; i++) { super.deliver(OUTPUT_PORT_NAME_AGGREGATED_TSPOINT, new NamedDoubleTimeSeriesPoint(variables.getLastTimestampInCurrentInterval() + (i * this.aggregationSpan), Double.NaN, // Note: Count filter should use 0.0 appname)); } } } variables.setFirstTimestampInCurrentInterval(startOfTimestampsInterval); variables.setLastTimestampInCurrentInterval(endOfTimestampsInterval); variables.getAggregationList().clear(); } variables.getAggregationList().add(input); }
controller); listReader.addObject(new NamedDoubleTimeSeriesPoint(1000000L, 3.0, OP_SIGNATURE_A)); listReader.addObject(new NamedDoubleTimeSeriesPoint(13000000L, 13.0, OP_SIGNATURE_A)); listReader.addObject(new NamedDoubleTimeSeriesPoint(16000000L, 16.0, OP_SIGNATURE_A)); Assert.assertEquals(5999999L, sinkPlugin.getList().get(0).getTime()); Assert.assertEquals(10999999L, sinkPlugin.getList().get(1).getTime()); Assert.assertEquals(15999999L, sinkPlugin.getList().get(2).getTime()); Assert.assertEquals(Double.NaN, sinkPlugin.getList().get(1).getDoubleValue(), 0.001d);
private NamedDoubleTimeSeriesPoint calculateAggregationValueOfCurrentInterval(final AggregationVariableSet variables, final String name) { final double aggregationValue; final NamedDoubleTimeSeriesPoint tsPoint; final long firstTimestampInCurrentInterval = variables.getFirstTimestampInCurrentInterval(); final long lastTimestampInCurrentInterval = variables.getLastTimestampInCurrentInterval(); synchronized (this) { final int listSize = variables.getAggregationList().size(); if (listSize <= 0) { tsPoint = new NamedDoubleTimeSeriesPoint(lastTimestampInCurrentInterval, Double.NaN, name); } else { final double[] a = new double[listSize]; for (int i = 0; i < listSize; i++) { a[i] = variables.getAggregationList().get(i).getValue(); } aggregationValue = this.aggregationMethod.getAggregationValue(a); tsPoint = new NamedDoubleTimeSeriesPoint(lastTimestampInCurrentInterval, aggregationValue, name); variables.getAggregationList().clear(); } variables.setFirstTimestampInCurrentInterval(firstTimestampInCurrentInterval + this.aggregationSpan); variables.setLastTimestampInCurrentInterval(lastTimestampInCurrentInterval + this.aggregationSpan); } return tsPoint; }
@InputPort(name = INPUT_PORT_NAME_VALUE, eventTypes = { NamedDoubleRecord.class }) public void inputExecutionRecord(final NamedDoubleRecord record) { final long timestampMillis = this.timeunit.convert(record.getTimestamp(), super.recordsTimeUnitFromProjectContext); final NamedDoubleTimeSeriesPoint tspoint = new NamedDoubleTimeSeriesPoint(timestampMillis, record.getResponseTime(), record.getApplicationName()); super.deliver(OUTPUT_PORT_NAME_VALUE, tspoint); }
/** * This method represents the input port for the incoming measurements. * * @param input * The next incoming measurement */ @InputPort(eventTypes = { NamedDoubleTimeSeriesPoint.class }, name = TimeSeriesPointAggregatorFilter.INPUT_PORT_NAME_TSPOINT) public void inputTSPoint(final NamedDoubleTimeSeriesPoint input) { final String name = input.getName(); this.aggregationVariables.putIfAbsent(name, new AggregationVariableSet()); if (this.aggregationTimescopeGlobal) { this.processInputGlobalScope(input); } else { this.processInputVariableScope(input); } }
private void addNewTsPoint(final Map<Long, List<NamedDoubleTimeSeriesPoint>> orderedTsPoints, final NamedDoubleTimeSeriesPoint newTsPoint) { final long newTsPointTimestamp = newTsPoint.getTime(); if (!orderedTsPoints.containsKey(newTsPointTimestamp)) { orderedTsPoints.put(newTsPointTimestamp, new ArrayList<NamedDoubleTimeSeriesPoint>()); } final List<NamedDoubleTimeSeriesPoint> tsPointList = orderedTsPoints.get(newTsPointTimestamp); tsPointList.add(newTsPoint); }
public double getDoubleValue() { return this.getValue(); }
/** * Represents the input port for measurements. * * @param input * Incoming measurements */ @InputPort(eventTypes = { NamedDoubleTimeSeriesPoint.class }, name = ForecastingFilter.INPUT_PORT_NAME_TSPOINT) public void inputEvent(final NamedDoubleTimeSeriesPoint input) { if (this.checkInitialization(input.getName())) { this.processInput(input, input.getTime(), input.getName()); } else { // Initialization of the forecasting variables for a new application this.applicationForecastingWindow.put(input.getName(), new TimeSeries<Double>(input.getTime(), super.recordsTimeUnitFromProjectContext, this.deltat.get(), this.timeSeriesWindowCapacity.get())); this.processInput(input, input.getTime(), input.getName()); } }