Skip to content

Commit

Permalink
[HWKMETRICS-185] Create a common module to store classes used by both…
Browse files Browse the repository at this point in the history
… JAX-RS implementations.
  • Loading branch information
Stefan Negrea committed Jul 27, 2015
1 parent a8a7d7c commit 2f9597c
Show file tree
Hide file tree
Showing 21 changed files with 1,438 additions and 2 deletions.
116 changes: 116 additions & 0 deletions api/metrics-api-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?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.6.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>hawkular-metrics-api-common</artifactId>
<packaging>bundle</packaging>

<name>Hawkular Metrics Public API Common</name>
<description>Hawkular Metrics Public API Common</description>

<dependencies>
<dependency>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-core-impl</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-core-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

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

<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
</dependency>

<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-math</artifactId>
</dependency>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<scope>provided</scope>
</dependency>

<!-- test -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<!-- documentation -->
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.10</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.api.jaxrs;

import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;

/**
* Return information what failed in the REST-call.
* @author Michael Burman
*/
@ApiModel(description = "If REST-call returns other than success, detailed error is returned.")
public class ApiError {
private final String errorMsg;

public ApiError(String errorMsg) {
this.errorMsg = errorMsg;
}

@ApiModelProperty(value = "Detailed error message of what happened")
public String getErrorMsg() {
return errorMsg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.api.jaxrs.model;

import static java.util.Collections.unmodifiableList;

import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.wordnik.swagger.annotations.ApiModel;

/**
* A container for availability data points to be persisted. Note that the tenant id is not included because it is
* obtained from the tenant header in the HTTP request.
*
* @author jsanda
*/
@ApiModel(description = "An availability metric with one or more data points")
public class Availability {

@JsonProperty
private String id;

@JsonProperty
private List<AvailabilityDataPoint> data;

public String getId() {
return id;
}

public List<AvailabilityDataPoint> getData() {
return unmodifiableList(data);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Availability that = (Availability) o;
return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return "Availability{" +
"id='" + id + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.api.jaxrs.model;

import static java.util.Collections.emptyMap;

import java.util.Map;
import java.util.Objects;

import org.hawkular.metrics.core.api.AvailabilityType;
import org.hawkular.metrics.core.api.DataPoint;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import com.wordnik.swagger.annotations.ApiModel;

/**
* @author jsanda
*/
@ApiModel(description = "Consists of a timestamp and a value where supported values are \"up\" and \"down\"")
public class AvailabilityDataPoint {

@JsonProperty
private long timestamp;

@JsonProperty
private String value;

@JsonProperty
private Map<String, String> tags = emptyMap();

/**
* Used by JAX-RS/Jackson to deserialize HTTP request data
*/
private AvailabilityDataPoint() {
}

/**
* Used to prepared data for serialization into the HTTP response
*
* @param dataPoint
*/
public AvailabilityDataPoint(DataPoint<AvailabilityType> dataPoint) {
timestamp = dataPoint.getTimestamp();
value = dataPoint.getValue().getText().toLowerCase();
tags = dataPoint.getTags();
}

public long getTimestamp() {
return timestamp;
}

public String getValue() {
return value.toLowerCase();
}

public Map<String, String> getTags() {
return ImmutableMap.copyOf(tags);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AvailabilityDataPoint dataPoint = (AvailabilityDataPoint) o;
return Objects.equals(timestamp, dataPoint.timestamp) &&
Objects.equals(value, dataPoint.value);
}

@Override
public int hashCode() {
return Objects.hash(timestamp, value);
}

@Override
public String toString() {
return com.google.common.base.Objects.toStringHelper(this)
.add("timestamp", timestamp)
.add("value", value)
.add("tags", tags)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.api.jaxrs.model;

import static java.util.Collections.unmodifiableList;

import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* A container for data points for a single counter metric.
*
* @author jsanda
*/
public class Counter {

@JsonProperty
private String id;

@JsonProperty
private List<CounterDataPoint> data;

public String getId() {
return id;
}

public List<CounterDataPoint> getData() {
return unmodifiableList(data);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Counter gauge = (Counter) o;
return Objects.equals(id, gauge.id) &&
Objects.equals(data, gauge.data);
}

@Override
public int hashCode() {
return Objects.hash(id, data);
}

@Override
public String toString() {
return com.google.common.base.Objects.toStringHelper(this)
.add("id", id)
.add("data", data)
.toString();
}

}

0 comments on commit 2f9597c

Please sign in to comment.