Skip to content

Commit

Permalink
[HWKMETRICS] need to inject a TaskService into MetricsServiceImpl now
Browse files Browse the repository at this point in the history
  • Loading branch information
John Sanda committed Jun 19, 2015
1 parent 0ccfc50 commit 2cbc856
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
import org.hawkular.metrics.api.jaxrs.util.Eager;
import org.hawkular.metrics.core.api.MetricsService;
import org.hawkular.metrics.core.impl.MetricsServiceImpl;
import org.hawkular.metrics.tasks.api.Task;
import org.hawkular.metrics.tasks.api.TaskService;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -52,6 +55,7 @@
import com.google.common.base.Throwables;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.Uninterruptibles;
import rx.Observable;

/**
* Bean created on startup to manage the lifecycle of the {@link MetricsService} instance shared in application scope.
Expand Down Expand Up @@ -106,6 +110,20 @@ public enum State {
MetricsServiceLifecycle() {
// Create the shared instance now and initialize it with the C* session when ready
metricsService = new MetricsServiceImpl();
metricsService.setTaskService(new TaskService() {
@Override
public void start() {
}

@Override
public void shutdown() {
}

@Override
public Observable<Task> scheduleTask(DateTime time, Task task) {
throw new UnsupportedOperationException("Task scheduling is not yet supported");
}
});
ThreadFactory threadFactory = r -> {
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setName(MetricsService.class.getSimpleName().toLowerCase(Locale.ROOT) + "-lifecycle-thread");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ public Observable<ResultSet> insertAvailabilityTag(String tag, String tagValue,
new BatchStatement(UNLOGGED),
(batch, a) -> {
batch.add(insertAvailabilityTags.bind(metric.getTenantId(), tag, tagValue,
MetricType.AVAILABILITY.getCode(), metric.getId().getName(), metric.getId().getInterval()
.toString(), getTimeUUID(a.getDataPoint().getTimestamp()), getBytes(a.getDataPoint()),
a.getTTL()));
MetricType.AVAILABILITY.getCode(), metric.getId().getName(),
metric.getId().getInterval().toString(), getTimeUUID(a.getDataPoint().getTimestamp()),
getBytes(a.getDataPoint()), a.getTTL()));
return batch;
}).flatMap(rxSession::execute);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.metrics.core.impl;

import java.util.Set;

import org.hawkular.metrics.tasks.api.Task;
import org.hawkular.metrics.tasks.api.TaskService;
import org.hawkular.metrics.tasks.api.TaskType;
import org.joda.time.DateTime;
import rx.Observable;

/**
* @author jsanda
*/
public class FakeTaskService implements TaskService {

@Override
public void start() {
}

@Override
public void shutdown() {
}

@Override
public Observable<Task> scheduleTask(DateTime time, Task task) {
return Observable.just(new Task() {
@Override
public TaskType getTaskType() {
return task.getTaskType();
}

@Override
public String getTarget() {
return task.getTarget();
}

@Override
public Set<String> getSources() {
return task.getSources();
}

@Override
public int getInterval() {
return task.getInterval();
}

@Override
public int getWindow() {
return task.getWindow();
}

@Override
public DateTime getTimeSlice() {
return time;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class MetricsServiceITest extends MetricsITest {
public void initClass() {
initSession();
metricsService = new MetricsServiceImpl();
metricsService.setTaskService(new FakeTaskService());
metricsService.startUp(session, getKeyspace(), false, new MetricRegistry());
dataAccess = metricsService.getDataAccess();

Expand Down Expand Up @@ -330,10 +331,10 @@ public void addAndFetchCounterData() throws Exception {
start.getMillis(), end.getMillis());
List<DataPoint<Long>> actual = toList(data);
List<DataPoint<Long>> expected = asList(
new DataPoint<>(start.getMillis(), 10L),
new DataPoint<>(start.plusMinutes(2).getMillis(), 15L),
new DataPoint<>(end.getMillis(), 45L),
new DataPoint<>(start.plusMinutes(4).getMillis(), 25L),
new DataPoint<>(end.getMillis(), 45L)
new DataPoint<>(start.plusMinutes(2).getMillis(), 15L),
new DataPoint<>(start.getMillis(), 10L)
);

assertEquals(actual, expected, "The counter data does not match the expected values");
Expand Down

0 comments on commit 2cbc856

Please sign in to comment.