Skip to content

Commit

Permalink
Remove radio-related JAX-RS resources and service methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Schalanda committed Oct 15, 2015
1 parent c61d3fe commit 1a65b86
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 179 deletions.
Expand Up @@ -52,12 +52,12 @@ public GELFKafkaInput(@Assisted Configuration configuration,

protected GELFKafkaInput(MetricRegistry metricRegistry,
Configuration configuration,
KafkaTransport radioKafkaTransport,
KafkaTransport kafkaTransport,
GelfCodec codec,
LocalMetricRegistry localRegistry,
MessageInput.Config config,
MessageInput.Descriptor descriptor, ServerStatus serverStatus) {
super(metricRegistry, configuration, radioKafkaTransport, localRegistry, codec, config, descriptor, serverStatus);
super(metricRegistry, configuration, kafkaTransport, localRegistry, codec, config, descriptor, serverStatus);
}

@FactoryClass
Expand Down
Expand Up @@ -52,12 +52,12 @@ public RawKafkaInput(@Assisted Configuration configuration,

protected RawKafkaInput(MetricRegistry metricRegistry,
Configuration configuration,
KafkaTransport radioKafkaTransport,
KafkaTransport kafkaTransport,
RawCodec codec,
LocalMetricRegistry localRegistry,
MessageInput.Config config,
MessageInput.Descriptor descriptor, ServerStatus serverStatus) {
super(metricRegistry, configuration, radioKafkaTransport, localRegistry, codec, config, descriptor, serverStatus);
super(metricRegistry, configuration, kafkaTransport, localRegistry, codec, config, descriptor, serverStatus);
}

@FactoryClass
Expand Down
Expand Up @@ -52,12 +52,12 @@ public SyslogKafkaInput(@Assisted Configuration configuration,

protected SyslogKafkaInput(MetricRegistry metricRegistry,
Configuration configuration,
KafkaTransport radioKafkaTransport,
KafkaTransport kafkaTransport,
SyslogCodec codec,
LocalMetricRegistry localRegistry,
MessageInput.Config config,
MessageInput.Descriptor descriptor, ServerStatus serverStatus) {
super(metricRegistry, configuration, radioKafkaTransport, localRegistry, codec, config, descriptor, serverStatus);
super(metricRegistry, configuration, kafkaTransport, localRegistry, codec, config, descriptor, serverStatus);
}

@FactoryClass
Expand Down

This file was deleted.

Expand Up @@ -173,10 +173,6 @@ public String getSourceInputId() {
return sourceInputId;
}

public boolean viaRadio() {
return sourceRadioId != null;
}

public String getSourceRadioId() {
return sourceRadioId;
}
Expand Down
Expand Up @@ -32,10 +32,12 @@
*/
package org.graylog2.restroutes;

import com.sun.codemodel.*;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import org.graylog2.restroutes.internal.ResourceRoutesParser;
import org.graylog2.restroutes.internal.RouteClassGenerator;
import org.graylog2.restroutes.internal.RouteClass;
import org.graylog2.restroutes.internal.RouteClassGenerator;
import org.graylog2.restroutes.internal.RouterGenerator;
import org.graylog2.shared.rest.resources.RestResource;

Expand Down Expand Up @@ -75,25 +77,6 @@ public static void main(String[] argv) {
final RouterGenerator routerGenerator = new RouterGenerator(router, generator);
routerGenerator.build(routeClassList);

// do the same for radio resources
JDefinedClass radioRouter = null;
try {
radioRouter = codeModel._class(packagePrefix + ".Radio");
} catch (JClassAlreadyExistsException e) {
e.printStackTrace();
System.exit(-1);
}

final ResourceRoutesParser radioParser = new ResourceRoutesParser("org.graylog2.radio.rest.resources");
final List<RouteClass> radioRouteClassList = radioParser.buildClasses();
radioRouteClassList.addAll(sharedRouteClassList);
final RouteClassGenerator radioGenerator = new RouteClassGenerator(packagePrefix + ".radio", codeModel);
final RouterGenerator radioRouterGenerator = new RouterGenerator(radioRouter, radioGenerator, JMod.PUBLIC);
radioRouterGenerator.build(radioRouteClassList);

JMethod radioMethod = router.method(JMod.PUBLIC | JMod.STATIC, radioRouter, "radio");
radioMethod.body().directStatement("return new " + radioRouter.name() + "();");

try {
File dest = new File(argv[0]);

Expand Down
20 changes: 2 additions & 18 deletions graylog2-server/src/main/java/org/graylog2/cluster/Node.java
Expand Up @@ -19,25 +19,9 @@
import org.graylog2.plugin.database.Persisted;
import org.joda.time.DateTime;

import java.util.Locale;

/**
* @author Dennis Oelkers <dennis@torch.sh>
*/
public interface Node extends Persisted {
public enum Type {
SERVER,
RADIO;

public static Type fromString(String from) {
if (from.toLowerCase(Locale.ENGLISH).equals("server"))
return SERVER;

if (from.toLowerCase(Locale.ENGLISH).equals("radio"))
return RADIO;

return null;
}
enum Type {
SERVER, RADIO
}

String getNodeId();
Expand Down
Expand Up @@ -22,15 +22,11 @@
import java.net.URI;
import java.util.Map;

/**
* @author Dennis Oelkers <dennis@torch.sh>
*/
public interface NodeService extends PersistedService {
String registerServer(String nodeId, boolean isMaster, URI restTransportUri);

String registerRadio(String nodeId, String restTransportUri);

Node byNodeId(String nodeId) throws NodeNotFoundException;

Node byNodeId(NodeId nodeId) throws NodeNotFoundException;

Map<String, Node> allActive(Node.Type type);
Expand Down
Expand Up @@ -17,17 +17,17 @@
package org.graylog2.cluster;

import com.google.common.collect.Maps;
import javax.inject.Inject;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.bson.types.ObjectId;
import org.graylog2.Configuration;
import org.graylog2.database.MongoConnection;
import org.graylog2.database.PersistedServiceImpl;
import org.graylog2.plugin.database.ValidationException;
import org.graylog2.plugin.Tools;
import org.graylog2.plugin.database.ValidationException;
import org.graylog2.plugin.system.NodeId;

import javax.inject.Inject;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -57,21 +57,6 @@ public String registerServer(String nodeId, boolean isMaster, URI restTransportU
}
}

@Override
public String registerRadio(String nodeId, String restTransportUri) {
Map<String, Object> fields = Maps.newHashMap();
fields.put("last_seen", Tools.getUTCTimestamp());
fields.put("node_id", nodeId);
fields.put("type", Node.Type.RADIO.toString());
fields.put("transport_address", restTransportUri);

try {
return save(new NodeImpl(fields));
} catch (ValidationException e) {
throw new RuntimeException("Validation failed.", e);
}
}

@Override
public Node byNodeId(String nodeId) throws NodeNotFoundException {
DBObject query = new BasicDBObject("node_id", nodeId);
Expand Down
Expand Up @@ -16,7 +16,6 @@
*/
package org.graylog2.inputs;

import org.graylog2.cluster.Node;
import org.graylog2.database.NotFoundException;
import org.graylog2.plugin.database.PersistedService;
import org.graylog2.plugin.database.ValidationException;
Expand All @@ -30,8 +29,6 @@
public interface InputService extends PersistedService {
List<Input> allOfThisNode(String nodeId);

List<Input> allOfRadio(Node radio);

Input create(String id, Map<String, Object> fields);

Input create(Map<String, Object> fields);
Expand All @@ -40,12 +37,8 @@ public interface InputService extends PersistedService {

Input findForThisNode(String nodeId, String id) throws NotFoundException;

Input findForThisRadio(String radioId, String id) throws NotFoundException;

Input findForThisNodeOrGlobal(String nodeId, String id) throws NotFoundException;

Input findForThisRadioOrGlobal(String radioId, String id) throws NotFoundException;

/**
* @return the total number of inputs in the cluster (including global inputs).
*/
Expand Down
Expand Up @@ -26,9 +26,7 @@
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.QueryBuilder;
import org.bson.types.ObjectId;
import org.graylog2.cluster.Node;
import org.graylog2.database.MongoConnection;
import org.graylog2.database.NotFoundException;
import org.graylog2.database.PersistedServiceImpl;
Expand All @@ -46,7 +44,6 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -83,21 +80,6 @@ public List<Input> allOfThisNode(final String nodeId) {
return inputs.build();
}

@Override
public List<Input> allOfRadio(Node radio) {
final List<BasicDBObject> query = ImmutableList.of(
new BasicDBObject(MessageInput.FIELD_RADIO_ID, radio.getNodeId()),
new BasicDBObject(MessageInput.FIELD_NODE_ID, radio.getNodeId()),
new BasicDBObject(MessageInput.FIELD_GLOBAL, true));

final ImmutableList.Builder<Input> inputs = ImmutableList.builder();
for (DBObject o : query(InputImpl.class, new BasicDBObject("$or", query))) {
inputs.add(new InputImpl((ObjectId) o.get("_id"), o.toMap()));
}

return inputs.build();
}

@Override
public Input create(String id, Map<String, Object> fields) {
return new InputImpl(new ObjectId(id), fields);
Expand Down Expand Up @@ -131,25 +113,6 @@ public Input findForThisNodeOrGlobal(String nodeId, String id) throws NotFoundEx
return new InputImpl((ObjectId) o.get("_id"), o.toMap());
}

@Override
public Input findForThisRadioOrGlobal(final String radioId, String id) throws NotFoundException {
final List<DBObject> radioIdOrGlobal = ImmutableList.<DBObject>of(
new BasicDBObject(MessageInput.FIELD_RADIO_ID, radioId),
new BasicDBObject(MessageInput.FIELD_NODE_ID, radioId),
new BasicDBObject(MessageInput.FIELD_GLOBAL, true));

final List<DBObject> query = ImmutableList.<DBObject>of(
new BasicDBObject("_id", new ObjectId(id)),
new BasicDBObject("$or", radioIdOrGlobal));

final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
if (o == null) {
throw new NotFoundException();
} else {
return new InputImpl((ObjectId) o.get("_id"), o.toMap());
}
}

@Override
public Input findForThisNode(String nodeId, String id) throws NotFoundException, IllegalArgumentException {
final List<BasicDBObject> forThisNode = ImmutableList.of(
Expand All @@ -168,26 +131,6 @@ public Input findForThisNode(String nodeId, String id) throws NotFoundException,
}
}

@Override
public Input findForThisRadio(String radioId, String id) throws NotFoundException {
final List<Object> list = new ArrayList<Object>() {{
add(false);
add(null);
}};

final List<DBObject> query = ImmutableList.of(
new BasicDBObject("_id", new ObjectId(id)),
new BasicDBObject(MessageInput.FIELD_RADIO_ID, radioId),
QueryBuilder.start(MessageInput.FIELD_GLOBAL).in(list).get());

final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
if (o == null) {
throw new NotFoundException();
} else {
return new InputImpl((ObjectId) o.get("_id"), o.toMap());
}
}

@Override
public void addExtractor(Input input, Extractor extractor) throws ValidationException {
embed(input, InputImpl.EMBEDDED_EXTRACTORS, extractor);
Expand Down Expand Up @@ -380,9 +323,7 @@ public Map<String, Long> totalCountByType() {

@Override
public long localCountForNode(String nodeId) {
final List<BasicDBObject> forThisNode = ImmutableList.of(
new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId),
new BasicDBObject(MessageInput.FIELD_RADIO_ID, nodeId));
final List<BasicDBObject> forThisNode = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId));

final List<BasicDBObject> query = ImmutableList.of(
new BasicDBObject(MessageInput.FIELD_GLOBAL, false),
Expand All @@ -395,8 +336,7 @@ public long localCountForNode(String nodeId) {
public long totalCountForNode(String nodeId) {
final List<BasicDBObject> query = ImmutableList.of(
new BasicDBObject(MessageInput.FIELD_GLOBAL, true),
new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId),
new BasicDBObject(MessageInput.FIELD_RADIO_ID, nodeId));
new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId));

return count(InputImpl.class, new BasicDBObject("$or", query));
}
Expand Down
Expand Up @@ -62,13 +62,7 @@ public SystemResource(ServerStatus serverStatus) {
public SystemOverviewResponse system() {
checkPermission(RestPermissions.SYSTEM_READ, serverStatus.getNodeId().toString());

final String facility;
if (serverStatus.hasCapability(ServerStatus.Capability.RADIO))
facility = "graylog2-radio";
else
facility = "graylog2-server";

return SystemOverviewResponse.create(facility,
return SystemOverviewResponse.create("graylog2-server",
ServerVersion.CODENAME,
serverStatus.getNodeId().toString(),
ServerVersion.VERSION.toString(),
Expand Down

0 comments on commit 1a65b86

Please sign in to comment.