use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.
the class InputServiceImpl method findForThisNode.
@Override
public Input findForThisNode(String nodeId, String id) throws NotFoundException, IllegalArgumentException {
final List<BasicDBObject> forThisNode = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, false));
final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject(InputImpl.FIELD_ID, new ObjectId(id)), new BasicDBObject("$and", forThisNode));
final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
if (o == null) {
throw new NotFoundException("Couldn't find input " + id + " on Graylog node " + nodeId);
} else {
return new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap());
}
}
use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.
the class InputServiceImpl method all.
@Override
public List<Input> all() {
final List<DBObject> ownInputs = query(InputImpl.class, new BasicDBObject());
final ImmutableList.Builder<Input> inputs = ImmutableList.builder();
for (final DBObject o : ownInputs) {
inputs.add(new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap()));
}
return inputs.build();
}
use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.
the class InputFacadeTest method createExcerpt.
@Test
public void createExcerpt() {
final ImmutableMap<String, Object> fields = ImmutableMap.of("title", "Dashboard Title");
final InputImpl input = new InputImpl(fields);
final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input);
final EntityExcerpt excerpt = facade.createExcerpt(inputWithExtractors);
assertThat(excerpt.id()).isEqualTo(ModelId.of(input.getId()));
assertThat(excerpt.type()).isEqualTo(ModelTypes.INPUT_V1);
assertThat(excerpt.title()).isEqualTo(input.getTitle());
}
use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.
the class InputFacadeTest method exportNativeEntity.
@Test
public void exportNativeEntity() {
final ImmutableMap<String, Object> fields = ImmutableMap.of(MessageInput.FIELD_TITLE, "Input Title", MessageInput.FIELD_TYPE, "org.graylog2.inputs.raw.udp.RawUDPInput", MessageInput.FIELD_CONFIGURATION, Collections.emptyMap());
final InputImpl input = new InputImpl(fields);
final ImmutableList<Extractor> extractors = ImmutableList.of();
final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, extractors);
final EntityDescriptor descriptor = EntityDescriptor.create(input.getId(), ModelTypes.INPUT_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(inputWithExtractors, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Input Title"));
assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
assertThat(inputEntity.configuration()).isEmpty();
}
use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.
the class InputServiceImpl method allOfThisNode.
@Override
public List<Input> allOfThisNode(final String nodeId) {
final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, true));
final List<DBObject> ownInputs = query(InputImpl.class, new BasicDBObject("$or", query));
final ImmutableList.Builder<Input> inputs = ImmutableList.builder();
for (final DBObject o : ownInputs) {
inputs.add(new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap()));
}
return inputs.build();
}
Aggregations