Skip to content

Commit

Permalink
Merge pull request #205 from hawkular/task-queue
Browse files Browse the repository at this point in the history
Initial task scheduling support
  • Loading branch information
Stefan Negrea committed May 14, 2015
2 parents 731bcf9 + 2e17e79 commit 404ef8d
Show file tree
Hide file tree
Showing 26 changed files with 2,657 additions and 6 deletions.
6 changes: 6 additions & 0 deletions core/metrics-core-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@

<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>schema-manager</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hawkular-metrics-core-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import org.hawkular.metrics.core.api.RetentionSettings;
import org.hawkular.metrics.core.api.Tenant;
import org.hawkular.metrics.core.api.TenantAlreadyExistsException;
import org.hawkular.metrics.core.impl.schema.SchemaManager;
import org.hawkular.metrics.schema.SchemaManager;
import org.joda.time.Duration;
import org.joda.time.Hours;
import org.slf4j.Logger;
Expand Down Expand Up @@ -203,7 +203,7 @@ public void startUp(Map<String, String> params) {

if (keyspace==null||keyspace.isEmpty()) {
logger.debug("No explicit keyspace given, will default to 'hawkular'");
keyspace = "hawkular-metrics";
keyspace = "hawkular_metrics";
}

logger.info("Using a key space of '" + keyspace + "'");
Expand Down
2 changes: 1 addition & 1 deletion core/metrics-core-impl/src/main/script/schema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import com.datastax.driver.core.Cluster
import com.datastax.driver.core.Session
import org.hawkular.metrics.core.impl.schema.SchemaManager
import org.hawkular.metrics.schema.SchemaManager

Cluster cluster = new Cluster.Builder()
.addContactPoint("127.0.0.1")
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@
</developers>

<modules>
<module>schema-manager</module>
<module>core/metrics-core-api</module>
<module>core/metrics-core-impl</module>
<module>task-queue</module>
<module>embedded-cassandra/embedded-cassandra-service</module>
<module>embedded-cassandra/embedded-cassandra-ear</module>
<module>api/metrics-api-jaxrs</module>
Expand Down
55 changes: 55 additions & 0 deletions schema-manager/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-parent</artifactId>
<version>0.3.4-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>schema-manager</artifactId>

<name>Schema Manager</name>
<description>Schema manager for Cassandra</description>

<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>${datastax.driver.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.metrics.core.impl.schema;
package org.hawkular.metrics.schema;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -27,7 +27,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.io.CharStreams;

import org.hawkular.metrics.core.impl.util.TokenReplacingReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.metrics.core.impl.util;
package org.hawkular.metrics.schema;

import java.io.IOException;
import java.io.PushbackReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,28 @@ CREATE TABLE ${keyspace}.counters (
c_value counter,
PRIMARY KEY ((tenant_id, group), c_name)
);

-- #

CREATE TABLE ${keyspace}.task_queue (
task_type text,
time_slice timestamp,
segment int,
target text,
sources set<text>,
interval int,
window int,
failed_time_slices set<timestamp>,
PRIMARY KEY ((task_type, time_slice, segment), target)
);

-- #

CREATE TABLE ${keyspace}.leases (
time_slice timestamp,
task_type text,
segment_offset int,
owner text,
finished boolean,
PRIMARY KEY (time_slice, task_type, segment_offset)
);
89 changes: 89 additions & 0 deletions task-queue/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-parent</artifactId>
<version>0.3.4-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>hawkular-metrics-task-queue</artifactId>
<name>Hawkular Metrics Task Queue</name>

<properties>
<test.keyspace>hawkulartest</test.keyspace>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>schema-manager</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>${datastax.driver.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<keyspace>${test.keyspace}</keyspace>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.tasks;

import static org.joda.time.DateTime.now;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Days;
import org.joda.time.Duration;
import org.joda.time.Hours;
import org.joda.time.Period;

/**
* @author jsanda
*/
public class DateTimeService {

static {
// Force the timezone to UTC to avoid any problems due to transitions from DST to non-DST
DateTimeZone.setDefault(DateTimeZone.UTC);
}

/**
* @return A DateTime object rounded down to the start of the current hour. For example, if the current time is
* 17:21:09, then 17:00:00 is returned.
*/
public DateTime currentHour() {
return getTimeSlice(now(), Hours.ONE.toStandardDuration());
}

/**
* The 24 hour time slices are fix - 00:00 to 24:00. This method determines the 24 hour time slice based on
* {@link #currentHour()} and returns the start of the time slice.
*
* @return A DateTime object rounded down to the start of the current 24 hour time slice.
*/
public DateTime current24HourTimeSlice() {
return get24HourTimeSlice(currentHour());
}

/**
* This method determines the 24 hour time slice for the specified time and returns the start of that time slice.
*
* @param time The DateTime to be rounded down
* @return A DateTime rounded down to the start of the 24 hour time slice in which the time parameter falls.
* @see #current24HourTimeSlice()
*/
public DateTime get24HourTimeSlice(DateTime time) {
return getTimeSlice(time, Days.ONE.toStandardDuration());
}

public DateTime getTimeSlice(DateTime dt, Duration duration) {
Period p = duration.toPeriod();

if (p.getYears() != 0) {
return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
} else if (p.getMonths() != 0) {
return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
} else if (p.getWeeks() != 0) {
return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
} else if (p.getDays() != 0) {
return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
} else if (p.getHours() != 0) {
return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
} else if (p.getMinutes() != 0) {
return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
} else if (p.getSeconds() != 0) {
return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
}
return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

}

0 comments on commit 404ef8d

Please sign in to comment.