use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class OutputFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.OUTPUT_V1).data(objectMapper.convertValue(OutputEntity.create(ValueReference.of("STDOUT"), ValueReference.of("org.graylog2.outputs.LoggingOutput"), ReferenceMapUtils.toReferenceMap(ImmutableMap.of("prefix", "Writing message: "))), JsonNode.class)).build();
final NativeEntity<Output> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.OUTPUT_V1);
assertThat(nativeEntity.entity().getTitle()).isEqualTo("STDOUT");
assertThat(nativeEntity.entity().getType()).isEqualTo("org.graylog2.outputs.LoggingOutput");
assertThat(nativeEntity.entity().getCreatorUserId()).isEqualTo("username");
assertThat(nativeEntity.entity().getConfiguration()).containsEntry("prefix", "Writing message: ");
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class InputFacadeTest method exportEntity.
@Test
@MongoDBFixtures("InputFacadeTest.json")
public void exportEntity() {
final ModelId id = ModelId.of("5acc84f84b900a4ff290d9a7");
final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.INPUT_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
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("Local Raw UDP"));
assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
assertThat(inputEntity.global()).isEqualTo(ValueReference.of(false));
assertThat(inputEntity.configuration()).containsEntry("bind_address", ValueReference.of("127.0.0.1")).containsEntry("port", ValueReference.of(5555));
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class InputFacadeTest method createNativeEntity.
@Test
@Ignore("Doesn't work without massive amount of mocks")
public void createNativeEntity() {
final Map<String, Object> configuration = new HashMap<>();
configuration.put("override_source", null);
configuration.put("recv_buffer_size", 262144);
configuration.put("bind_address", "127.0.0.1");
configuration.put("port", 5555);
configuration.put("number_worker_threads", 8);
final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
final NativeEntity<InputWithExtractors> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
final InputWithExtractors inputWithExtractors = nativeEntity.entity();
final Input savedInput = inputWithExtractors.input();
final String savedId = savedInput.getId();
assertThat(nativeEntity.descriptor()).isEqualTo(EntityDescriptor.create(savedId, ModelTypes.INPUT_V1));
assertThat(savedInput.getTitle()).isEqualTo("Local Raw UDP");
assertThat(savedInput.getType()).isEqualTo("org.graylog2.inputs.raw.udp.RawUDPInput");
assertThat(savedInput.isGlobal()).isFalse();
assertThat(savedInput.getContentPack()).isNull();
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class ContentPackServiceTest method setUp.
@Before
public void setUp() throws Exception {
final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = contentPackInstallService;
final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
pluginMetaData = new HashSet<>();
outputFactories = new HashMap<>();
outputFactories2 = new HashMap<>();
final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = ImmutableMap.of(ModelTypes.GROK_PATTERN_V1, new GrokPatternFacade(objectMapper, patternService), ModelTypes.STREAM_V1, new StreamFacade(objectMapper, streamService, streamRuleService, alertService, alarmCallbackConfigurationService, legacyAlertConditionMigration, indexSetService, userService), ModelTypes.OUTPUT_V1, new OutputFacade(objectMapper, outputService, pluginMetaData, outputFactories, outputFactories2));
contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
Map<String, String> entityData = new HashMap<>(2);
entityData.put("name", "NAME");
entityData.put("pattern", "\\w");
grokPattern = GrokPattern.builder().pattern("\\w").name("NAME").build();
JsonNode jsonData = objectMapper.convertValue(entityData, JsonNode.class);
EntityV1 entityV1 = EntityV1.builder().id(ModelId.of("12345")).type(ModelTypes.GROK_PATTERN_V1).data(jsonData).build();
ImmutableSet<Entity> entities = ImmutableSet.of(entityV1);
NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("12345"), "dead-beef1", ModelTypes.GROK_PATTERN_V1, "NAME");
nativeEntityDescriptors = ImmutableSet.of(nativeEntityDescriptor);
contentPack = ContentPackV1.builder().description("test").entities(entities).name("test").revision(1).summary("").vendor("").url(URI.create("http://graylog.com")).id(ModelId.of("dead-beef")).build();
contentPackInstallation = ContentPackInstallation.builder().contentPackId(ModelId.of("dead-beef")).contentPackRevision(1).entities(nativeEntityDescriptors).comment("Installed").parameters(ImmutableMap.copyOf(Collections.emptyMap())).createdAt(Instant.now()).createdBy("me").build();
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method resolveMatchingDependecyForInstallation.
@Test
public void resolveMatchingDependecyForInstallation() {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{PORTAL}"), JsonNode.class)).build();
final Entity grokPatternEntityDependency = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("PORTAL", "\\d\\d"), JsonNode.class)).build();
final EntityDescriptor dependencyDescriptor = grokPatternEntityDependency.toEntityDescriptor();
final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap(1);
entityDescriptorEntityMap.put(dependencyDescriptor, grokPatternEntityDependency);
final Map<String, ValueReference> parameters = Collections.emptyMap();
Graph<Entity> graph = facade.resolveForInstallation(grokPatternEntity, parameters, entityDescriptorEntityMap);
assertThat(graph.nodes().toArray()).contains(grokPatternEntityDependency);
}
Aggregations