Search in sources :

Example 41 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class InputFacadeTest method resolveNativeEntityLookupTable.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveNativeEntityLookupTable() throws NotFoundException {
    when(lookupuptableBuilder.lookupTable("whois")).thenReturn(lookupuptableBuilder);
    when(lookupuptableBuilder.lookupTable("tor-exit-node-list")).thenReturn(lookupuptableBuilder);
    when(lookupuptableBuilder.build()).thenReturn(lookupTable);
    when(lookupTableService.newBuilder()).thenReturn(lookupuptableBuilder);
    when(lookupTableService.hasTable("whois")).thenReturn(true);
    when(lookupTableService.hasTable("tor-exit-node-list")).thenReturn(true);
    when(lookupTableWhois.id()).thenReturn("dead-beef");
    when(dbLookupTableService.get("whois")).thenReturn(Optional.of(lookupTableWhois));
    when(lookupTableTor.id()).thenReturn("dead-feed");
    when(dbLookupTableService.get("tor-exit-node-list")).thenReturn(Optional.of(lookupTableTor));
    final Input input = inputService.find("5ae2eb0a3d27464477f0fd8b");
    EntityDescriptor entityDescriptor = EntityDescriptor.create(ModelId.of(input.getId()), ModelTypes.INPUT_V1);
    EntityDescriptor expectedEntitiyDescriptorWhois = EntityDescriptor.create(ModelId.of("dead-beef"), ModelTypes.LOOKUP_TABLE_V1);
    EntityDescriptor expectedEntitiyDescriptorTor = EntityDescriptor.create(ModelId.of("dead-feed"), ModelTypes.LOOKUP_TABLE_V1);
    Graph<EntityDescriptor> graph = facade.resolveNativeEntity(entityDescriptor);
    assertThat(graph.nodes()).contains(expectedEntitiyDescriptorWhois);
    assertThat(graph.nodes()).contains(expectedEntitiyDescriptorTor);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 42 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class ContentPackInstallationRequestTest method testSerialisation.

@Test
public void testSerialisation() {
    final ImmutableMap<String, ValueReference> parameters = ImmutableMap.of("param1", ValueReference.of("string"), "param2", ValueReference.of(42), "param3", ValueReference.of(3.14d), "param4", ValueReference.of(true));
    final ContentPackInstallationRequest request = ContentPackInstallationRequest.create(parameters, "comment");
    final JsonNode node = objectMapper.valueToTree(request);
    assertThat(node.path("comment").asText()).isEqualTo("comment");
    assertThat(node.path("parameters").path("param1").path("@type").asText()).isEqualTo("string");
    assertThat(node.path("parameters").path("param1").path("@value").asText()).isEqualTo("string");
    assertThat(node.path("parameters").path("param2").path("@type").asText()).isEqualTo("integer");
    assertThat(node.path("parameters").path("param2").path("@value").asInt()).isEqualTo(42);
    assertThat(node.path("parameters").path("param3").path("@type").asText()).isEqualTo("double");
    assertThat(node.path("parameters").path("param3").path("@value").asDouble()).isEqualTo(3.14d);
    assertThat(node.path("parameters").path("param4").path("@type").asText()).isEqualTo("boolean");
    assertThat(node.path("parameters").path("param4").path("@value").asBoolean()).isEqualTo(true);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Test(org.junit.Test)

Example 43 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class LocalKafkaJournalTest method setUp.

@Before
public void setUp() throws IOException {
    scheduler = new ScheduledThreadPoolExecutor(1);
    scheduler.prestartCoreThread();
    journalDirectory = temporaryFolder.newFolder();
    final File nodeId = temporaryFolder.newFile("node-id");
    Files.write(nodeId.toPath(), UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8));
    final Configuration configuration = new Configuration() {

        @Override
        public String getNodeIdFile() {
            return nodeId.getAbsolutePath();
        }
    };
    serverStatus = new ServerStatus(configuration, EnumSet.of(ServerStatus.Capability.SERVER), new EventBus("KafkaJournalTest"), NullAuditEventSender::new);
}
Also used : Configuration(org.graylog2.Configuration) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ServerStatus(org.graylog2.plugin.ServerStatus) EventBus(com.google.common.eventbus.EventBus) File(java.io.File) Before(org.junit.Before)

Example 44 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class InputEventListenerTest method inputCreatedStartsGlobalInputOnOtherNode.

@Test
public void inputCreatedStartsGlobalInputOnOtherNode() throws Exception {
    final String inputId = "input-id";
    final Input input = mock(Input.class);
    when(inputService.find(inputId)).thenReturn(input);
    when(nodeId.toString()).thenReturn("node-id");
    when(input.getNodeId()).thenReturn("other-node-id");
    when(input.isGlobal()).thenReturn(true);
    final MessageInput messageInput = mock(MessageInput.class);
    when(inputService.getMessageInput(input)).thenReturn(messageInput);
    listener.inputCreated(InputCreated.create(inputId));
    verify(inputLauncher, times(1)).launch(messageInput);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) Test(org.junit.Test)

Example 45 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class InputEventListenerTest method inputUpdatedRestartsGlobalInputOnAnyNode.

@Test
public void inputUpdatedRestartsGlobalInputOnAnyNode() throws Exception {
    final String inputId = "input-id";
    final Input input = mock(Input.class);
    @SuppressWarnings("unchecked") final IOState<MessageInput> inputState = mock(IOState.class);
    when(inputState.getState()).thenReturn(IOState.Type.RUNNING);
    when(inputService.find(inputId)).thenReturn(input);
    when(inputRegistry.getInputState(inputId)).thenReturn(inputState);
    when(nodeId.toString()).thenReturn("node-id");
    when(input.getNodeId()).thenReturn("other-node-id");
    when(input.isGlobal()).thenReturn(true);
    final MessageInput messageInput = mock(MessageInput.class);
    when(inputService.getMessageInput(input)).thenReturn(messageInput);
    listener.inputUpdated(InputUpdated.create(inputId));
    verify(inputLauncher, times(1)).launch(messageInput);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) Test(org.junit.Test)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)29 ApiOperation (io.swagger.annotations.ApiOperation)28 MessageInput (org.graylog2.plugin.inputs.MessageInput)23 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)19 Input (org.graylog2.inputs.Input)15 AuditEvent (org.graylog2.audit.jersey.AuditEvent)14 Test (org.junit.Test)14 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 Node (org.graylog2.cluster.Node)12 Map (java.util.Map)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 PUT (javax.ws.rs.PUT)6 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)6 Notification (org.graylog2.notifications.Notification)6 Activity (org.graylog2.shared.system.activities.Activity)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 EventBus (com.google.common.eventbus.EventBus)5 URI (java.net.URI)5