Skip to content

Commit

Permalink
Moving and extracting DTOs to proper places.
Browse files Browse the repository at this point in the history
(cherry picked from commit 5a0c646)

Conflicts:
	graylog2-rest-client/src/main/java/org/graylog2/restclient/models/Radio.java
	graylog2-rest-models/src/main/java/org/graylog2/rest/models/sources/responses/SourcesList.java
	graylog2-server/src/main/java/org/graylog2/rest/resources/system/DeflectorResource.java
  • Loading branch information
dennisoelkers committed Mar 25, 2015
1 parent 09ab41f commit f9005fa
Show file tree
Hide file tree
Showing 91 changed files with 361 additions and 179 deletions.
Expand Up @@ -18,6 +18,7 @@


import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.graylog2.rest.models.system.buffers.responses.BuffersUtilizationSummary;
import org.graylog2.restclient.models.api.responses.BufferSummaryResponse; import org.graylog2.restclient.models.api.responses.BufferSummaryResponse;
import org.graylog2.restclient.models.api.responses.BuffersResponse; import org.graylog2.restclient.models.api.responses.BuffersResponse;


Expand All @@ -35,6 +36,12 @@ public BufferInfo(BuffersResponse br) {
outputBuffer = br.buffers.get("output"); outputBuffer = br.buffers.get("output");
} }


public BufferInfo(BuffersUtilizationSummary bus) {
inputBuffer = BufferSummaryResponse.fromSingleRingUtilization(bus.buffers().input());
processBuffer = BufferSummaryResponse.EMPTY;
outputBuffer = BufferSummaryResponse.fromSingleRingUtilization(bus.buffers().output());
}

public BufferSummaryResponse getInputBuffer() { public BufferSummaryResponse getInputBuffer() {
return MoreObjects.firstNonNull(inputBuffer, BufferSummaryResponse.EMPTY); return MoreObjects.firstNonNull(inputBuffer, BufferSummaryResponse.EMPTY);
} }
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject; import com.google.inject.assistedinject.AssistedInject;
import org.graylog2.rest.models.system.buffers.responses.BufferClasses;
import org.graylog2.rest.models.system.inputs.requests.InputLaunchRequest; import org.graylog2.rest.models.system.inputs.requests.InputLaunchRequest;
import org.graylog2.restclient.lib.APIException; import org.graylog2.restclient.lib.APIException;
import org.graylog2.restclient.lib.ApiClient; import org.graylog2.restclient.lib.ApiClient;
Expand Down Expand Up @@ -91,13 +92,13 @@ public interface Factory {
private AtomicInteger failureCount = new AtomicInteger(0); private AtomicInteger failureCount = new AtomicInteger(0);


private BufferInfo bufferInfo; private BufferInfo bufferInfo;
private BufferClassesResponse bufferClasses; private BufferClasses bufferClasses;
private JournalInfo journalInfo; private JournalInfo journalInfo;


/* for initial set up in test */ /* for initial set up in test */
public Node(NodeSummaryResponse r) { /*public Node(NodeSummaryResponse r) {
this(null, null, null, r); this(null, null, null, r);
} }*/


@AssistedInject @AssistedInject
public Node(ApiClient api, public Node(ApiClient api,
Expand Down Expand Up @@ -152,9 +153,10 @@ public BufferInfo loadBufferInfo() {
return BufferInfo.buildEmpty(); return BufferInfo.buildEmpty();
} }


public synchronized BufferClassesResponse getBufferClasses() { public synchronized BufferClasses getBufferClasses() {
if (this.bufferClasses == null) { if (this.bufferClasses == null) {
this.bufferClasses = loadBufferClasses(); final BufferClassesResponse response = loadBufferClasses();
this.bufferClasses = BufferClasses.create(response.processBufferClass, response.outputBufferClass);
} }
return this.bufferClasses; return this.bufferClasses;
} }
Expand Down Expand Up @@ -187,7 +189,7 @@ public JournalInfo loadJournalInfo() {
public Map<String, InternalLoggerSubsystem> allLoggerSubsystems() { public Map<String, InternalLoggerSubsystem> allLoggerSubsystems() {
Map<String, InternalLoggerSubsystem> subsystems = Maps.newHashMap(); Map<String, InternalLoggerSubsystem> subsystems = Maps.newHashMap();
try { try {
LoggerSubsystemsResponse response = api.path(routes.LoggersResource().subsytems(), LoggerSubsystemsResponse.class) LoggerSubsystemsResponse response = api.path(routes.LoggersResource().subsystems(), LoggerSubsystemsResponse.class)
.node(this) .node(this)
.execute(); .execute();


Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.graylog2.restclient.models.api.responses; package org.graylog2.restclient.models.api.responses;


import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.graylog2.rest.models.system.buffers.responses.SingleRingUtilization;


/** /**
* @author Lennart Koopmann <lennart@torch.sh> * @author Lennart Koopmann <lennart@torch.sh>
Expand All @@ -29,4 +30,11 @@ public class BufferSummaryResponse {
@JsonProperty("utilization_percent") @JsonProperty("utilization_percent")
public float utilizationPercent; public float utilizationPercent;


public static BufferSummaryResponse fromSingleRingUtilization(SingleRingUtilization sru) {
final BufferSummaryResponse bur = new BufferSummaryResponse();
bur.utilization = sru.utilization();
bur.utilizationPercent = sru.utilizationPercent();

return bur;
}
} }
8 changes: 8 additions & 0 deletions graylog2-rest-models/pom.xml
Expand Up @@ -52,5 +52,13 @@
<groupId>joda-time</groupId> <groupId>joda-time</groupId>
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-bean-validation</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.count.responses; package org.graylog2.rest.models.count.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.dashboards.requests; package org.graylog2.rest.models.dashboards.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.dashboards.requests; package org.graylog2.rest.models.dashboards.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.dashboards.requests; package org.graylog2.rest.models.dashboards.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.dashboards.requests; package org.graylog2.rest.models.dashboards.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.dashboards.responses; package org.graylog2.rest.models.dashboards.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Expand Up @@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.messages.responses; package org.graylog2.rest.models.messages.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;


Expand All @@ -28,7 +29,8 @@ public abstract class MessageTokens {
@JsonProperty @JsonProperty
public abstract List<String> tokens(); public abstract List<String> tokens();


public static MessageTokens create(List<String> tokens) { @JsonCreator
public static MessageTokens create(@JsonProperty("tokens") List<String> tokens) {
return new AutoValue_MessageTokens(tokens); return new AutoValue_MessageTokens(tokens);
} }
} }
@@ -0,0 +1,30 @@
package org.graylog2.rest.models.messages.responses;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import com.google.common.collect.Multimap;
import com.google.common.collect.Range;

import java.util.Map;

@AutoValue
@JsonAutoDetect
public abstract class ResultMessageSummary {
@JsonProperty("highlight_ranges")
public abstract Multimap<String, Range<Integer>> highlightRanges();

@JsonProperty
public abstract Map<String, Object> message();

@JsonProperty
public abstract String index();

@JsonCreator
public static ResultMessageSummary create(@JsonProperty("highlight_ranges") Multimap<String, Range<Integer>> highlightRanges,
@JsonProperty("message") Map<String, Object> message,
@JsonProperty("index") String index) {
return new AutoValue_ResultMessageSummary(highlightRanges, message, index);
}
}
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.search.responses; package org.graylog2.rest.models.search.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.search.responses; package org.graylog2.rest.models.search.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.search.responses; package org.graylog2.rest.models.search.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Expand Up @@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.search.responses; package org.graylog2.rest.models.search.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;


Expand All @@ -35,7 +36,8 @@ public abstract class TermsStatsResult {
@JsonProperty @JsonProperty
public abstract String builtQuery(); public abstract String builtQuery();


public static TermsStatsResult create(long time, List<Map<String, Object>> terms, String builtQuery) { @JsonCreator
public static TermsStatsResult create(@JsonProperty("time") long time, @JsonProperty("terms") List<Map<String, Object>> terms, @JsonProperty("built_query") String builtQuery) {
return new AutoValue_TermsStatsResult(time, terms, builtQuery); return new AutoValue_TermsStatsResult(time, terms, builtQuery);
} }
} }
Expand Up @@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.search.responses; package org.graylog2.rest.models.search.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import org.joda.time.DateTime; import org.joda.time.DateTime;
Expand All @@ -30,7 +31,8 @@ public abstract class TimeRange {
@JsonProperty @JsonProperty
public abstract DateTime to(); public abstract DateTime to();


public static TimeRange create(DateTime from, DateTime to) { @JsonCreator
public static TimeRange create(@JsonProperty("from") DateTime from, @JsonProperty("to") DateTime to) {
return new AutoValue_TimeRange(from, to); return new AutoValue_TimeRange(from, to);
} }
} }
Expand Up @@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.sources.responses; package org.graylog2.rest.models.sources.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;


Expand All @@ -37,7 +38,11 @@ public abstract class SourcesList {
@JsonProperty @JsonProperty
public abstract int range(); public abstract int range();


public static SourcesList create(int total, Map<String, Long> sources, long tookMs, int range) { @JsonCreator
public static SourcesList create(@JsonProperty("total") int total,
@JsonProperty("sources") Map<String, Long> sources,
@JsonProperty("took_ms") long tookMs,
@JsonProperty("range") int range) {
return new AutoValue_SourcesList(total, sources, tookMs, range); return new AutoValue_SourcesList(total, sources, tookMs, range);
} }


Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.streams.alerts.requests; package org.graylog2.rest.models.streams.alerts.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,12 +14,12 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.streams.outputs; package org.graylog2.rest.models.streams.outputs;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import org.graylog2.plugin.streams.Output;
import org.graylog2.rest.models.system.outputs.responses.OutputSummary; import org.graylog2.rest.models.system.outputs.responses.OutputSummary;


import java.util.Collection; import java.util.Collection;
Expand All @@ -33,7 +33,8 @@ public abstract class OutputListResponse {
@JsonProperty @JsonProperty
public abstract Collection<OutputSummary> outputs(); public abstract Collection<OutputSummary> outputs();


public static OutputListResponse create(long total, Collection<OutputSummary> outputs) { @JsonCreator
public static OutputListResponse create(@JsonProperty("total") long total, @JsonProperty("outputs") Collection<OutputSummary> outputs) {
return new AutoValue_OutputListResponse(total, outputs); return new AutoValue_OutputListResponse(total, outputs);
} }


Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.streams.outputs; package org.graylog2.rest.models.streams.outputs.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.streams.outputs; package org.graylog2.rest.models.streams.outputs.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.resources.system.indexer.responses; package org.graylog2.rest.models.system.indexer.responses;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;


Expand All @@ -31,7 +32,8 @@ public abstract class ClosedIndices {
@JsonProperty @JsonProperty
public abstract int total(); public abstract int total();


public static ClosedIndices create(Set<String> indices, int total) { @JsonCreator
public static ClosedIndices create(@JsonProperty("indices") Set<String> indices, @JsonProperty("total") int total) {
return new AutoValue_ClosedIndices(indices, total); return new AutoValue_ClosedIndices(indices, total);
} }
} }

0 comments on commit f9005fa

Please sign in to comment.