From 30133b1755ca8358f32eed406670d514abad4aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Tue, 14 Jan 2025 12:07:02 +0100 Subject: [PATCH 01/56] UI improvements to setup routing step --- .../InputSetupWizard.SetupRouting.test.tsx | 2 +- .../steps/SetupRoutingStep.tsx | 38 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx index a65b10422e99..a6e4ac2728d9 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx @@ -265,7 +265,7 @@ describe('InputSetupWizard Setup Routing', () => { await selectEvent.select(streamSelect, 'Aloho'); - const warning = await screen.findByText(/The selected stream has existing pipelines/i); + const warning = await screen.findByText(/Pipelines connected to target Stream/i); const warningPipeline1 = await screen.findByText(/Pipeline1/i); const warningPipeline2 = await screen.findByText(/Pipeline2/i); diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx index e98db578c56b..622d277075f7 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx @@ -19,7 +19,7 @@ import { useEffect, useMemo, useState, useCallback } from 'react'; import styled, { css } from 'styled-components'; import { Alert, Button, Row, Col } from 'components/bootstrap'; -import { Select } from 'components/common'; +import { Select, Tooltip } from 'components/common'; import useInputSetupWizard from 'components/inputs/InputSetupWizard/hooks/useInputSetupWizard'; import useInputSetupWizardSteps from 'components/inputs/InputSetupWizard/hooks/useInputSetupWizardSteps'; import { defaultCompare } from 'logic/DefaultCompare'; @@ -45,12 +45,12 @@ const StyledHeading = styled.h3(({ theme }) => css` `); const ExistingStreamCol = styled(Col)(({ theme }) => css` + border-left: 1px solid ${theme.colors.cards.border}; padding-top: ${theme.spacings.sm}; padding-bottom: ${theme.spacings.md}; `); const CreateStreamCol = styled(Col)(({ theme }) => css` - border-left: 1px solid ${theme.colors.cards.border}; padding-top: ${theme.spacings.sm}; padding-bottom: ${theme.spacings.md}; `); @@ -62,6 +62,13 @@ const ButtonCol = styled(Col)(({ theme }) => css` margin-top: ${theme.spacings.lg}; `); +const StyledTooltip = styled(Tooltip)(({ theme }) => css` + &.mantine-Tooltip-tooltip { + background-color: ${theme.colors.global.background}!important; + font-size: ${theme.fonts.size.small}!important; + } +`); + const ConntectedPipelinesList = styled.ul` list-style-type: disc; padding-left: 20px; @@ -188,16 +195,22 @@ const SetupRoutingStep = () => {

- Choose a Destination Stream to route Messages from this Input to. Messages that are not - routed to any Streams will be sent to the "All Messages" Stream. + Choose a Destination Stream to Route Messages from this Input to. Messages that are not routed to any Streams will be routed to the Default stream. +

+

+ Via this setup dialog, Pipeline rules will be automatically created and attached to the Default Stream, to route messages to the selected Stream. +

+

+ We recommend creating a new Stream for each new Input. This will help categorize your messages into a basic schema that will make it easier to target searches.

{selectedStreamId && streamHasConnectedPipelines && ( - - The selected Stream has existing Pipelines connected to it: + + We recommending checking the impact of these prior to completing the Input Setup. The target Stream has the following Pipelines connected to it: {streamPipelinesData.map((pipeline) =>
  • {pipeline.title}
  • )}
    @@ -224,6 +237,15 @@ const SetupRoutingStep = () => {
    ) : ( + + Route to a new Stream + + + + Choose an existing Stream {!isLoadingStreams && ( @@ -236,10 +258,6 @@ const SetupRoutingStep = () => { value={selectedStreamId} /> )} - - Route to a new Stream - - )} {(hasPreviousStep || hasNextStep || showNewStreamSection) && ( From 387ae727593376d25ebe4d5308be9c4b93e6465a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Tue, 14 Jan 2025 12:18:35 +0100 Subject: [PATCH 02/56] Link directly to input diagnosis page --- .../InputSetupWizard/steps/StartInputStep.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx index 2390fea0bdc6..04f5d9719e00 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx @@ -18,7 +18,9 @@ import * as React from 'react'; import { useEffect, useState, useMemo } from 'react'; import styled, { css } from 'styled-components'; import type { UseMutationResult } from '@tanstack/react-query'; +import { useNavigate } from 'react-router-dom'; +import Routes from 'routing/Routes'; import useSetupInputMutations from 'components/inputs/InputSetupWizard/hooks/useSetupInputMutations'; import { InputStatesStore } from 'stores/inputs/InputStatesStore'; import { Button, Row, Col } from 'components/bootstrap'; @@ -55,7 +57,8 @@ const ButtonCol = styled(Col)(({ theme }) => css` export type ProcessingSteps = 'createStream' | 'startStream' | 'createPipeline' | 'setupRouting' | 'deleteStream' | 'deletePipeline' | 'deleteRouting' | 'result'; const StartInputStep = () => { - const { goToPreviousStep, goToNextStep, orderedSteps, activeStep, wizardData, stepsConfig } = useInputSetupWizard(); + const navigateTo = useNavigate(); + const { goToPreviousStep, orderedSteps, activeStep, wizardData, stepsConfig } = useInputSetupWizard(); const { stepsData } = useInputSetupWizardSteps(); const hasPreviousStep = checkHasPreviousStep(orderedSteps, activeStep); const hasNextStep = checkHasNextStep(orderedSteps, activeStep); @@ -240,8 +243,12 @@ const StartInputStep = () => { rollback(); }; - const onNextStep = () => { - goToNextStep(); + const goToInputDiagnosis = () => { + const { input } = wizardData; + + if (!input) return; + + navigateTo(Routes.SYSTEM.INPUT_DIAGNOSIS(input.id)); }; const handleBackClick = () => { @@ -317,7 +324,7 @@ const StartInputStep = () => { if (hasNextStep) { return ( - + ); } From 72570c2565df1291d5acf198723cb9363b8f7851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Wed, 15 Jan 2025 12:04:12 +0100 Subject: [PATCH 03/56] More UI improvements and tests --- .../InputSetupWizard.SetupRouting.test.tsx | 171 ++++++++++------- .../steps/SetupRoutingStep.tsx | 173 ++++++++++++------ 2 files changed, 221 insertions(+), 123 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx index a6e4ac2728d9..0e868ece9084 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.SetupRouting.test.tsx @@ -180,98 +180,139 @@ describe('InputSetupWizard Setup Routing', () => { it('should render the Setup Routing step', async () => { renderWizard(); - const routingStepText = await screen.findByText(/Choose a Destination Stream to route Messages from this Input to./i); + const routingStepText = await screen.findByText(/Select a destination Stream to route messages from this input to./i); expect(routingStepText).toBeInTheDocument(); }); - it('should only show editable existing streams', async () => { - asMock(useStreams).mockReturnValue(useStreamsResult( - [ - { id: 'alohoid', title: 'Aloho', is_editable: true }, - { id: 'moraid', title: 'Mora', is_editable: false }, - ], - )); + describe('Stream Selection', () => { + it('should show the stream select when clicking on choose stream', async () => { + renderWizard(); + const selectStreamButton = await screen.findByRole('button', { + name: /Select Stream/i, + hidden: true, + }); - renderWizard(); + fireEvent.click(selectStreamButton); - const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); + await screen.findByLabelText(/All messages \(Default\)/i); + }); - await selectEvent.openMenu(streamSelect); + it('should only show editable existing streams', async () => { + asMock(useStreams).mockReturnValue(useStreamsResult( + [ + { id: 'alohoid', title: 'Aloho', is_editable: true }, + { id: 'moraid', title: 'Mora', is_editable: false }, + ], + )); - const alohoOption = await screen.findByText(/Aloho/i); - const moraOption = screen.queryByText(/Mora/i); + renderWizard(); + const selectStreamButton = await screen.findByRole('button', { + name: /Select Stream/i, + hidden: true, + }); - expect(alohoOption).toBeInTheDocument(); - expect(moraOption).not.toBeInTheDocument(); - }); + fireEvent.click(selectStreamButton); - it('should not show existing default stream in select', async () => { - asMock(useStreams).mockReturnValue(useStreamsResult( - [ - { id: 'alohoid', title: 'Aloho', is_editable: true, is_default: true }, - { id: 'moraid', title: 'Mora', is_editable: true }, - ], - )); + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); - renderWizard(); + await selectEvent.openMenu(streamSelect); - const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); + const alohoOption = await screen.findByText(/Aloho/i); + const moraOption = screen.queryByText(/Mora/i); - await selectEvent.openMenu(streamSelect); + expect(alohoOption).toBeInTheDocument(); + expect(moraOption).not.toBeInTheDocument(); + }); - const moraOption = await screen.findByText(/Mora/i); - const alohoOption = screen.queryByText(/Aloho/i); + it('should not show existing default stream in select', async () => { + asMock(useStreams).mockReturnValue(useStreamsResult( + [ + { id: 'alohoid', title: 'Aloho', is_editable: true, is_default: true }, + { id: 'moraid', title: 'Mora', is_editable: true }, + ], + )); - expect(moraOption).toBeInTheDocument(); - expect(alohoOption).not.toBeInTheDocument(); - }); + renderWizard(); - it('should allow the user to select a stream', async () => { - asMock(useStreams).mockReturnValue(useStreamsResult( - [ - { id: 'alohoid', title: 'Aloho', is_editable: true }, - { id: 'moraid', title: 'Mora', is_editable: true }, - ], - )); + const selectStreamButton = await screen.findByRole('button', { + name: /Select Stream/i, + hidden: true, + }); - renderWizard(); + fireEvent.click(selectStreamButton); - const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); - await selectEvent.openMenu(streamSelect); + await selectEvent.openMenu(streamSelect); - await selectEvent.select(streamSelect, 'Aloho'); - }); + const moraOption = await screen.findByText(/Mora/i); + const alohoOption = screen.queryByText(/Aloho/i); - it('should show a warning if the selected stream has connected pipelines', async () => { - asMock(useStreams).mockReturnValue(useStreamsResult( - [ - { id: 'alohoid', title: 'Aloho', is_editable: true }, - { id: 'moraid', title: 'Mora', is_editable: true }, - ], - )); + expect(moraOption).toBeInTheDocument(); + expect(alohoOption).not.toBeInTheDocument(); + }); - asMock(usePipelinesConnectedStream).mockReturnValue(pipelinesConnectedMock([ - { id: 'pipeline1', title: 'Pipeline1' }, - { id: 'pipeline2', title: 'Pipeline2' }, - ])); + it('should allow the user to select a stream', async () => { + asMock(useStreams).mockReturnValue(useStreamsResult( + [ + { id: 'alohoid', title: 'Aloho', is_editable: true }, + { id: 'moraid', title: 'Mora', is_editable: true }, + ], + )); - renderWizard(); + renderWizard(); + + const selectStreamButton = await screen.findByRole('button', { + name: /Select Stream/i, + hidden: true, + }); + + fireEvent.click(selectStreamButton); + + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); + + await selectEvent.openMenu(streamSelect); + + await selectEvent.select(streamSelect, 'Aloho'); + }); - const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); + it('should show a warning if the selected stream has connected pipelines', async () => { + asMock(useStreams).mockReturnValue(useStreamsResult( + [ + { id: 'alohoid', title: 'Aloho', is_editable: true }, + { id: 'moraid', title: 'Mora', is_editable: true }, + ], + )); - await selectEvent.openMenu(streamSelect); + asMock(usePipelinesConnectedStream).mockReturnValue(pipelinesConnectedMock([ + { id: 'pipeline1', title: 'Pipeline1' }, + { id: 'pipeline2', title: 'Pipeline2' }, + ])); - await selectEvent.select(streamSelect, 'Aloho'); + renderWizard(); + + const selectStreamButton = await screen.findByRole('button', { + name: /Select Stream/i, + hidden: true, + }); + + fireEvent.click(selectStreamButton); - const warning = await screen.findByText(/Pipelines connected to target Stream/i); - const warningPipeline1 = await screen.findByText(/Pipeline1/i); - const warningPipeline2 = await screen.findByText(/Pipeline2/i); + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); - expect(warning).toBeInTheDocument(); - expect(warningPipeline1).toBeInTheDocument(); - expect(warningPipeline2).toBeInTheDocument(); + await selectEvent.openMenu(streamSelect); + + await selectEvent.select(streamSelect, 'Aloho'); + + const warning = await screen.findByText(/Pipelines connected to target Stream/i); + const warningPipeline1 = await screen.findByText(/Pipeline1/i); + const warningPipeline2 = await screen.findByText(/Pipeline2/i); + + expect(warning).toBeInTheDocument(); + expect(warningPipeline1).toBeInTheDocument(); + expect(warningPipeline2).toBeInTheDocument(); + }); }); describe('Stream creation', () => { @@ -323,7 +364,7 @@ describe('InputSetupWizard Setup Routing', () => { }); const nextStepButton = await screen.findByRole('button', { - name: /Finish & Start Input/i, + name: /Skip & Start Input/i, hidden: true, }); diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx index 622d277075f7..f2f51b4d5fe5 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx @@ -45,7 +45,6 @@ const StyledHeading = styled.h3(({ theme }) => css` `); const ExistingStreamCol = styled(Col)(({ theme }) => css` - border-left: 1px solid ${theme.colors.cards.border}; padding-top: ${theme.spacings.sm}; padding-bottom: ${theme.spacings.md}; `); @@ -53,6 +52,7 @@ const ExistingStreamCol = styled(Col)(({ theme }) => css` const CreateStreamCol = styled(Col)(({ theme }) => css` padding-top: ${theme.spacings.sm}; padding-bottom: ${theme.spacings.md}; + border-right: 1px solid ${theme.colors.cards.border}; `); const ButtonCol = styled(Col)(({ theme }) => css` @@ -69,7 +69,7 @@ const StyledTooltip = styled(Tooltip)(({ theme }) => css` } `); -const ConntectedPipelinesList = styled.ul` +const StyledList = styled.ul` list-style-type: disc; padding-left: 20px; `; @@ -87,6 +87,7 @@ const SetupRoutingStep = () => { const { stepsData, setStepsData } = useInputSetupWizardSteps(); const newStream: StreamFormValues = getStepConfigOrData(stepsData, currentStepName, 'newStream'); const [selectedStreamId, setSelectedStreamId] = useState(undefined); + const [showSelectStream, setShowSelectStream] = useState(false); const [showCreateStream, setShowCreateStream] = useState(false); const hasPreviousStep = checkHasPreviousStep(orderedSteps, activeStep); const hasNextStep = checkHasNextStep(orderedSteps, activeStep); @@ -160,6 +161,10 @@ const SetupRoutingStep = () => { setShowCreateStream(true); }; + const handleSelectStream = () => { + setShowSelectStream(true); + }; + const onNextStep = () => { goToNextStep(); }; @@ -169,6 +174,8 @@ const SetupRoutingStep = () => { updateStepConfigOrData(stepsData, currentStepName, defaultStepData, true), ); + setSelectedStreamId(undefined); + setShowSelectStream(false); setShowCreateStream(false); goToPreviousStep(); @@ -187,84 +194,134 @@ const SetupRoutingStep = () => { }; const backButtonText = newStream ? 'Reset' : 'Back'; + const nextButtonText = showCreateStream || showSelectStream ? 'Finish & Start Input' : 'Skip & Start Input'; const showNewStreamSection = newStream || showCreateStream; return ( - - -

    - Choose a Destination Stream to Route Messages from this Input to. Messages that are not routed to any Streams will be routed to the Default stream. -

    -

    - Via this setup dialog, Pipeline rules will be automatically created and attached to the Default Stream, to route messages to the selected Stream. -

    -

    - We recommend creating a new Stream for each new Input. This will help categorize your messages into a basic schema that will make it easier to target searches. -

    -
    -
    - {selectedStreamId && streamHasConnectedPipelines && ( + {!showNewStreamSection && !showSelectStream && ( + <> - - - We recommending checking the impact of these prior to completing the Input Setup. The target Stream has the following Pipelines connected to it: - - {streamPipelinesData.map((pipeline) =>
  • {pipeline.title}
  • )} -
    -
    - + + +
  • + Select a destination Stream to route messages from this input to. +
  • +
  • + We recommend creating a new stream for each new input. This will help categorise your messages into a basic schema. +
  • +
  • + Messages that are not routed to any Stream will be routed to the Default Stream. +
  • +
  • + Pipeline rules can be automatically created and attached to the Default Stream by this Wizard. +
  • +
    +
    - )} - {showNewStreamSection ? ( - - - - Create new Stream - - {newStream ? ( - <> -

    This Input will use a new stream: "{newStream.title}".

    -

    Matches will {!newStream.remove_matches_from_default_stream && ('not ')}be removed from the Default Stream.

    - {getStepConfigOrData(stepsData, currentStepName, 'shouldCreateNewPipeline') && (

    A new Pipeline will be created.

    )} - - ) : ( - - )} - -
    - ) : ( + + {!selectedStreamId && ( Route to a new Stream - - Choose an existing Stream - {!isLoadingStreams && ( - + + + )} + + )} + {(hasPreviousStep || hasNextStep || showNewStreamSection) && ( - {(hasPreviousStep || showNewStreamSection) && ()} - {hasNextStep && ()} + {(hasPreviousStep || showNewStreamSection || showSelectStream) && ()} + {hasNextStep && ()} )} From cead70c8e36cbc642c2449d39640382dccddaf24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Wed, 15 Jan 2025 12:10:05 +0100 Subject: [PATCH 04/56] Remove text from create stream form --- .../steps/SetupRoutingStep.tsx | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx index f2f51b4d5fe5..386f23bfce9f 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx @@ -244,27 +244,9 @@ const SetupRoutingStep = () => { {showNewStreamSection && ( - - - - Create new Stream - - -
  • - Select a destination Stream to route messages from this input to. -
  • -
  • - We recommend creating a new stream for each new input. This will help categorise your messages into a basic schema. -
  • -
  • - Messages that are not routed to any Stream will be routed to the Default Stream. -
  • -
  • - Pipeline rules can be automatically created and attached to the Default Stream by this Wizard. -
  • -
    -
    -
    + + Create new Stream + {newStream ? ( <>

    This Input will use a new stream: "{newStream.title}".

    From 8b7ad9c9116641bd89dbcc676de64f43ecef900c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Wed, 15 Jan 2025 12:37:42 +0100 Subject: [PATCH 05/56] Fix start input tests --- .../InputSetupWizard.StartInput.test.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx index be6dbf2d7c92..8d13e3a4cfa7 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx @@ -172,7 +172,7 @@ const newPipelineConfig = { }; const goToStartInputStep = async () => { - const nextButton = await screen.findByRole('button', { name: /Finish & Start Input/i, hidden: true }); + const nextButton = await screen.findByRole('button', { name: /& Start Input/i, hidden: true }); fireEvent.click(nextButton); }; @@ -253,6 +253,13 @@ describe('InputSetupWizard Start Input', () => { it('should start input when an existing stream is selected', async () => { renderWizard(); + const selectStreamButton = await screen.findByRole('button', { + name: /Select Stream/i, + hidden: true, + }); + + fireEvent.click(selectStreamButton); + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); await selectEvent.openMenu(streamSelect); From df7344a41c00a52f1e09ff9444ffb153cffac32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Fri, 17 Jan 2025 12:05:07 +0100 Subject: [PATCH 06/56] WIP add first test --- .../InputSetupWizard.StartInput.test.tsx | 217 ++++++++++-------- .../hooks/useSetupInputMutations.ts | 8 +- .../InputSetupWizard/steps/StartInputStep.tsx | 2 +- 3 files changed, 131 insertions(+), 96 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx index be6dbf2d7c92..8f62cb97c365 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx @@ -17,7 +17,9 @@ import * as React from 'react'; import { render, screen, fireEvent, waitFor } from 'wrappedTestingLibrary'; import selectEvent from 'react-select-event'; +import { act } from 'wrappedTestingLibrary/hooks'; +import suppressConsole from 'helpers/suppressConsole'; import fetch from 'logic/rest/FetchProvider'; import { asMock, StoreMock as MockStore } from 'helpers/mocking'; import usePipelinesConnectedStream from 'hooks/usePipelinesConnectedStream'; @@ -228,127 +230,162 @@ beforeEach(() => { asMock(useStreams).mockReturnValue(useStreamsResult); asMock(usePipelinesConnectedStream).mockReturnValue(pipelinesConnectedMock()); asMock(useIndexSetsList).mockReturnValue(useIndexSetsListResult); - asMock(fetch).mockImplementation(() => Promise.resolve({})); }); describe('InputSetupWizard Start Input', () => { - it('should render the Start Input step', async () => { - renderWizard(); - goToStartInputStep(); - - expect(await screen.findByText(/Set up and start the Input according to the configuration made./i)).toBeInTheDocument(); - }); - - it('should start when default stream is selected', async () => { - renderWizard(); - goToStartInputStep(); - startInput(); - - await waitFor(() => expect(InputStatesStore.start).toHaveBeenCalledWith(input)); + describe('Start Input', () => { + beforeEach(() => { + asMock(fetch).mockReturnValue(Promise.resolve({})); + }); - expect(await screen.findByRole('heading', { name: /Setting up Input.../i, hidden: true })).toBeInTheDocument(); - expect(await screen.findByText(/Input started sucessfully!/i)).toBeInTheDocument(); - }); + it('should render the Start Input step', async () => { + renderWizard(); + goToStartInputStep(); - it('should start input when an existing stream is selected', async () => { - renderWizard(); + expect(await screen.findByText(/Set up and start the Input according to the configuration made./i)).toBeInTheDocument(); + }); - const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); + it('should start when default stream is selected', async () => { + renderWizard(); + goToStartInputStep(); + startInput(); - await selectEvent.openMenu(streamSelect); + await waitFor(() => expect(InputStatesStore.start).toHaveBeenCalledWith(input)); - await selectEvent.select(streamSelect, 'One Stream'); + expect(await screen.findByRole('heading', { name: /Setting up Input.../i, hidden: true })).toBeInTheDocument(); + expect(await screen.findByText(/Input started sucessfully!/i)).toBeInTheDocument(); + }); - goToStartInputStep(); - startInput(); + it('should start input when an existing stream is selected', async () => { + renderWizard(); - await waitFor(() => expect(InputStatesStore.start).toHaveBeenCalledWith(input)); + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'PUT', - expect.stringMatching(updateRoutingUrlRegEx), - { input_id: 'input-test-id', stream_id: 'streamId1' }, - )); + await selectEvent.openMenu(streamSelect); - expect(await screen.findByRole('heading', { name: /Setting up Input.../i, hidden: true })).toBeInTheDocument(); - expect(await screen.findByText(/Routing set up!/i)).toBeInTheDocument(); - expect(await screen.findByText(/Input started sucessfully!/i)).toBeInTheDocument(); - }); + await selectEvent.select(streamSelect, 'One Stream'); - describe('new stream', () => { - it('should show the progress for all steps', async () => { - renderWizard(); - await waitFor(() => createStream(true)); goToStartInputStep(); startInput(); + await waitFor(() => expect(InputStatesStore.start).toHaveBeenCalledWith(input)); + + await waitFor(() => expect(fetch).toHaveBeenCalledWith( + 'PUT', + expect.stringMatching(updateRoutingUrlRegEx), + { input_id: 'input-test-id', stream_id: 'streamId1' }, + )); + expect(await screen.findByRole('heading', { name: /Setting up Input.../i, hidden: true })).toBeInTheDocument(); - expect(await screen.findByText(/Stream "Wingardium" created!/i)).toBeInTheDocument(); - expect(await screen.findByText(/Pipeline "Wingardium" created!/i)).toBeInTheDocument(); expect(await screen.findByText(/Routing set up!/i)).toBeInTheDocument(); expect(await screen.findByText(/Input started sucessfully!/i)).toBeInTheDocument(); }); - it('should start the input', async () => { - renderWizard(); - await waitFor(() => createStream()); - goToStartInputStep(); - startInput(); - - await waitFor(() => expect(InputStatesStore.start).toHaveBeenCalledWith(input)); + describe('new stream', () => { + it('should show the progress for all steps', async () => { + renderWizard(); + await waitFor(() => createStream(true)); + goToStartInputStep(); + startInput(); + + expect(await screen.findByRole('heading', { name: /Setting up Input.../i, hidden: true })).toBeInTheDocument(); + expect(await screen.findByText(/Stream "Wingardium" created!/i)).toBeInTheDocument(); + expect(await screen.findByText(/Pipeline "Wingardium" created!/i)).toBeInTheDocument(); + expect(await screen.findByText(/Routing set up!/i)).toBeInTheDocument(); + expect(await screen.findByText(/Input started sucessfully!/i)).toBeInTheDocument(); + }); + + it('should start the input', async () => { + renderWizard(); + await waitFor(() => createStream()); + goToStartInputStep(); + startInput(); + + await waitFor(() => expect(InputStatesStore.start).toHaveBeenCalledWith(input)); + }); + + it('should create the new stream', async () => { + renderWizard(); + await waitFor(() => createStream()); + goToStartInputStep(); + startInput(); + + await waitFor(() => expect(fetch).toHaveBeenCalledWith( + 'POST', + expect.stringContaining(createStreamUrl), + newStreamConfig, + )); + }); + + it('should start the new stream', async () => { + asMock(fetch).mockImplementation(() => Promise.resolve({ stream_id: 1 })); + + renderWizard(); + await waitFor(() => createStream()); + goToStartInputStep(); + startInput(); + + await waitFor(() => expect(fetch).toHaveBeenCalledWith( + 'POST', + expect.stringContaining(startStreamUrl(1)), + )); + }); + + it('should create the new pipeline', async () => { + renderWizard(); + await waitFor(() => createStream(true)); + goToStartInputStep(); + startInput(); + + await waitFor(() => expect(fetch).toHaveBeenCalledWith( + 'POST', + expect.stringMatching(createPipelineUrlRegEx), + newPipelineConfig, + )); + }); + + it('create routing for the new stream', async () => { + renderWizard(); + await waitFor(() => createStream(true)); + goToStartInputStep(); + startInput(); + + await waitFor(() => expect(fetch).toHaveBeenCalledWith( + 'PUT', + expect.stringMatching(updateRoutingUrlRegEx), + { input_id: 'input-test-id', stream_id: 'streamId1' }, + )); + }); }); + }); - it('should create the new stream', async () => { - renderWizard(); - await waitFor(() => createStream()); - goToStartInputStep(); - startInput(); + describe('Rollback', () => { + it('shows the rollback button', async () => { + // asMock(fetch).mockReturnValue('{ "id": 1 }', { status: 200, headers: { 'content-type': 'application/json' } }); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'POST', - expect.stringContaining(createStreamUrl), - newStreamConfig, - )); - }); + asMock(fetch).mockRejectedValueOnce({}); + asMock(fetch).mockReturnValue(Promise.resolve({})); - it('should start the new stream', async () => { - asMock(fetch).mockImplementation(() => Promise.resolve({ stream_id: 1 })); + await suppressConsole(async () => { + try { + renderWizard(); + } catch (_) {} - renderWizard(); - await waitFor(() => createStream()); - goToStartInputStep(); - startInput(); + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'POST', - expect.stringContaining(startStreamUrl(1)), - )); - }); + await selectEvent.openMenu(streamSelect); - it('should create the new pipeline', async () => { - renderWizard(); - await waitFor(() => createStream(true)); - goToStartInputStep(); - startInput(); + await selectEvent.select(streamSelect, 'One Stream'); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'POST', - expect.stringMatching(createPipelineUrlRegEx), - newPipelineConfig, - )); - }); + goToStartInputStep(); - it('create routing for the new stream', async () => { - renderWizard(); - await waitFor(() => createStream(true)); - goToStartInputStep(); - startInput(); + startInput() + .catch(() => {}); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'PUT', - expect.stringMatching(updateRoutingUrlRegEx), - { input_id: 'input-test-id', stream_id: 'streamId1' }, - )); + const rollbackInputButton = await screen.findByTestId('rollback-input-button'); + + fireEvent.click(rollbackInputButton); + }); }); }); }); diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts b/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts index 575670b352dd..66b55f024f23 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts @@ -16,6 +16,8 @@ */ import { useMutation } from '@tanstack/react-query'; +import { Streams } from '@graylog/server-api'; + import { qualifyUrl } from 'util/URLUtils'; import fetch from 'logic/rest/FetchProvider'; import ApiRoutes from 'routing/ApiRoutes'; @@ -39,11 +41,7 @@ type PipelineConfiguration = Pick -const createStream = async (stream: StreamConfiguration): Promise<{ stream_id: string }> => { - const url = qualifyUrl(ApiRoutes.StreamsApiController.create().url); - - return fetch('POST', url, stream); -}; +const createStream = async (stream: StreamConfiguration): Promise<{ stream_id: string }> => Streams.create(stream); const startStream = async (streamId) => { const url = qualifyUrl(ApiRoutes.StreamsApiController.resume(streamId).url); diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx index 2390fea0bdc6..cf39d332ff52 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx @@ -311,7 +311,7 @@ const StartInputStep = () => { if (startInputStatus === 'FAILED' || startInputStatus === 'ROLLING_BACK') { return ( - + ); } From fe6c28226770cd5ba073e87d77cfebd2e00d165b Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Fri, 17 Jan 2025 16:08:12 +0100 Subject: [PATCH 07/56] Using `mutatet` instead of `mutateAsync` to make sure promise rejection is caught. --- .../InputSetupWizard.StartInput.test.tsx | 27 +++++++------------ .../InputSetupWizard/steps/StartInputStep.tsx | 5 ++-- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx index 8f62cb97c365..db0ef2c8de7c 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx @@ -17,9 +17,7 @@ import * as React from 'react'; import { render, screen, fireEvent, waitFor } from 'wrappedTestingLibrary'; import selectEvent from 'react-select-event'; -import { act } from 'wrappedTestingLibrary/hooks'; -import suppressConsole from 'helpers/suppressConsole'; import fetch from 'logic/rest/FetchProvider'; import { asMock, StoreMock as MockStore } from 'helpers/mocking'; import usePipelinesConnectedStream from 'hooks/usePipelinesConnectedStream'; @@ -361,31 +359,24 @@ describe('InputSetupWizard Start Input', () => { describe('Rollback', () => { it('shows the rollback button', async () => { - // asMock(fetch).mockReturnValue('{ "id": 1 }', { status: 200, headers: { 'content-type': 'application/json' } }); - - asMock(fetch).mockRejectedValueOnce({}); + asMock(fetch).mockRejectedValueOnce(new Error()); asMock(fetch).mockReturnValue(Promise.resolve({})); - await suppressConsole(async () => { - try { - renderWizard(); - } catch (_) {} + renderWizard(); - const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); + const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); - await selectEvent.openMenu(streamSelect); + await selectEvent.openMenu(streamSelect); - await selectEvent.select(streamSelect, 'One Stream'); + await selectEvent.select(streamSelect, 'One Stream'); - goToStartInputStep(); + goToStartInputStep(); - startInput() - .catch(() => {}); + startInput(); - const rollbackInputButton = await screen.findByTestId('rollback-input-button'); + const rollbackInputButton = await screen.findByTestId('rollback-input-button'); - fireEvent.click(rollbackInputButton); - }); + fireEvent.click(rollbackInputButton); }); }); }); diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx index cf39d332ff52..01d1c7c455f9 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx @@ -163,9 +163,8 @@ const StartInputStep = () => { break; case 'EXISTING': - updateRoutingMutation.mutateAsync({ input_id: inputId, stream_id: routingStepData.streamId }).finally(() => { - startInput(); - }); + updateRoutingMutation.mutate({ input_id: inputId, stream_id: routingStepData.streamId }); + startInput(); break; case 'DEFAULT': From 14570a67c729b8cac9d3a7c2ba3755963900189e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Mon, 20 Jan 2025 13:16:01 +0100 Subject: [PATCH 08/56] Use generated apis --- .../hooks/useSetupInputMutations.ts | 50 ++++++------------- .../InputSetupWizard/steps/StartInputStep.tsx | 2 +- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts b/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts index 66b55f024f23..98688e920054 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts @@ -16,13 +16,11 @@ */ import { useMutation } from '@tanstack/react-query'; -import { Streams } from '@graylog/server-api'; +import { PipelinesPipelines, Streams, PipelinesRules } from '@graylog/server-api'; -import { qualifyUrl } from 'util/URLUtils'; -import fetch from 'logic/rest/FetchProvider'; -import ApiRoutes from 'routing/ApiRoutes'; import type { Stream } from 'logic/streams/types'; import type { PipelineType } from 'stores/pipelines/PipelinesStore'; +import SourceGenerator from 'logic/pipelines/SourceGenerator'; export type RoutingParams = { stream_id?: string, @@ -41,43 +39,25 @@ type PipelineConfiguration = Pick -const createStream = async (stream: StreamConfiguration): Promise<{ stream_id: string }> => Streams.create(stream); +const createStream = async (stream: StreamConfiguration): Promise<{ stream_id: string }> => Streams.create({ + matching_type: undefined, + rules: undefined, + content_pack: undefined, + description: undefined, + ...stream, +}); -const startStream = async (streamId) => { - const url = qualifyUrl(ApiRoutes.StreamsApiController.resume(streamId).url); +const startStream = async (streamId) => Streams.resume(streamId); - return fetch('POST', url); -}; - -const createPipeline = (pipeline: PipelineConfiguration) : Promise => { - const url = qualifyUrl(ApiRoutes.PipelinesController.create().url); - - return fetch('POST', url, pipeline); -}; - -const updateRouting = async (params: RoutingParams): Promise <{ id: string }> => { - const url = qualifyUrl(ApiRoutes.PipelinesController.updateRouting().url); - - return fetch('PUT', url, params); -}; - -const deleteStream = async (streamId: string) => { - const url = qualifyUrl(ApiRoutes.StreamsApiController.delete(streamId).url); - - return fetch('DELETE', url); -}; +const createPipeline = (pipeline: PipelineConfiguration): Promise => PipelinesPipelines.createFromParser(SourceGenerator.generatePipeline(pipeline)); -const deletePipeline = async (pipelineId: string) => { - const url = qualifyUrl(ApiRoutes.PipelinesController.delete(pipelineId).url); +const updateRouting = async (params: RoutingParams): Promise <{rule_id: string}> => PipelinesPipelines.routing({ remove_from_default: undefined, stream_id: undefined, ...params }); - return fetch('DELETE', url); -}; +const deleteStream = async (streamId: string) => Streams.remove(streamId); -const deleteRoutingRule = async (ruleId: string) => { - const url = qualifyUrl(ApiRoutes.RulesController.delete(ruleId).url); +const deletePipeline = async (pipelineId: string) => PipelinesPipelines.remove(pipelineId); - return fetch('DELETE', url); -}; +const deleteRoutingRule = async (ruleId: string) => PipelinesRules.remove(ruleId); const usePipelineRoutingMutation = () => { const createStreamMutation = useMutation(createStream); diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx index 01d1c7c455f9..be2c1122bb04 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx @@ -180,7 +180,7 @@ const StartInputStep = () => { const routingStepData = getStepConfigOrData(stepsData, INPUT_WIZARD_STEPS.SETUP_ROUTING) as RoutingStepData; const createdStreamId = createStreamMutation.data?.stream_id; const createdPipelineId = createPipelineMutation.data?.id; - const routingRuleId = updateRoutingMutation.data?.id; + const routingRuleId = updateRoutingMutation.data?.rule_id; switch (routingStepData.streamType) { case 'NEW': From cfd60aa8b0b49a26675d56a87583bc8ddae75808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Wed, 22 Jan 2025 09:46:31 +0100 Subject: [PATCH 09/56] Fix ts issues --- .../hooks/useSetupInputMutations.ts | 25 ++++++++++++++----- .../InputSetupWizard/steps/StartInputStep.tsx | 13 +++------- .../src/components/pipelines/PipelineForm.tsx | 2 +- .../src/stores/pipelines/PipelinesStore.ts | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts b/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts index 98688e920054..64b654cbd3bf 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/hooks/useSetupInputMutations.ts @@ -18,9 +18,9 @@ import { useMutation } from '@tanstack/react-query'; import { PipelinesPipelines, Streams, PipelinesRules } from '@graylog/server-api'; -import type { Stream } from 'logic/streams/types'; -import type { PipelineType } from 'stores/pipelines/PipelinesStore'; import SourceGenerator from 'logic/pipelines/SourceGenerator'; +import type { Stream } from 'logic/streams/types'; +import type { PipelineType, StageType } from 'stores/pipelines/PipelinesStore'; export type RoutingParams = { stream_id?: string, @@ -35,9 +35,8 @@ export type StreamConfiguration = Pick + 'description' +> & Partial>; const createStream = async (stream: StreamConfiguration): Promise<{ stream_id: string }> => Streams.create({ matching_type: undefined, @@ -49,7 +48,21 @@ const createStream = async (stream: StreamConfiguration): Promise<{ stream_id: s const startStream = async (streamId) => Streams.resume(streamId); -const createPipeline = (pipeline: PipelineConfiguration): Promise => PipelinesPipelines.createFromParser(SourceGenerator.generatePipeline(pipeline)); +const createPipeline = (pipeline: PipelineConfiguration): Promise => { + const requestPipeline = { + id: undefined, + errors: undefined, + created_at: undefined, + modified_at: undefined, + stages: [{ stage: 0, rules: [], match: 'EITHER' } as StageType], + ...pipeline, + }; + + return PipelinesPipelines.createFromParser({ + ...requestPipeline, + source: SourceGenerator.generatePipeline(requestPipeline), + }); +}; const updateRouting = async (params: RoutingParams): Promise <{rule_id: string}> => PipelinesPipelines.routing({ remove_from_default: undefined, stream_id: undefined, ...params }); diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx index be2c1122bb04..cad5ead1405e 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx @@ -27,7 +27,6 @@ import useInputSetupWizardSteps from 'components/inputs/InputSetupWizard//hooks/ import { INPUT_WIZARD_STEPS } from 'components/inputs/InputSetupWizard/types'; import { checkHasPreviousStep, checkHasNextStep, checkIsNextStepDisabled, getStepConfigOrData } from 'components/inputs/InputSetupWizard/helpers/stepHelper'; import type { RoutingStepData } from 'components/inputs/InputSetupWizard/steps/SetupRoutingStep'; -import SourceGenerator from 'logic/pipelines/SourceGenerator'; import type { StreamConfiguration } from 'components/inputs/InputSetupWizard/hooks/useSetupInputMutations'; import ProgressMessage from 'components/inputs/InputSetupWizard/steps/components/ProgressMessage'; @@ -110,12 +109,7 @@ const StartInputStep = () => { description: `Pipeline for Stream: ${stream.title} created by the Input Setup Wizard.`, }; - const requestPipeline = { - ...pipeline, - source: SourceGenerator.generatePipeline({ ...pipeline, stages: [{ stage: 0, rules: [], match: '' }] }), - }; - - return createPipelineMutation.mutateAsync(requestPipeline); + return createPipelineMutation.mutateAsync(pipeline); }; const startInput = async () => { @@ -163,8 +157,9 @@ const StartInputStep = () => { break; case 'EXISTING': - updateRoutingMutation.mutate({ input_id: inputId, stream_id: routingStepData.streamId }); - startInput(); + updateRoutingMutation.mutateAsync({ input_id: inputId, stream_id: routingStepData.streamId }).finally(() => { + startInput(); + }); break; case 'DEFAULT': diff --git a/graylog2-web-interface/src/components/pipelines/PipelineForm.tsx b/graylog2-web-interface/src/components/pipelines/PipelineForm.tsx index 26e0c0faad56..cc14a94d6456 100644 --- a/graylog2-web-interface/src/components/pipelines/PipelineForm.tsx +++ b/graylog2-web-interface/src/components/pipelines/PipelineForm.tsx @@ -38,7 +38,7 @@ const emptyPipeline: PipelineType = { id: undefined, title: '', description: '', - stages: [{ stage: 0, rules: [], match: '' }], + stages: [{ stage: 0, rules: [], match: 'EITHER' }], source: '', created_at: '', modified_at: '', diff --git a/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts b/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts index 3b5e047d46f1..e42697885d9f 100644 --- a/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts +++ b/graylog2-web-interface/src/stores/pipelines/PipelinesStore.ts @@ -66,7 +66,7 @@ export type PipelineType = { export type StageType = { stage: number, - match: string, + match: 'ALL' | 'EITHER' | 'PASS', rules: Array, }; From 513208838d752c0f17641c96a582b242c1fceac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Wed, 22 Jan 2025 10:36:55 +0100 Subject: [PATCH 10/56] Remove wip test --- .../InputSetupWizard.StartInput.test.tsx | 82 +++++++------------ 1 file changed, 29 insertions(+), 53 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx index db0ef2c8de7c..61184248d6e2 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.StartInput.test.tsx @@ -18,7 +18,8 @@ import * as React from 'react'; import { render, screen, fireEvent, waitFor } from 'wrappedTestingLibrary'; import selectEvent from 'react-select-event'; -import fetch from 'logic/rest/FetchProvider'; +import { PipelinesPipelines, Streams } from '@graylog/server-api'; + import { asMock, StoreMock as MockStore } from 'helpers/mocking'; import usePipelinesConnectedStream from 'hooks/usePipelinesConnectedStream'; import useStreams from 'components/streams/hooks/useStreams'; @@ -29,6 +30,22 @@ import { InputStatesStore } from 'stores/inputs/InputStatesStore'; import InputSetupWizardProvider from './contexts/InputSetupWizardProvider'; import InputSetupWizard from './Wizard'; +jest.mock('@graylog/server-api', () => ({ + PipelinesPipelines: { + createFromParser: jest.fn(), + routing: jest.fn(), + remove: jest.fn(), + }, + Streams: { + create: jest.fn(), + resume: jest.fn(), + remove: jest.fn(), + }, + PipelinesRules: { + remove: jest.fn(), + }, +})); + jest.mock('components/streams/hooks/useStreams', () => jest.fn()); jest.mock('hooks/usePipelinesConnectedStream'); jest.mock('components/indices/hooks/useIndexSetsList'); @@ -153,11 +170,6 @@ const useIndexSetsListResult = { refetch: () => {}, }; -const updateRoutingUrlRegEx = /.+(system\/pipelines\/pipeline\/routing)/i; -const createStreamUrl = '/streams'; -const startStreamUrl = (streamId) => `/streams/${streamId}/resume`; -const createPipelineUrlRegEx = /.+(system\/pipelines\/pipeline)/i; - const newStreamConfig = { description: 'Wingardium new stream', index_set_id: 'default_id', @@ -232,10 +244,6 @@ beforeEach(() => { describe('InputSetupWizard Start Input', () => { describe('Start Input', () => { - beforeEach(() => { - asMock(fetch).mockReturnValue(Promise.resolve({})); - }); - it('should render the Start Input step', async () => { renderWizard(); goToStartInputStep(); @@ -268,9 +276,7 @@ describe('InputSetupWizard Start Input', () => { await waitFor(() => expect(InputStatesStore.start).toHaveBeenCalledWith(input)); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'PUT', - expect.stringMatching(updateRoutingUrlRegEx), + await waitFor(() => expect(PipelinesPipelines.routing).toHaveBeenCalledWith( { input_id: 'input-test-id', stream_id: 'streamId1' }, )); @@ -280,6 +286,10 @@ describe('InputSetupWizard Start Input', () => { }); describe('new stream', () => { + beforeEach(() => { + asMock(Streams.create).mockReturnValue(Promise.resolve({ stream_id: '1' })); + }); + it('should show the progress for all steps', async () => { renderWizard(); await waitFor(() => createStream(true)); @@ -308,25 +318,18 @@ describe('InputSetupWizard Start Input', () => { goToStartInputStep(); startInput(); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'POST', - expect.stringContaining(createStreamUrl), - newStreamConfig, + await waitFor(() => expect(Streams.create).toHaveBeenCalledWith( + expect.objectContaining(newStreamConfig), )); }); it('should start the new stream', async () => { - asMock(fetch).mockImplementation(() => Promise.resolve({ stream_id: 1 })); - renderWizard(); await waitFor(() => createStream()); goToStartInputStep(); startInput(); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'POST', - expect.stringContaining(startStreamUrl(1)), - )); + await waitFor(() => expect(Streams.resume).toHaveBeenCalled()); }); it('should create the new pipeline', async () => { @@ -335,10 +338,8 @@ describe('InputSetupWizard Start Input', () => { goToStartInputStep(); startInput(); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'POST', - expect.stringMatching(createPipelineUrlRegEx), - newPipelineConfig, + await waitFor(() => expect(PipelinesPipelines.createFromParser).toHaveBeenCalledWith( + expect.objectContaining(newPipelineConfig), )); }); @@ -348,35 +349,10 @@ describe('InputSetupWizard Start Input', () => { goToStartInputStep(); startInput(); - await waitFor(() => expect(fetch).toHaveBeenCalledWith( - 'PUT', - expect.stringMatching(updateRoutingUrlRegEx), + await waitFor(() => expect(PipelinesPipelines.routing).toHaveBeenCalledWith( { input_id: 'input-test-id', stream_id: 'streamId1' }, )); }); }); }); - - describe('Rollback', () => { - it('shows the rollback button', async () => { - asMock(fetch).mockRejectedValueOnce(new Error()); - asMock(fetch).mockReturnValue(Promise.resolve({})); - - renderWizard(); - - const streamSelect = await screen.findByLabelText(/All messages \(Default\)/i); - - await selectEvent.openMenu(streamSelect); - - await selectEvent.select(streamSelect, 'One Stream'); - - goToStartInputStep(); - - startInput(); - - const rollbackInputButton = await screen.findByTestId('rollback-input-button'); - - fireEvent.click(rollbackInputButton); - }); - }); }); From fd07254fd4b2c842740a67523c37f7469bcf3c78 Mon Sep 17 00:00:00 2001 From: Othello Maurer Date: Wed, 29 Jan 2025 11:41:35 +0100 Subject: [PATCH 11/56] Refactor misc MongoDB API usages (#21385) * Remove JacksonDBCollection usage from DBContentStreamUserSettingsService * Remove JacksonDBCollection usage from EntityListPreferencesServiceImpl * Remove JacksonDBCollection usage from DecoratorServiceImpl * Remove JacksonDBCollection usage from ESMongoDateTimeDeserializerTest * Remove JacksonDBCollection usage from DBProcessingStatusService * Remove JacksonDBCollection usage from RoleServiceImpl * Remove JacksonDBCollection usage from OutputServiceImpl * Remove JacksonDBCollection usage from DBTelemetryUserSettingsService * Remove JacksonDBCollection usage from MongoInputStatusService * Remove usage of legacy DuplicateKeyException * Remove usage of PaginatedDbService#getPage * Fix MigrationHelpersTest * Remove usage of DuplicateKeyException from AccessTokenServiceImplTest * Remove usage of DuplicateKeyException from MongoDbSessionDAO * Remove redundant parenthesis Co-authored-by: Bernd Ahlers * Fix error message * Fix error message * Replace integer casts with Ints#saturatedCast --------- Co-authored-by: Bernd Ahlers --- .../views/favorites/FavoritesResource.java | 20 ++-- .../views/favorites/FavoritesService.java | 14 ++- .../views/search/views/ViewService.java | 9 +- .../lastOpened/LastOpenedService.java | 9 +- .../db/ContentStreamUserSettings.java | 3 +- .../DBContentStreamUserSettingsService.java | 33 ++++--- .../graylog2/decorators/DecoratorImpl.java | 10 +- .../decorators/DecoratorServiceImpl.java | 55 +++++------ .../inputs/persistence/InputStatusRecord.java | 2 + .../persistence/MongoInputStatusService.java | 46 ++++----- .../graylog2/migrations/MigrationHelpers.java | 11 ++- ...0705071400_AddEventIndexSetsMigration.java | 12 ++- .../EntityListPreferencesServiceImpl.java | 43 ++++----- .../system/indexer/IndexSetsResource.java | 10 +- .../system/lookup/LookupTableResource.java | 24 +++-- .../security/AccessTokenServiceImpl.java | 15 +-- .../graylog2/security/MongoDbSessionDAO.java | 8 +- .../graylog2/streams/OutputServiceImpl.java | 89 ++++++++--------- .../processing/DBProcessingStatusService.java | 68 ++++++------- .../processing/ProcessingStatusDto.java | 3 +- .../db/DBTelemetryUserSettingsService.java | 28 +++--- .../user/db/TelemetryUserSettingsDto.java | 6 +- .../org/graylog2/users/RoleServiceImpl.java | 96 ++++++++----------- .../ESMongoDateTimeDeserializerTest.java | 20 ++-- .../facades/OutputFacadeTest.java | 6 +- .../ContentStreamServiceWithDbTest.java | 4 +- .../database/utils/MongoUtilsTest.java | 24 +++++ .../decorators/DecoratorServiceImplTest.java | 3 +- .../MongoInputStatusServiceTest.java | 13 +-- .../migrations/MigrationHelpersTest.java | 10 +- .../RolesToGrantsMigrationTest.java | 3 +- ...tPreferencesCleanerOnUserDeletionTest.java | 4 +- .../EntityListPreferencesServiceImplTest.java | 3 +- .../security/AccessTokenServiceImplTest.java | 11 ++- .../streams/OutputServiceImplTest.java | 4 +- .../DBProcessingStatusServiceTest.java | 12 +-- .../rest/TelemetryServiceWithDbTest.java | 3 +- 37 files changed, 386 insertions(+), 348 deletions(-) diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesResource.java b/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesResource.java index 90866a39eef4..532b1342aa0d 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesResource.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesResource.java @@ -19,18 +19,9 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.apache.shiro.authz.annotation.RequiresAuthentication; -import org.graylog.grn.GRN; -import org.graylog.plugins.views.audit.ViewsAuditEventTypes; -import org.graylog.plugins.views.search.permissions.SearchUser; -import org.graylog2.audit.jersey.AuditEvent; -import org.graylog2.rest.models.PaginatedResponse; - import jakarta.inject.Inject; - +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; - import jakarta.ws.rs.DELETE; import jakarta.ws.rs.DefaultValue; import jakarta.ws.rs.GET; @@ -41,6 +32,11 @@ import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.MediaType; +import org.apache.shiro.authz.annotation.RequiresAuthentication; +import org.graylog.plugins.views.audit.ViewsAuditEventTypes; +import org.graylog.plugins.views.search.permissions.SearchUser; +import org.graylog2.audit.jersey.AuditEvent; +import org.graylog2.rest.models.PaginatedResponse; import java.util.Optional; @@ -60,8 +56,8 @@ public FavoritesResource(final FavoritesService favoritesService) { @GET @ApiOperation("Get the Favorites for the Start Page for the user") - public PaginatedResponse getFavoriteItems(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, - @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("5") int perPage, + public PaginatedResponse getFavoriteItems(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") @Min(1) int page, + @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("5") @Min(1) int perPage, @ApiParam(name = "type") @QueryParam("type") Optional type, @Context SearchUser searchUser) { return favoritesService.findFavoritesFor(searchUser, type, page, perPage); diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesService.java b/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesService.java index 5e1afe688b08..0679a0288ca8 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesService.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/favorites/FavoritesService.java @@ -19,7 +19,7 @@ import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import com.mongodb.BasicDBObject; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import com.mongodb.client.MongoCollection; import com.mongodb.client.model.Filters; import com.mongodb.client.model.Indexes; @@ -30,7 +30,6 @@ import org.graylog.plugins.views.startpage.recentActivities.RecentActivityEvent; import org.graylog.plugins.views.startpage.title.StartPageItemTitleRetriever; import org.graylog2.database.MongoCollections; -import org.graylog2.database.PaginatedDbService; import org.graylog2.database.PaginatedList; import org.graylog2.database.utils.MongoUtils; import org.graylog2.rest.models.PaginatedResponse; @@ -73,9 +72,11 @@ public PaginatedResponse findFavoritesFor(final SearchUser searchUser, .map(title -> new Favorite(i, title)) ) .flatMap(Optional::stream) + .skip(perPage * Math.max(0L, page - 1)) + .limit(perPage) .toList(); - return PaginatedResponse.create("favorites", new PaginatedList<>(PaginatedDbService.getPage(items, page, perPage), items.size(), page, perPage)); + return PaginatedResponse.create("favorites", new PaginatedList<>(items, items.size(), page, perPage)); } public void save(FavoritesForUserDTO favorite) { @@ -129,8 +130,11 @@ public Optional create(final FavoritesForUserDTO favorite) try { final var result = db.insertOne(favorite); return mongoUtils.getById(MongoUtils.insertedId(result)); - } catch (DuplicateKeyException e) { - throw new IllegalStateException("Unable to create a Favorites collection, collection with this id already exists : " + favorite.id()); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + throw new IllegalStateException("Unable to create favorites. Favorites with this id already exist: " + favorite.id()); + } + throw e; } } diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/views/ViewService.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/views/ViewService.java index fe7cea64098b..fc28c585c78a 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/views/ViewService.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/views/ViewService.java @@ -16,7 +16,7 @@ */ package org.graylog.plugins.views.search.views; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import com.mongodb.client.MongoCollection; import com.mongodb.client.model.Filters; import com.mongodb.client.model.Sorts; @@ -226,8 +226,11 @@ public ViewDTO save(ViewDTO viewDTO) { try { final var save = collection.insertOne(requirementsForView(viewDTO)); return mongoUtils.getById(MongoUtils.insertedId(save)).orElseThrow(() -> new IllegalStateException("Unable to retrieve saved View!")); - } catch (DuplicateKeyException e) { - throw new IllegalStateException("Unable to save view, it already exists."); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + throw new IllegalStateException("Unable to save view, it already exists."); + } + throw e; } } diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/startpage/lastOpened/LastOpenedService.java b/graylog2-server/src/main/java/org/graylog/plugins/views/startpage/lastOpened/LastOpenedService.java index 0ecc88024b79..b8faa0086608 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/startpage/lastOpened/LastOpenedService.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/startpage/lastOpened/LastOpenedService.java @@ -19,7 +19,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import com.mongodb.client.MongoCollection; import com.mongodb.client.model.Filters; import com.mongodb.client.model.Indexes; @@ -59,8 +59,11 @@ Optional findForUser(final String userId) { public void create(final LastOpenedForUserDTO lastOpenedItems) { try { db.insertOne(lastOpenedItems); - } catch (DuplicateKeyException e) { - throw new IllegalStateException("Unable to create a last opened collection, collection with this id already exists : " + lastOpenedItems.id()); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + throw new IllegalStateException("Unable to create record of last opened items. Record with this id already exists : " + lastOpenedItems.id()); + } + throw e; } } diff --git a/graylog2-server/src/main/java/org/graylog2/contentstream/db/ContentStreamUserSettings.java b/graylog2-server/src/main/java/org/graylog2/contentstream/db/ContentStreamUserSettings.java index 7aad9cf01974..7bcf71c44970 100644 --- a/graylog2-server/src/main/java/org/graylog2/contentstream/db/ContentStreamUserSettings.java +++ b/graylog2-server/src/main/java/org/graylog2/contentstream/db/ContentStreamUserSettings.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import org.graylog2.database.MongoEntity; import org.mongojack.Id; import org.mongojack.ObjectId; @@ -27,7 +28,7 @@ import java.util.List; @AutoValue -public abstract class ContentStreamUserSettings { +public abstract class ContentStreamUserSettings implements MongoEntity { public static final String FIELD_USER_ID = "user_id"; public static final String FIELD_CONTENT_ENABLED = "content_stream_enabled"; diff --git a/graylog2-server/src/main/java/org/graylog2/contentstream/db/DBContentStreamUserSettingsService.java b/graylog2-server/src/main/java/org/graylog2/contentstream/db/DBContentStreamUserSettingsService.java index c9aaad03aaf7..7933836a9696 100644 --- a/graylog2-server/src/main/java/org/graylog2/contentstream/db/DBContentStreamUserSettingsService.java +++ b/graylog2-server/src/main/java/org/graylog2/contentstream/db/DBContentStreamUserSettingsService.java @@ -16,42 +16,41 @@ */ package org.graylog2.contentstream.db; -import org.bson.types.ObjectId; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.graylog2.database.MongoConnection; -import org.mongojack.DBQuery; -import org.mongojack.JacksonDBCollection; - +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.ReplaceOptions; import jakarta.inject.Inject; +import org.graylog2.database.MongoCollections; +import org.graylog2.database.utils.MongoUtils; import java.util.Optional; -import static org.graylog2.telemetry.user.db.TelemetryUserSettingsDto.FIELD_USER_ID; +import static org.graylog2.contentstream.db.ContentStreamUserSettings.FIELD_USER_ID; public class DBContentStreamUserSettingsService { public static final String COLLECTION_NAME = "content_stream_user_settings"; - private final JacksonDBCollection db; + private final MongoCollection collection; @Inject - public DBContentStreamUserSettingsService(MongoConnection mongoConnection, - MongoJackObjectMapperProvider mapper) { - this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection(COLLECTION_NAME), - ContentStreamUserSettings.class, - ObjectId.class, - mapper.get()); + public DBContentStreamUserSettingsService(MongoCollections mongoCollections) { + collection = mongoCollections.collection(COLLECTION_NAME, ContentStreamUserSettings.class); } public Optional findByUserId(String userId) { - return Optional.ofNullable(db.findOne(DBQuery.is(FIELD_USER_ID, userId))); + return Optional.ofNullable(collection.find(Filters.eq(FIELD_USER_ID, userId)).first()); } public void save(ContentStreamUserSettings dto) { - db.save(dto); + if (dto.id() == null) { + collection.insertOne(dto); + } else { + collection.replaceOne(MongoUtils.idEq(dto.id()), dto, new ReplaceOptions().upsert(true)); + } } public void delete(String userId) { - db.remove(DBQuery.is(FIELD_USER_ID, userId)); + collection.deleteMany(Filters.eq(FIELD_USER_ID, userId)); } } diff --git a/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorImpl.java b/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorImpl.java index ad7b9bcad017..723464ae28e8 100644 --- a/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorImpl.java @@ -21,15 +21,14 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import jakarta.validation.constraints.NotBlank; import org.graylog.autovalue.WithBeanGetter; +import org.graylog2.database.BuildableMongoEntity; import org.graylog2.database.DbEntity; import org.mongojack.Id; import org.mongojack.ObjectId; import javax.annotation.Nullable; - -import jakarta.validation.constraints.NotBlank; - import java.util.Map; import java.util.Optional; @@ -42,7 +41,8 @@ @DbEntity(collection = "decorators", titleField = NO_TITLE, readPermission = DECORATORS_READ) -public abstract class DecoratorImpl implements Decorator, Comparable { +public abstract class DecoratorImpl implements Decorator, Comparable, + BuildableMongoEntity { static final String FIELD_ID = "id"; static final String FIELD_TYPE = "type"; static final String FIELD_CONFIG = "config"; @@ -109,7 +109,7 @@ public static Decorator create(@JsonProperty(FIELD_TYPE) String type, } @AutoValue.Builder - public abstract static class Builder { + public abstract static class Builder implements BuildableMongoEntity.Builder { public abstract Builder id(String id); abstract Builder type(String type); diff --git a/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorServiceImpl.java index 5b3acc80d9a4..c879a1967422 100644 --- a/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/decorators/DecoratorServiceImpl.java @@ -17,59 +17,55 @@ package org.graylog2.decorators; import com.google.common.base.Strings; -import com.mongodb.DBCollection; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Filters; +import jakarta.inject.Inject; import org.graylog2.database.DbEntity; -import org.graylog2.database.MongoConnection; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; -import org.mongojack.DBQuery; -import org.mongojack.JacksonDBCollection; - -import jakarta.inject.Inject; +import org.graylog2.database.utils.MongoUtils; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkArgument; public class DecoratorServiceImpl implements DecoratorService { - private final JacksonDBCollection coll; + private final MongoCollection collection; + private final MongoUtils mongoUtils; @Inject - public DecoratorServiceImpl(MongoConnection mongoConnection, MongoJackObjectMapperProvider mongoJackObjectMapperProvider) { + public DecoratorServiceImpl(MongoCollections mongoCollections) { final String collectionName = DecoratorImpl.class.getAnnotation(DbEntity.class).collection(); - final DBCollection dbCollection = mongoConnection.getDatabase().getCollection(collectionName); - this.coll = JacksonDBCollection.wrap(dbCollection, DecoratorImpl.class, String.class, mongoJackObjectMapperProvider.get()); + collection = mongoCollections.collection(collectionName, DecoratorImpl.class); + mongoUtils = mongoCollections.utils(collection); } @Override public List findForStream(String streamId) { - return toInterfaceList(coll.find(DBQuery.is(DecoratorImpl.FIELD_STREAM, Optional.of(streamId))).toArray()); + return collection.find(Filters.eq(DecoratorImpl.FIELD_STREAM, streamId)).into(new ArrayList<>()); } @Override public List findForGlobal() { - return toInterfaceList(coll.find(DBQuery.or( - DBQuery.notExists(DecoratorImpl.FIELD_STREAM), - DBQuery.is(DecoratorImpl.FIELD_STREAM, Optional.empty()) - )).toArray()); + return collection.find(Filters.or( + Filters.exists(DecoratorImpl.FIELD_STREAM, false), + Filters.eq(DecoratorImpl.FIELD_STREAM, Optional.empty()) + )).into(new ArrayList<>()); } @Override public Decorator findById(String decoratorId) throws NotFoundException { - final Decorator result = coll.findOneById(decoratorId); - if (result == null) { - throw new NotFoundException("Decorator with id " + decoratorId + " not found."); - } - - return result; + return mongoUtils.getById(decoratorId).orElseThrow(() -> + new NotFoundException("Decorator with id " + decoratorId + " not found.") + ); } @Override public List findAll() { - return toInterfaceList(coll.find().toArray()); + return collection.find().into(new ArrayList<>()); } @Override @@ -86,18 +82,15 @@ public Decorator create(String type, Map config, int order) { public Decorator save(Decorator decorator) { checkArgument(decorator instanceof DecoratorImpl, "Argument must be an instance of DecoratorImpl, not %s", decorator.getClass()); if (!Strings.isNullOrEmpty(decorator.id())) { - this.coll.updateById(decorator.id(), (DecoratorImpl) decorator); - return this.coll.findOneById(decorator.id()); + collection.replaceOne(MongoUtils.idEq(decorator.id()), (DecoratorImpl) decorator); + return decorator; } - return this.coll.save((DecoratorImpl) decorator).getSavedObject(); + return mongoUtils.save((DecoratorImpl) decorator); } @Override public int delete(String id) { - return this.coll.removeById(id).getN(); + return mongoUtils.deleteById(id) ? 1 : 0; } - private List toInterfaceList(List concreteList) { - return concreteList.stream().collect(Collectors.toList()); - } } diff --git a/graylog2-server/src/main/java/org/graylog2/inputs/persistence/InputStatusRecord.java b/graylog2-server/src/main/java/org/graylog2/inputs/persistence/InputStatusRecord.java index fa2638fff32c..e86ad8f7ddbd 100644 --- a/graylog2-server/src/main/java/org/graylog2/inputs/persistence/InputStatusRecord.java +++ b/graylog2-server/src/main/java/org/graylog2/inputs/persistence/InputStatusRecord.java @@ -42,6 +42,8 @@ public static Builder builder() { return new AutoValue_InputStatusRecord.Builder(); } + public abstract Builder toBuilder(); + @AutoValue.Builder public static abstract class Builder { @Id diff --git a/graylog2-server/src/main/java/org/graylog2/inputs/persistence/MongoInputStatusService.java b/graylog2-server/src/main/java/org/graylog2/inputs/persistence/MongoInputStatusService.java index 65fa2e31ce47..bdd3120fea05 100644 --- a/graylog2-server/src/main/java/org/graylog2/inputs/persistence/MongoInputStatusService.java +++ b/graylog2-server/src/main/java/org/graylog2/inputs/persistence/MongoInputStatusService.java @@ -18,22 +18,19 @@ import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; -import com.mongodb.DB; -import com.mongodb.DBCollection; -import org.bson.types.ObjectId; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.graylog2.database.MongoConnection; +import com.google.common.primitives.Ints; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.ReplaceOptions; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.inputs.InputService; import org.graylog2.rest.models.system.inputs.responses.InputDeleted; -import org.mongojack.JacksonDBCollection; -import org.mongojack.WriteResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.inject.Inject; -import jakarta.inject.Singleton; - import java.util.Optional; /** @@ -47,42 +44,35 @@ public class MongoInputStatusService implements InputStatusService { public static final String COLLECTION_NAME = "input_status"; - private final JacksonDBCollection statusCollection; private final InputService inputService; + private final MongoCollection collection; @Inject - public MongoInputStatusService(MongoConnection mongoConnection, - MongoJackObjectMapperProvider objectMapperProvider, - InputService inputService, - EventBus eventBus) { + public MongoInputStatusService(MongoCollections mongoCollections, InputService inputService, EventBus eventBus) { this.inputService = inputService; - DB mongoDatabase = mongoConnection.getDatabase(); - DBCollection collection = mongoDatabase.getCollection(COLLECTION_NAME); + this.collection = mongoCollections.nonEntityCollection(COLLECTION_NAME, InputStatusRecord.class); eventBus.register(this); - - statusCollection = JacksonDBCollection.wrap( - collection, - InputStatusRecord.class, - ObjectId.class, - objectMapperProvider.get()); } @Override public Optional get(final String inputId) { - return Optional.ofNullable(statusCollection.findOneById(new ObjectId(inputId))); + return Optional.ofNullable(collection.find(MongoUtils.idEq(inputId)).first()); } @Override public InputStatusRecord save(InputStatusRecord statusRecord) { - final WriteResult save = statusCollection.save(statusRecord); - return save.getSavedObject(); + if (statusRecord.inputId() == null) { + final var insertedId = MongoUtils.insertedIdAsString(collection.insertOne(statusRecord)); + return statusRecord.toBuilder().inputId(insertedId).build(); + } + collection.replaceOne(MongoUtils.idEq(statusRecord.inputId()), statusRecord, new ReplaceOptions().upsert(true)); + return statusRecord; } @Override public int delete(String inputId) { - final WriteResult delete = statusCollection.removeById(new ObjectId(inputId)); - return delete.getN(); + return Ints.saturatedCast(collection.deleteOne(MongoUtils.idEq(inputId)).getDeletedCount()); } /** diff --git a/graylog2-server/src/main/java/org/graylog2/migrations/MigrationHelpers.java b/graylog2-server/src/main/java/org/graylog2/migrations/MigrationHelpers.java index 44657d626540..087748c9f8b9 100644 --- a/graylog2-server/src/main/java/org/graylog2/migrations/MigrationHelpers.java +++ b/graylog2-server/src/main/java/org/graylog2/migrations/MigrationHelpers.java @@ -16,9 +16,10 @@ */ package org.graylog2.migrations; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import jakarta.inject.Inject; import org.graylog2.database.NotFoundException; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.plugin.database.ValidationException; import org.graylog2.plugin.database.users.User; import org.graylog2.shared.users.Role; @@ -82,7 +83,13 @@ public String ensureBuiltinRole(String roleName, String description, Set try { final Role savedRole = roleService.save(fixedRole); return savedRole.getId(); - } catch (DuplicateKeyException | ValidationException e) { + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + LOG.error("Unable to save fixed '" + roleName + "' role, please restart Graylog to fix this.", e); + } else { + throw e; + } + } catch (ValidationException e) { LOG.error("Unable to save fixed '" + roleName + "' role, please restart Graylog to fix this.", e); } } diff --git a/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java b/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java index fabde0ebb770..113bdb6eeecc 100644 --- a/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java +++ b/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java @@ -18,7 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import jakarta.inject.Inject; import org.bson.types.ObjectId; import org.graylog.events.notifications.EventNotificationSettings; @@ -29,6 +29,7 @@ import org.graylog.events.processor.systemnotification.SystemNotificationEventProcessorConfig; import org.graylog2.configuration.ElasticsearchConfiguration; import org.graylog2.database.NotFoundException; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.indexer.IndexSet; import org.graylog2.indexer.IndexSetValidator; import org.graylog2.indexer.MongoIndexSet; @@ -177,9 +178,12 @@ private IndexSet setupEventsIndexSet(String indexSetTitle, String indexSetDescri LOG.info("Successfully created events index-set <{}/{}>", savedIndexSet.id(), savedIndexSet.title()); return mongoIndexSetFactory.create(savedIndexSet); - } catch (DuplicateKeyException e) { - LOG.error("Couldn't create index-set <{}/{}>", indexSetTitle, indexPrefix); - throw new RuntimeException(e.getMessage()); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + LOG.error("Couldn't create index-set <{}/{}>", indexSetTitle, indexPrefix); + throw new RuntimeException(e.getMessage()); + } + throw e; } } diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImpl.java index 933054636ade..96fa1f57decf 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImpl.java @@ -16,16 +16,14 @@ */ package org.graylog2.rest.resources.entities.preferences.service; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.graylog2.database.MongoConnection; +import com.google.common.primitives.Ints; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.ReplaceOptions; +import jakarta.inject.Inject; +import org.graylog2.database.MongoCollections; import org.graylog2.rest.resources.entities.preferences.model.StoredEntityListPreferences; import org.graylog2.rest.resources.entities.preferences.model.StoredEntityListPreferencesId; -import org.mongojack.JacksonDBCollection; -import org.mongojack.WriteResult; - -import jakarta.inject.Inject; import static org.graylog2.rest.resources.entities.preferences.model.StoredEntityListPreferencesId.USER_ID_SUB_FIELD; @@ -33,34 +31,33 @@ public class EntityListPreferencesServiceImpl implements EntityListPreferencesSe public static final String ENTITY_LIST_PREFERENCES_MONGO_COLLECTION_NAME = "entity_list_preferences"; - private final JacksonDBCollection db; + private final MongoCollection collection; @Inject - public EntityListPreferencesServiceImpl(final MongoConnection mongoConnection, - final MongoJackObjectMapperProvider mapper) { - this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection(ENTITY_LIST_PREFERENCES_MONGO_COLLECTION_NAME), - StoredEntityListPreferences.class, - StoredEntityListPreferencesId.class, - mapper.get()); - + public EntityListPreferencesServiceImpl(MongoCollections mongoCollections) { + collection = mongoCollections.nonEntityCollection(ENTITY_LIST_PREFERENCES_MONGO_COLLECTION_NAME, + StoredEntityListPreferences.class); } @Override public StoredEntityListPreferences get(final StoredEntityListPreferencesId preferencesId) { - return this.db.findOneById(preferencesId); + return collection.find(Filters.eq("_id", preferencesId)).first(); } @Override public boolean save(final StoredEntityListPreferences preferences) { - final WriteResult save = db.save(preferences); - return save.getN() > 0; + if (preferences.preferencesId() == null) { + collection.insertOne(preferences); + } else { + collection.replaceOne(Filters.eq("_id", preferences.preferencesId()), preferences, + new ReplaceOptions().upsert(true)); + } + return true; // ¯\_(ツ)_/¯ } @Override public int deleteAllForUser(String userId) { - DBObject query = new BasicDBObject(); - query.put("_id." + USER_ID_SUB_FIELD, userId); - final WriteResult result = this.db.remove(query); - return result.getN(); + return Ints.saturatedCast(collection.deleteMany(Filters.eq("_id." + USER_ID_SUB_FIELD, userId)) + .getDeletedCount()); } } diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/system/indexer/IndexSetsResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/system/indexer/IndexSetsResource.java index e1adc378202c..0b92480c2101 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/system/indexer/IndexSetsResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/system/indexer/IndexSetsResource.java @@ -17,7 +17,7 @@ package org.graylog2.rest.resources.system.indexer; import com.codahale.metrics.annotation.Timed; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -45,6 +45,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; import org.graylog2.audit.AuditEventTypes; import org.graylog2.audit.jersey.AuditEvent; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.datatiering.DataTieringConfig; import org.graylog2.indexer.IndexSet; import org.graylog2.indexer.IndexSetRegistry; @@ -257,8 +258,11 @@ public IndexSetSummary save(@ApiParam(name = "Index set configuration", required final IndexSetConfig savedObject = indexSetService.save(indexSetConfig); final IndexSetConfig defaultIndexSet = indexSetService.getDefault(); return IndexSetSummary.fromIndexSetConfig(savedObject, savedObject.equals(defaultIndexSet)); - } catch (DuplicateKeyException e) { - throw new BadRequestException(e.getMessage()); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + throw new BadRequestException(e.getMessage()); + } + throw e; } } diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/system/lookup/LookupTableResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/system/lookup/LookupTableResource.java index 3c66785d9637..0c3e7c56a991 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/system/lookup/LookupTableResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/system/lookup/LookupTableResource.java @@ -24,7 +24,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -54,6 +54,7 @@ import org.graylog2.audit.jersey.AuditEvent; import org.graylog2.audit.jersey.NoAuditEvent; import org.graylog2.database.PaginatedList; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.lookup.CachePurge; import org.graylog2.lookup.LookupDefaultMultiValue; import org.graylog2.lookup.LookupDefaultSingleValue; @@ -334,8 +335,11 @@ public LookupTableApi createTable(@ApiParam LookupTableApi lookupTable) { LookupTableDto saved = dbTableService.saveAndPostEvent(lookupTable.toDto()); return LookupTableApi.fromDto(saved); - } catch (DuplicateKeyException e) { - throw new BadRequestException(e.getMessage()); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + throw new BadRequestException(e.getMessage()); + } + throw e; } } @@ -559,8 +563,11 @@ public DataAdapterApi createAdapter(@Valid @ApiParam DataAdapterApi newAdapter) DataAdapterDto saved = dbDataAdapterService.saveAndPostEvent(dto); return DataAdapterApi.fromDto(saved); - } catch (DuplicateKeyException e) { - throw new BadRequestException(e.getMessage()); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + throw new BadRequestException(e.getMessage()); + } + throw e; } } @@ -709,8 +716,11 @@ public CacheApi createCache(@ApiParam CacheApi newCache) { try { final CacheDto saved = dbCacheService.saveAndPostEvent(newCache.toDto()); return CacheApi.fromDto(saved); - } catch (DuplicateKeyException e) { - throw new BadRequestException(e.getMessage()); + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + throw new BadRequestException(e.getMessage()); + } + throw e; } } diff --git a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java index ab89b697e2c3..48aa7276b71e 100644 --- a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java @@ -24,11 +24,14 @@ import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObjectBuilder; import com.mongodb.DBObject; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; import org.apache.commons.lang3.StringUtils; import org.bson.types.ObjectId; import org.graylog2.database.MongoConnection; import org.graylog2.database.PersistedServiceImpl; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.plugin.Tools; import org.graylog2.plugin.database.ValidationException; import org.joda.time.DateTime; @@ -36,10 +39,6 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nullable; - -import jakarta.inject.Inject; -import jakarta.inject.Singleton; - import java.math.BigInteger; import java.security.SecureRandom; import java.util.HashMap; @@ -135,7 +134,11 @@ public AccessToken create(String username, String name) { accessToken = new AccessTokenImpl(fields); try { id = saveWithoutValidation(encrypt(accessToken)); - } catch (DuplicateKeyException ignore) { + } catch (MongoException e) { + // ignore duplicate key errors + if (!MongoUtils.isDuplicateKeyError(e)) { + throw e; + } } } while (iterations++ < 10 && id == null); if (id == null) { diff --git a/graylog2-server/src/main/java/org/graylog2/security/MongoDbSessionDAO.java b/graylog2-server/src/main/java/org/graylog2/security/MongoDbSessionDAO.java index b56e113b9ff8..b950ebde16aa 100644 --- a/graylog2-server/src/main/java/org/graylog2/security/MongoDbSessionDAO.java +++ b/graylog2-server/src/main/java/org/graylog2/security/MongoDbSessionDAO.java @@ -25,15 +25,15 @@ import com.google.common.collect.Maps; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; +import jakarta.inject.Inject; import org.apache.shiro.session.Session; import org.apache.shiro.session.mgt.SimpleSession; import org.apache.shiro.session.mgt.eis.CachingSessionDAO; +import org.graylog2.database.utils.MongoUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jakarta.inject.Inject; - import java.io.Serializable; import java.util.Collection; import java.util.List; @@ -120,7 +120,7 @@ protected void doUpdate(Session session) { // We need to retry the update, and stagger them a bit, so no all of the retries attempt it at the same time again. // Usually this should succeed the first time, though final Retryer retryer = RetryerBuilder.newBuilder() - .retryIfExceptionOfType(DuplicateKeyException.class) + .retryIfException(e -> e instanceof MongoException me && MongoUtils.isDuplicateKeyError(me)) .withWaitStrategy(WaitStrategies.randomWait(5, TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(10)) .build(); diff --git a/graylog2-server/src/main/java/org/graylog2/streams/OutputServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/streams/OutputServiceImpl.java index 04d9ae5e2504..0c630fa8f1a9 100644 --- a/graylog2-server/src/main/java/org/graylog2/streams/OutputServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/streams/OutputServiceImpl.java @@ -17,54 +17,55 @@ package org.graylog2.streams; import com.google.common.collect.ImmutableSet; -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.FindOneAndUpdateOptions; +import com.mongodb.client.model.Projections; +import com.mongodb.client.model.ReplaceOptions; +import com.mongodb.client.model.ReturnDocument; +import com.mongodb.client.model.Updates; +import jakarta.inject.Inject; +import org.bson.Document; +import org.bson.conversions.Bson; import org.bson.types.ObjectId; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; import org.graylog2.database.DbEntity; -import org.graylog2.database.MongoConnection; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.events.ClusterEventBus; import org.graylog2.outputs.events.OutputChangedEvent; import org.graylog2.plugin.Tools; import org.graylog2.plugin.database.ValidationException; import org.graylog2.plugin.streams.Output; import org.graylog2.rest.models.streams.outputs.requests.CreateOutputRequest; -import org.mongojack.DBQuery; -import org.mongojack.DBUpdate; -import org.mongojack.JacksonDBCollection; -import org.mongojack.WriteResult; - -import jakarta.inject.Inject; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; +import static org.graylog2.database.utils.MongoUtils.idEq; + public class OutputServiceImpl implements OutputService { - private final JacksonDBCollection coll; - private final DBCollection dbCollection; private final StreamService streamService; private final ClusterEventBus clusterEventBus; + private final MongoCollection collection; + private final MongoCollection rawCollection; @Inject - public OutputServiceImpl(MongoConnection mongoConnection, - MongoJackObjectMapperProvider mapperProvider, + public OutputServiceImpl(MongoCollections mongoCollections, StreamService streamService, ClusterEventBus clusterEventBus) { this.streamService = streamService; final String collectionName = OutputImpl.class.getAnnotation(DbEntity.class).collection(); - this.dbCollection = mongoConnection.getDatabase().getCollection(collectionName); - this.coll = JacksonDBCollection.wrap(dbCollection, OutputImpl.class, String.class, mapperProvider.get()); + this.collection = mongoCollections.nonEntityCollection(collectionName, OutputImpl.class); + this.rawCollection = collection.withDocumentClass(Document.class); this.clusterEventBus = clusterEventBus; } @Override public Output load(String streamOutputId) throws NotFoundException { - final Output output = coll.findOneById(streamOutputId); + final Output output = collection.find(idEq(streamOutputId)).first(); if (output == null) { throw new NotFoundException("Couldn't find output with id " + streamOutputId); } @@ -74,25 +75,25 @@ public Output load(String streamOutputId) throws NotFoundException { @Override public Set loadAll() { - try (org.mongojack.DBCursor outputs = coll.find()) { - return ImmutableSet.copyOf((Iterable) outputs); - } + return ImmutableSet.copyOf(collection.find()); } @Override public Set loadByIds(Collection ids) { - final DBQuery.Query query = DBQuery.in(OutputImpl.FIELD_ID, ids); - try (org.mongojack.DBCursor dbCursor = coll.find(query)) { - return ImmutableSet.copyOf((Iterable) dbCursor); - } + return ImmutableSet.copyOf(collection.find(MongoUtils.stringIdsIn(ids))); } @Override - public Output create(Output request) throws ValidationException { - final OutputImpl outputImpl = implOrFail(request); - final WriteResult writeResult = coll.save(outputImpl); - - return writeResult.getSavedObject(); + public Output create(Output output) throws ValidationException { + final OutputImpl outputImpl = implOrFail(output); + if (output.getId() == null) { + final var insertedId = MongoUtils.insertedIdAsString(collection.insertOne(outputImpl)); + return OutputImpl.create(insertedId, outputImpl.getTitle(), outputImpl.getType(), + outputImpl.getCreatorUserId(), outputImpl.getConfiguration(), outputImpl.getCreatedAt(), + outputImpl.getContentPack()); + } + collection.replaceOne(idEq(outputImpl.getId()), outputImpl, new ReplaceOptions().upsert(true)); + return outputImpl; } @Override @@ -103,7 +104,7 @@ public Output create(CreateOutputRequest request, String userId) throws Validati @Override public void destroy(Output model) throws NotFoundException { - coll.removeById(model.getId()); + collection.deleteOne(idEq(model.getId())); // Removing the output from all streams will emit a StreamsChangedEvent for affected streams. // The OutputRegistry will handle this event and stop the output. @@ -112,37 +113,39 @@ public void destroy(Output model) throws NotFoundException { @Override public Output update(String id, Map deltas) { - DBUpdate.Builder update = new DBUpdate.Builder(); - for (Map.Entry fields : deltas.entrySet()) { - update = update.set(fields.getKey(), fields.getValue()); - } + final List updates = deltas.entrySet().stream() + .map(field -> Updates.set(field.getKey(), field.getValue())) + .toList(); - final OutputImpl updatedOutput = - coll.findAndModify(DBQuery.is(OutputImpl.FIELD_ID, id), null, null, false, update, true, false); + final OutputImpl updatedOutput = collection.findOneAndUpdate(idEq(id), Updates.combine(updates), + new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)); - this.clusterEventBus.post(OutputChangedEvent.create(updatedOutput.getId())); + if (updatedOutput != null) { + this.clusterEventBus.post(OutputChangedEvent.create(updatedOutput.getId())); + } return updatedOutput; } @Override public long count() { - return coll.count(); + return collection.countDocuments(); } @Override public Map countByType() { final Map outputsCountByType = new HashMap<>(); - try (DBCursor outputTypes = dbCollection.find(null, new BasicDBObject(OutputImpl.FIELD_TYPE, 1))) { + try (final var stream = MongoUtils.stream(rawCollection.find() + .projection(Projections.include(OutputImpl.FIELD_TYPE)))) { - for (DBObject outputType : outputTypes) { + stream.forEach(outputType -> { final String type = (String) outputType.get(OutputImpl.FIELD_TYPE); if (type != null) { final Long oldValue = outputsCountByType.get(type); final Long newValue = (oldValue == null) ? 1 : oldValue + 1; outputsCountByType.put(type, newValue); } - } + }); } return outputsCountByType; diff --git a/graylog2-server/src/main/java/org/graylog2/system/processing/DBProcessingStatusService.java b/graylog2-server/src/main/java/org/graylog2/system/processing/DBProcessingStatusService.java index 552a0b84aff4..b61e8da73ec4 100644 --- a/graylog2-server/src/main/java/org/graylog2/system/processing/DBProcessingStatusService.java +++ b/graylog2-server/src/main/java/org/graylog2/system/processing/DBProcessingStatusService.java @@ -19,27 +19,31 @@ import com.github.joschi.jadconfig.util.Duration; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; -import com.mongodb.BasicDBObject; import com.mongodb.MongoException; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.FindOneAndReplaceOptions; +import com.mongodb.client.model.IndexOptions; +import com.mongodb.client.model.Indexes; +import com.mongodb.client.model.ReturnDocument; +import com.mongodb.client.model.Sorts; import jakarta.inject.Inject; import jakarta.inject.Named; -import org.bson.types.ObjectId; +import org.bson.conversions.Bson; import org.graylog.scheduler.clock.JobSchedulerClock; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.graylog2.database.MongoConnection; +import org.graylog2.database.MongoCollections; import org.graylog2.plugin.BaseConfiguration; import org.graylog2.plugin.indexer.searches.timeranges.TimeRange; import org.graylog2.plugin.system.NodeId; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.mongojack.DBCursor; -import org.mongojack.DBQuery; -import org.mongojack.DBSort; -import org.mongojack.JacksonDBCollection; +import java.util.ArrayList; import java.util.List; import java.util.Optional; +import static com.mongodb.client.model.Filters.eq; +import static com.mongodb.client.model.Indexes.ascending; import static org.graylog2.system.processing.ProcessingStatusDto.FIELD_UPDATED_AT; /** @@ -53,27 +57,23 @@ public class DBProcessingStatusService { private final String nodeId; private final JobSchedulerClock clock; private final Duration updateThreshold; - private final JacksonDBCollection db; private final BaseConfiguration baseConfiguration; + private final MongoCollection collection; @Inject - public DBProcessingStatusService(MongoConnection mongoConnection, + public DBProcessingStatusService(MongoCollections mongoCollections, NodeId nodeId, JobSchedulerClock clock, @Named(ProcessingStatusConfig.UPDATE_THRESHOLD) Duration updateThreshold, @Named(ProcessingStatusConfig.JOURNAL_WRITE_RATE_THRESHOLD) int journalWriteRateThreshold, - MongoJackObjectMapperProvider mapper, BaseConfiguration baseConfiguration) { this.nodeId = nodeId.getNodeId(); this.clock = clock; this.updateThreshold = updateThreshold; this.baseConfiguration = baseConfiguration; - this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection(COLLECTION_NAME), - ProcessingStatusDto.class, - ObjectId.class, - mapper.get()); + this.collection = mongoCollections.collection(COLLECTION_NAME, ProcessingStatusDto.class); - db.createIndex(new BasicDBObject(ProcessingStatusDto.FIELD_NODE_ID, 1), new BasicDBObject("unique", true)); + collection.createIndex(ascending(ProcessingStatusDto.FIELD_NODE_ID), new IndexOptions().unique(true)); // Remove the old (3.1.0) index before creating the new one. This is needed, because mongodb >= 4.2 won't allow // the creation of identical indices with a different name. We don't use a migration, @@ -81,8 +81,8 @@ public DBProcessingStatusService(MongoConnection mongoConnection, // TODO remove this in a future release (maybe at 3.5) final String OLD_INDEX_NAME = "updated_at_1_input_journal.uncommitted_entries_1_input_journal.written_messages_1m_rate_1"; try { - if (db.getIndexInfo().stream().anyMatch(dbo -> dbo.get("name").equals(OLD_INDEX_NAME))) { - db.dropIndex(OLD_INDEX_NAME); + if (collection.listIndexes().into(new ArrayList<>()).stream().anyMatch(dbo -> dbo.get("name").equals(OLD_INDEX_NAME))) { + collection.dropIndex(OLD_INDEX_NAME); } } catch (MongoException ignored) { // index was either never created or already deleted @@ -91,18 +91,22 @@ public DBProcessingStatusService(MongoConnection mongoConnection, // Use a custom index name to avoid the automatically generated index name which will be pretty long and // might cause errors due to the 127 character index name limit. (e.g. when using a long database name) // See: https://github.com/Graylog2/graylog2-server/issues/6322 - db.createIndex(new BasicDBObject(FIELD_UPDATED_AT, 1) - .append(FIELD_UNCOMMITTED_ENTRIES, 1) - .append(FIELD_WRITTEN_MESSAGES_1M, 1), new BasicDBObject("name", "compound_0")); + collection.createIndex( + Indexes.compoundIndex( + ascending(FIELD_UPDATED_AT), + ascending(FIELD_UNCOMMITTED_ENTRIES), + ascending(FIELD_WRITTEN_MESSAGES_1M)), + new IndexOptions().name("compound_0") + ); } /** - * Rerturns all existing processing status entries from the database. + * Returns all existing processing status entries from the database. * * @return a list of all processing status entries */ public List all() { - return ImmutableList.copyOf(db.find().sort(DBSort.asc("_id")).iterator()); + return ImmutableList.copyOf(collection.find().sort(Sorts.ascending("_id"))); } /** @@ -111,7 +115,7 @@ public List all() { * @return the processing status entry or an empty optional if none exists */ public Optional get() { - return Optional.ofNullable(db.findOne(DBQuery.is(ProcessingStatusDto.FIELD_NODE_ID, nodeId))); + return Optional.ofNullable(collection.find(eq(ProcessingStatusDto.FIELD_NODE_ID, nodeId)).first()); } /** @@ -130,14 +134,10 @@ ProcessingStatusDto save(ProcessingStatusRecorder processingStatusRecorder, Date // TODO: Using a timestamp provided by the node for "updated_at" can be bad if the node clock is skewed. // Ideally we would use MongoDB's "$currentDate" but there doesn't seem to be a way to use that // with mongojack. - return db.findAndModify( - DBQuery.is(ProcessingStatusDto.FIELD_NODE_ID, nodeId), - null, - null, - false, + return collection.findOneAndReplace( + eq(ProcessingStatusDto.FIELD_NODE_ID, nodeId), ProcessingStatusDto.of(nodeId, processingStatusRecorder, updatedAt, baseConfiguration.isMessageJournalEnabled()), - true, // We want to return the updated document to the caller - true); + new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER).upsert(true)); } /** @@ -152,7 +152,7 @@ ProcessingStatusDto save(ProcessingStatusRecorder processingStatusRecorder, Date public ProcessingNodesState calculateProcessingState(TimeRange timeRange) { final DateTime updateThresholdTimestamp = clock.nowUTC().minus(updateThreshold.toMilliseconds()); - try (DBCursor statusCursor = db.find(activeNodes(updateThresholdTimestamp))) { + try (final var statusCursor = collection.find(activeNodes(updateThresholdTimestamp)).iterator()) { if (!statusCursor.hasNext()) { return ProcessingNodesState.NONE_ACTIVE; } @@ -188,8 +188,8 @@ private boolean isBusy(ProcessingStatusDto nodeProcessingStatus) { return nodeProcessingStatus.inputJournal().uncommittedEntries() > 0L || nodeProcessingStatus.processBufferUsage() > 0; } - private DBQuery.Query activeNodes(DateTime updateThresholdTimestamp) { - return DBQuery.greaterThan(FIELD_UPDATED_AT, updateThresholdTimestamp); + private Bson activeNodes(DateTime updateThresholdTimestamp) { + return Filters.gt(FIELD_UPDATED_AT, updateThresholdTimestamp); } public enum ProcessingNodesState { diff --git a/graylog2-server/src/main/java/org/graylog2/system/processing/ProcessingStatusDto.java b/graylog2-server/src/main/java/org/graylog2/system/processing/ProcessingStatusDto.java index fe3d5b6a103d..3fb1afeffe0f 100644 --- a/graylog2-server/src/main/java/org/graylog2/system/processing/ProcessingStatusDto.java +++ b/graylog2-server/src/main/java/org/graylog2/system/processing/ProcessingStatusDto.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.auto.value.AutoValue; +import org.graylog2.database.MongoEntity; import org.graylog2.plugin.lifecycles.Lifecycle; import org.joda.time.DateTime; import org.mongojack.Id; @@ -29,7 +30,7 @@ @AutoValue @JsonDeserialize(builder = ProcessingStatusDto.Builder.class) -public abstract class ProcessingStatusDto { +public abstract class ProcessingStatusDto implements MongoEntity { private static final String FIELD_ID = "id"; static final String FIELD_NODE_ID = "node_id"; static final String FIELD_NODE_LIFECYCLE_STATUS = "node_lifecycle_status"; diff --git a/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/DBTelemetryUserSettingsService.java b/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/DBTelemetryUserSettingsService.java index 504fc7d7a8c1..0c5e50170b44 100644 --- a/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/DBTelemetryUserSettingsService.java +++ b/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/DBTelemetryUserSettingsService.java @@ -16,13 +16,11 @@ */ package org.graylog2.telemetry.user.db; -import org.bson.types.ObjectId; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.graylog2.database.MongoConnection; -import org.mongojack.DBQuery; -import org.mongojack.JacksonDBCollection; - +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Filters; import jakarta.inject.Inject; +import org.graylog2.database.MongoCollections; +import org.graylog2.database.utils.MongoUtils; import java.util.Optional; @@ -32,26 +30,24 @@ public class DBTelemetryUserSettingsService { public static final String COLLECTION_NAME = "telemetry_user_settings"; - private final JacksonDBCollection db; + private final MongoCollection collection; + private final MongoUtils mongoUtils; @Inject - public DBTelemetryUserSettingsService(MongoConnection mongoConnection, - MongoJackObjectMapperProvider mapper) { - this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection(COLLECTION_NAME), - TelemetryUserSettingsDto.class, - ObjectId.class, - mapper.get()); + public DBTelemetryUserSettingsService(MongoCollections mongoCollections) { + collection = mongoCollections.collection(COLLECTION_NAME, TelemetryUserSettingsDto.class); + mongoUtils = mongoCollections.utils(collection); } public Optional findByUserId(String userId) { - return Optional.ofNullable(db.findOne(DBQuery.is(FIELD_USER_ID, userId))); + return Optional.ofNullable(collection.find(Filters.eq(FIELD_USER_ID, userId)).first()); } public void save(TelemetryUserSettingsDto dto) { - db.save(dto); + mongoUtils.save(dto); } public void delete(String userId) { - db.remove(DBQuery.is(FIELD_USER_ID, userId)); + collection.deleteMany(Filters.eq(FIELD_USER_ID, userId)); } } diff --git a/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/TelemetryUserSettingsDto.java b/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/TelemetryUserSettingsDto.java index 5ac8714bead3..ab33fb23c8b8 100644 --- a/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/TelemetryUserSettingsDto.java +++ b/graylog2-server/src/main/java/org/graylog2/telemetry/user/db/TelemetryUserSettingsDto.java @@ -19,13 +19,15 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import org.graylog2.database.BuildableMongoEntity; import org.mongojack.Id; import org.mongojack.ObjectId; import javax.annotation.Nullable; @AutoValue -public abstract class TelemetryUserSettingsDto { +public abstract class TelemetryUserSettingsDto + implements BuildableMongoEntity { public static final String FIELD_USER_ID = "user_id"; @@ -62,7 +64,7 @@ public static TelemetryUserSettingsDto create(@JsonProperty("id") @Id @ObjectId public abstract Boolean telemetryPermissionAsked(); @AutoValue.Builder - public abstract static class Builder { + public abstract static class Builder implements BuildableMongoEntity.Builder { public abstract Builder id(String id); diff --git a/graylog2-server/src/main/java/org/graylog2/users/RoleServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/users/RoleServiceImpl.java index 733b07f0f3d3..36e0a4b32c12 100644 --- a/graylog2-server/src/main/java/org/graylog2/users/RoleServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/users/RoleServiceImpl.java @@ -16,38 +16,40 @@ */ package org.graylog2.users; -import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.mongodb.BasicDBObject; -import com.mongodb.DuplicateKeyException; +import com.google.common.primitives.Ints; +import com.mongodb.MongoException; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.FindOneAndReplaceOptions; +import com.mongodb.client.model.IndexOptions; +import com.mongodb.client.model.Indexes; +import com.mongodb.client.model.ReturnDocument; import jakarta.inject.Inject; import jakarta.validation.ConstraintViolation; import jakarta.validation.Validator; -import org.bson.types.ObjectId; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.graylog2.database.MongoConnection; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.plugin.database.ValidationException; import org.graylog2.shared.security.Permissions; import org.graylog2.shared.users.Role; import org.graylog2.shared.users.Roles; -import org.mongojack.DBCursor; -import org.mongojack.DBQuery; -import org.mongojack.JacksonDBCollection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; -import static org.mongojack.DBQuery.and; -import static org.mongojack.DBQuery.is; +import static com.mongodb.client.model.Filters.eq; public class RoleServiceImpl implements RoleService { private static final Logger log = LoggerFactory.getLogger(RoleServiceImpl.class); @@ -60,25 +62,20 @@ public class RoleServiceImpl implements RoleService { public static final String ADMIN_ROLENAME = "Admin"; private static final String READER_ROLENAME = "Reader"; - private final JacksonDBCollection dbCollection; private final Validator validator; private final String adminRoleObjectId; private final String readerRoleObjectId; + private final MongoCollection collection; @Inject - public RoleServiceImpl(MongoConnection mongoConnection, - MongoJackObjectMapperProvider mapper, + public RoleServiceImpl(MongoCollections mongoCollections, Permissions permissions, Validator validator) { this.validator = validator; - dbCollection = JacksonDBCollection.wrap( - mongoConnection.getDatabase().getCollection(ROLES_COLLECTION_NAME), - RoleImpl.class, - ObjectId.class, - mapper.get()); + collection = mongoCollections.nonEntityCollection(ROLES_COLLECTION_NAME, RoleImpl.class); // lower case role names are unique, this allows arbitrary naming, but still uses an index - dbCollection.createIndex(new BasicDBObject(NAME_LOWER, 1), new BasicDBObject("unique", true)); + collection.createIndex(Indexes.ascending(NAME_LOWER), new IndexOptions().unique(true)); // make sure the two built-in roles actually exist adminRoleObjectId = checkNotNull(ensureBuiltinRole(ADMIN_ROLENAME, Sets.newHashSet("*"), "Admin", @@ -115,7 +112,13 @@ private String ensureBuiltinRole(String roleName, try { final RoleImpl savedRole = save(fixedAdmin); return savedRole.getId(); - } catch (DuplicateKeyException | ValidationException e) { + } catch (MongoException e) { + if (MongoUtils.isDuplicateKeyError(e)) { + log.error("Unable to save fixed " + roleName + " role, please restart Graylog to fix this.", e); + } else { + throw e; + } + } catch (ValidationException e) { log.error("Unable to save fixed " + roleName + " role, please restart Graylog to fix this.", e); } } @@ -130,7 +133,7 @@ private String ensureBuiltinRole(String roleName, @Override public Role loadById(String roleId) throws NotFoundException { - final Role role = dbCollection.findOneById(new ObjectId(roleId)); + final Role role = collection.find(MongoUtils.idEq(roleId)).first(); if (role == null) { throw new NotFoundException("No role found with id " + roleId); } @@ -139,7 +142,7 @@ public Role loadById(String roleId) throws NotFoundException { @Override public RoleImpl load(String roleName) throws NotFoundException { - final RoleImpl role = dbCollection.findOne(is(NAME_LOWER, roleName.toLowerCase(Locale.ENGLISH))); + final RoleImpl role = collection.find(eq(NAME_LOWER, roleName.toLowerCase(Locale.ENGLISH))).first(); if (role == null) { throw new NotFoundException("No role found with name " + roleName); @@ -149,45 +152,28 @@ public RoleImpl load(String roleName) throws NotFoundException { @Override public boolean exists(String roleName) { - return dbCollection.getCount(is(NAME_LOWER, roleName.toLowerCase(Locale.ENGLISH))) == 1; + return collection.countDocuments(eq(NAME_LOWER, roleName.toLowerCase(Locale.ENGLISH))) == 1; } @Override public Set loadAll() { - try (DBCursor rolesCursor = dbCollection.find()) { - return ImmutableSet.copyOf((Iterable) rolesCursor); - } + return ImmutableSet.copyOf(collection.find()); } @Override - public Map findIdMap(Set roleIds) throws NotFoundException { - final DBQuery.Query query = DBQuery.in(ID, roleIds); - try (DBCursor rolesCursor = dbCollection.find(query)) { - ImmutableSet roles = ImmutableSet.copyOf((Iterable) rolesCursor); - return Maps.uniqueIndex(roles, new Function() { - @Nullable - @Override - public String apply(Role input) { - return input.getId(); - } - }); - } + public Map findIdMap(Set roleIds) { + final var query = MongoUtils.stringIdsIn(roleIds); + final List roles = collection.find(query).into(new ArrayList<>()); + return Maps.uniqueIndex(roles, Role::getId); } @Override - public Map loadAllIdMap() throws NotFoundException { - final Set roles = loadAll(); - return Maps.uniqueIndex(roles, new Function() { - @Nullable - @Override - public String apply(Role input) { - return input.getId(); - } - }); + public Map loadAllIdMap() { + return Maps.uniqueIndex(loadAll(), Role::getId); } @Override - public Map loadAllLowercaseNameMap() throws NotFoundException { + public Map loadAllLowercaseNameMap() { final Set roles = loadAll(); return Maps.uniqueIndex(roles, Roles.roleToNameFunction(true)); } @@ -195,15 +181,15 @@ public Map loadAllLowercaseNameMap() throws NotFoundException { @Override public RoleImpl save(Role role1) throws ValidationException { // sucky but necessary because of graylog2-shared not knowing about mongodb :( - if (!(role1 instanceof RoleImpl)) { + if (!(role1 instanceof final RoleImpl role)) { throw new IllegalArgumentException("invalid Role implementation class"); } - RoleImpl role = (RoleImpl) role1; final Set> violations = validate(role); if (!violations.isEmpty()) { throw new ValidationException("Validation failed.", violations.toString()); } - return dbCollection.findAndModify(is(NAME_LOWER, role.nameLower()), null, null, false, role, true, true); + return collection.findOneAndReplace(eq(NAME_LOWER, role.nameLower()), role, + new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER).upsert(true)); } @Override @@ -213,8 +199,10 @@ public Set> validate(Role role) { @Override public int delete(String roleName) { - final DBQuery.Query nameMatchesAndNotReadonly = and(is(READ_ONLY, false), is(NAME_LOWER, roleName.toLowerCase(Locale.ENGLISH))); - return dbCollection.remove(nameMatchesAndNotReadonly).getN(); + final var nameMatchesAndNotReadonly = Filters.and( + eq(READ_ONLY, false), + eq(NAME_LOWER, roleName.toLowerCase(Locale.ENGLISH))); + return Ints.saturatedCast(collection.deleteOne(nameMatchesAndNotReadonly).getDeletedCount()); } @Override diff --git a/graylog2-server/src/test/java/org/graylog/events/event/ESMongoDateTimeDeserializerTest.java b/graylog2-server/src/test/java/org/graylog/events/event/ESMongoDateTimeDeserializerTest.java index ed1c0a436d4a..d73c481fb4f9 100644 --- a/graylog2-server/src/test/java/org/graylog/events/event/ESMongoDateTimeDeserializerTest.java +++ b/graylog2-server/src/test/java/org/graylog/events/event/ESMongoDateTimeDeserializerTest.java @@ -17,12 +17,11 @@ package org.graylog.events.event; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.mongodb.DBCollection; import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import org.graylog2.database.MongoCollections; import org.graylog2.shared.bindings.providers.ObjectMapperProvider; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -30,7 +29,6 @@ import org.junit.Rule; import org.junit.Test; import org.mongojack.Id; -import org.mongojack.JacksonDBCollection; import org.mongojack.ObjectId; import static org.assertj.core.api.Assertions.assertThat; @@ -39,34 +37,34 @@ public class ESMongoDateTimeDeserializerTest { @Rule public final MongoDBInstance mongodb = MongoDBInstance.createForClass(); - private ObjectMapper objectMapper; + private MongoJackObjectMapperProvider mapperProvider; @Before public void setUp() throws Exception { - objectMapper = new MongoJackObjectMapperProvider(new ObjectMapperProvider().get()).get(); + mapperProvider = new MongoJackObjectMapperProvider(new ObjectMapperProvider().get()); } @Test public void deserializeDateTime() throws Exception { final String json = "{\"date_time\":\"2016-12-13 14:00:00.000\"}"; - final DTO value = objectMapper.readValue(json, DTO.class); + final DTO value = mapperProvider.get().readValue(json, DTO.class); assertThat(value.dateTime).isEqualTo(new DateTime(2016, 12, 13, 14, 0, DateTimeZone.UTC)); } @Test public void deserializeIsoDateTime() throws Exception { final String json = "{\"date_time\":\"2016-12-13T14:00:00.000\"}"; - final DTO value = objectMapper.readValue(json, DTO.class); + final DTO value = mapperProvider.get().readValue(json, DTO.class); assertThat(value.dateTime).isEqualTo(new DateTime(2016, 12, 13, 14, 0, DateTimeZone.UTC)); } @Test @MongoDBFixtures("DateTime.json") - public void deserializeMongoDateTime() throws Exception { - final DBCollection date_collection = mongodb.mongoConnection().getDatabase().getCollection("date_collection"); - final JacksonDBCollection db = JacksonDBCollection.wrap(date_collection, DTO.class, ObjectId.class, objectMapper); + public void deserializeMongoDateTime() { + final var db = new MongoCollections(mapperProvider, mongodb.mongoConnection()).nonEntityCollection("date_collection", DTO.class); - final DTO value = db.findOne(); + final DTO value = db.find().first(); + assertThat(value).isNotNull(); assertThat(value.dateTime).isEqualTo(new DateTime(2019, 1, 13, 14, 0, DateTimeZone.UTC)); } diff --git a/graylog2-server/src/test/java/org/graylog2/contentpacks/facades/OutputFacadeTest.java b/graylog2-server/src/test/java/org/graylog2/contentpacks/facades/OutputFacadeTest.java index c8d6e4c2aee2..6dafc29d4ff9 100644 --- a/graylog2-server/src/test/java/org/graylog2/contentpacks/facades/OutputFacadeTest.java +++ b/graylog2-server/src/test/java/org/graylog2/contentpacks/facades/OutputFacadeTest.java @@ -34,6 +34,7 @@ import org.graylog2.contentpacks.model.entities.OutputEntity; import org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils; import org.graylog2.contentpacks.model.entities.references.ValueReference; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; import org.graylog2.events.ClusterEventBus; import org.graylog2.outputs.LoggingOutput; @@ -84,7 +85,10 @@ public class OutputFacadeTest { @Before public void setUp() throws Exception { - outputService = new OutputServiceImpl(mongodb.mongoConnection(), new MongoJackObjectMapperProvider(objectMapper), streamService, new ClusterEventBus()); + outputService = new OutputServiceImpl( + new MongoCollections(new MongoJackObjectMapperProvider(objectMapper), mongodb.mongoConnection()), + streamService, + new ClusterEventBus()); pluginMetaData = new HashSet<>(); outputFactories = new HashMap<>(); outputFactories2 = new HashMap<>(); diff --git a/graylog2-server/src/test/java/org/graylog2/contentstream/ContentStreamServiceWithDbTest.java b/graylog2-server/src/test/java/org/graylog2/contentstream/ContentStreamServiceWithDbTest.java index 4ad290d5e34e..ea922fd36cd9 100644 --- a/graylog2-server/src/test/java/org/graylog2/contentstream/ContentStreamServiceWithDbTest.java +++ b/graylog2-server/src/test/java/org/graylog2/contentstream/ContentStreamServiceWithDbTest.java @@ -24,6 +24,7 @@ import org.graylog2.contentstream.db.DBContentStreamUserSettingsService; import org.graylog2.contentstream.rest.ContentStreamService; import org.graylog2.contentstream.rest.ContentStreamSettings; +import org.graylog2.database.MongoCollections; import org.graylog2.plugin.database.users.User; import org.graylog2.shared.users.UserService; import org.junit.Before; @@ -63,7 +64,8 @@ public class ContentStreamServiceWithDbTest { public void setUp() { MongoJackObjectMapperProvider mongoJackObjectMapperProvider = new MongoJackObjectMapperProvider(new ObjectMapper()); contentStreamService = new ContentStreamService( - new DBContentStreamUserSettingsService(mongodb.mongoConnection(), mongoJackObjectMapperProvider), + new DBContentStreamUserSettingsService( + new MongoCollections(mongoJackObjectMapperProvider, mongodb.mongoConnection())), contentStreamFeedTags, eventBus ); diff --git a/graylog2-server/src/test/java/org/graylog2/database/utils/MongoUtilsTest.java b/graylog2-server/src/test/java/org/graylog2/database/utils/MongoUtilsTest.java index 21adb69c7117..e5fc2912194a 100644 --- a/graylog2-server/src/test/java/org/graylog2/database/utils/MongoUtilsTest.java +++ b/graylog2-server/src/test/java/org/graylog2/database/utils/MongoUtilsTest.java @@ -20,8 +20,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.auto.value.AutoValue; +import com.mongodb.BasicDBObject; +import com.mongodb.DBCollection; import com.mongodb.DuplicateKeyException; import com.mongodb.MongoClientException; +import com.mongodb.MongoException; import com.mongodb.MongoWriteException; import com.mongodb.ServerAddress; import com.mongodb.WriteConcernResult; @@ -45,6 +48,7 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @@ -218,6 +222,26 @@ void testIsDuplicateKeyError() { assertThat(MongoUtils.isDuplicateKeyError(legacyDupKeyException)).isTrue(); } + @Test + void testReproduceDuplicateKeyError(MongoDBTestService mongoDBTestService, MongoJackObjectMapperProvider objectMapperProvider) { + final DBCollection legacyCollection = mongoDBTestService.mongoConnection().getDatabase() + .getCollection("test"); + + final var dto = new DTO(new ObjectId().toHexString(), "test"); + final var document = new BasicDBObject(Map.of("_id", new ObjectId(dto.id()), "name", "test")); + + collection.insertOne(dto); + + assertThatThrownBy(() -> collection.insertOne(dto)) + .isInstanceOfSatisfying(MongoException.class, e -> + assertThat(MongoUtils.isDuplicateKeyError(e)).isTrue()); + + assertThatThrownBy(() -> legacyCollection.insert(document)) + .isInstanceOf(DuplicateKeyException.class) + .isInstanceOfSatisfying(MongoException.class, e -> + assertThat(MongoUtils.isDuplicateKeyError(e)).isTrue()); + } + @AutoValue @JsonDeserialize(builder = AutoValueDTO.Builder.class) public static abstract class AutoValueDTO implements BuildableMongoEntity { diff --git a/graylog2-server/src/test/java/org/graylog2/decorators/DecoratorServiceImplTest.java b/graylog2-server/src/test/java/org/graylog2/decorators/DecoratorServiceImplTest.java index dc0cfff92aec..8e585a0bc11c 100644 --- a/graylog2-server/src/test/java/org/graylog2/decorators/DecoratorServiceImplTest.java +++ b/graylog2-server/src/test/java/org/graylog2/decorators/DecoratorServiceImplTest.java @@ -19,6 +19,7 @@ import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; import org.graylog2.shared.bindings.providers.ObjectMapperProvider; import org.junit.Before; @@ -42,7 +43,7 @@ public class DecoratorServiceImplTest { public void setUp() { final ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider(); final MongoJackObjectMapperProvider provider = new MongoJackObjectMapperProvider(objectMapperProvider.get()); - decoratorService = new DecoratorServiceImpl(mongodb.mongoConnection(), provider); + decoratorService = new DecoratorServiceImpl(new MongoCollections(provider, mongodb.mongoConnection())); } @Test diff --git a/graylog2-server/src/test/java/org/graylog2/inputs/persistence/MongoInputStatusServiceTest.java b/graylog2-server/src/test/java/org/graylog2/inputs/persistence/MongoInputStatusServiceTest.java index e1fe801d3634..8d60ffca260b 100644 --- a/graylog2-server/src/test/java/org/graylog2/inputs/persistence/MongoInputStatusServiceTest.java +++ b/graylog2-server/src/test/java/org/graylog2/inputs/persistence/MongoInputStatusServiceTest.java @@ -18,10 +18,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.eventbus.EventBus; -import org.bson.types.ObjectId; import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; import org.graylog2.inputs.InputService; import org.graylog2.rest.models.system.inputs.responses.InputDeleted; @@ -32,7 +32,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.mongojack.JacksonDBCollection; import java.util.Optional; @@ -58,19 +57,13 @@ public class MongoInputStatusServiceTest { @Mock private InputService inputService; - private JacksonDBCollection db; - @Before public void setUp() { final ObjectMapper objectMapper = new ObjectMapperProvider().get(); final MongoJackObjectMapperProvider mapperProvider = new MongoJackObjectMapperProvider(objectMapper); - cut = new MongoInputStatusService(mongodb.mongoConnection(), mapperProvider, inputService, mockEventBus); - - db = JacksonDBCollection.wrap(mongodb.mongoConnection().getDatabase().getCollection(MongoInputStatusService.COLLECTION_NAME), - InputStatusRecord.class, - ObjectId.class, - mapperProvider.get()); + cut = new MongoInputStatusService( + new MongoCollections(mapperProvider, mongodb.mongoConnection()), inputService, mockEventBus); } @Test diff --git a/graylog2-server/src/test/java/org/graylog2/migrations/MigrationHelpersTest.java b/graylog2-server/src/test/java/org/graylog2/migrations/MigrationHelpersTest.java index bca9b168e408..057b42c2a475 100644 --- a/graylog2-server/src/test/java/org/graylog2/migrations/MigrationHelpersTest.java +++ b/graylog2-server/src/test/java/org/graylog2/migrations/MigrationHelpersTest.java @@ -18,7 +18,10 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoWriteException; +import com.mongodb.ServerAddress; +import com.mongodb.WriteError; +import org.bson.BsonDocument; import org.graylog.testing.TestUserService; import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; @@ -176,7 +179,10 @@ public void ensureBuiltinRoleExists() throws Exception { @Test public void ensureBuiltinRoleWithSaveError() throws Exception { when(roleService.load("test-role")).thenThrow(NotFoundException.class); - when(roleService.save(any(Role.class))).thenThrow(DuplicateKeyException.class); // Throw database error + final var duplicateKeyException = new MongoWriteException( + new WriteError(11000, "", new BsonDocument()), new ServerAddress(), Collections.emptySet() + ); + when(roleService.save(any(Role.class))).thenThrow(duplicateKeyException); assertThat(migrationHelpers.ensureBuiltinRole("test-role", "description", ImmutableSet.of("a", "b"))) .isNull(); diff --git a/graylog2-server/src/test/java/org/graylog2/migrations/V20200803120800_GrantsMigrations/RolesToGrantsMigrationTest.java b/graylog2-server/src/test/java/org/graylog2/migrations/V20200803120800_GrantsMigrations/RolesToGrantsMigrationTest.java index 0b220e22cd1c..a56fee02e8fe 100644 --- a/graylog2-server/src/test/java/org/graylog2/migrations/V20200803120800_GrantsMigrations/RolesToGrantsMigrationTest.java +++ b/graylog2-server/src/test/java/org/graylog2/migrations/V20200803120800_GrantsMigrations/RolesToGrantsMigrationTest.java @@ -81,7 +81,8 @@ void setUp(MongoDBTestService mongodb, this.grnRegistry = grnRegistry; - roleService = new RoleServiceImpl(mongodb.mongoConnection(), mongoJackObjectMapperProvider, permissions, validator); + roleService = new RoleServiceImpl( + new MongoCollections(mongoJackObjectMapperProvider, mongodb.mongoConnection()), permissions, validator); this.dbGrantService = new DBGrantService(new MongoCollections(mongoJackObjectMapperProvider, mongodb.mongoConnection())); this.userService = userService; diff --git a/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/listeners/EntityListPreferencesCleanerOnUserDeletionTest.java b/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/listeners/EntityListPreferencesCleanerOnUserDeletionTest.java index 9e0f337940b5..1609c5c45fe6 100644 --- a/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/listeners/EntityListPreferencesCleanerOnUserDeletionTest.java +++ b/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/listeners/EntityListPreferencesCleanerOnUserDeletionTest.java @@ -22,6 +22,7 @@ import org.graylog.testing.mongodb.MongoDBTestService; import org.graylog.testing.mongodb.MongoJackExtension; import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import org.graylog2.database.MongoCollections; import org.graylog2.rest.resources.entities.preferences.model.EntityListPreferences; import org.graylog2.rest.resources.entities.preferences.model.StoredEntityListPreferences; import org.graylog2.rest.resources.entities.preferences.model.StoredEntityListPreferencesId; @@ -52,7 +53,8 @@ class EntityListPreferencesCleanerOnUserDeletionTest { void setUp(MongoDBTestService mongodb, MongoJackObjectMapperProvider objectMapperProvider) { this.eventBus = new AsyncEventBus(MoreExecutors.directExecutor()); - this.service = Mockito.spy(new EntityListPreferencesServiceImpl(mongodb.mongoConnection(), objectMapperProvider)); + this.service = Mockito.spy(new EntityListPreferencesServiceImpl( + new MongoCollections(objectMapperProvider, mongodb.mongoConnection()))); this.listener = new EntityListPreferencesCleanerOnUserDeletion(eventBus, service); } diff --git a/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImplTest.java b/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImplTest.java index 3bd6dda98209..6189b7d56366 100644 --- a/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImplTest.java +++ b/graylog2-server/src/test/java/org/graylog2/rest/resources/entities/preferences/service/EntityListPreferencesServiceImplTest.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.graylog.testing.mongodb.MongoDBInstance; import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import org.graylog2.database.MongoCollections; import org.graylog2.database.MongoConnection; import org.graylog2.rest.resources.entities.preferences.model.EntityListPreferences; import org.graylog2.rest.resources.entities.preferences.model.SingleFieldSortPreferences; @@ -57,7 +58,7 @@ public class EntityListPreferencesServiceImplTest { public void setUp() { final MongoConnection mongoConnection = mongodb.mongoConnection(); final MongoJackObjectMapperProvider objectMapperProvider = new MongoJackObjectMapperProvider(new ObjectMapper()); - this.toTest = new EntityListPreferencesServiceImpl(mongoConnection, objectMapperProvider); + this.toTest = new EntityListPreferencesServiceImpl(new MongoCollections(objectMapperProvider, mongoConnection)); } @Test diff --git a/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java b/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java index bd94b783c42a..430211aadcba 100644 --- a/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java +++ b/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java @@ -16,7 +16,7 @@ */ package org.graylog2.security; -import com.mongodb.DuplicateKeyException; +import com.mongodb.MongoException; import com.mongodb.client.MongoCollection; import com.mongodb.client.model.Filters; import org.apache.commons.lang3.StringUtils; @@ -24,6 +24,7 @@ import org.bson.types.ObjectId; import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; +import org.graylog2.database.utils.MongoUtils; import org.graylog2.plugin.database.ValidationException; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -36,6 +37,7 @@ import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -196,12 +198,15 @@ public void testSave() throws Exception { assertEquals(token.getToken(), newToken.getToken()); } - @Test(expected = DuplicateKeyException.class) + @Test @MongoDBFixtures("accessTokensSingleToken.json") public void testExceptionForMultipleTokens() throws ValidationException { final AccessToken existingToken = accessTokenService.load("foobar"); final AccessToken newToken = accessTokenService.create("user", "foobar"); newToken.setToken(existingToken.getToken()); - accessTokenService.save(newToken); + assertThatThrownBy(() -> accessTokenService.save(newToken)) + .isInstanceOfSatisfying(MongoException.class, e -> + assertThat(MongoUtils.isDuplicateKeyError(e)).isTrue() + ); } } diff --git a/graylog2-server/src/test/java/org/graylog2/streams/OutputServiceImplTest.java b/graylog2-server/src/test/java/org/graylog2/streams/OutputServiceImplTest.java index 22dcd3aac20a..9e7910b0166b 100644 --- a/graylog2-server/src/test/java/org/graylog2/streams/OutputServiceImplTest.java +++ b/graylog2-server/src/test/java/org/graylog2/streams/OutputServiceImplTest.java @@ -21,6 +21,7 @@ import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import org.graylog2.database.MongoCollections; import org.graylog2.database.NotFoundException; import org.graylog2.events.ClusterEventBus; import org.graylog2.outputs.events.OutputChangedEvent; @@ -59,8 +60,7 @@ public void setUp() throws Exception { final ObjectMapper objectMapper = new ObjectMapperProvider().get(); final MongoJackObjectMapperProvider mapperProvider = new MongoJackObjectMapperProvider(objectMapper); outputService = new OutputServiceImpl( - mongodb.mongoConnection(), - mapperProvider, + new MongoCollections(mapperProvider, mongodb.mongoConnection()), streamService, clusterEventBus); } diff --git a/graylog2-server/src/test/java/org/graylog2/system/processing/DBProcessingStatusServiceTest.java b/graylog2-server/src/test/java/org/graylog2/system/processing/DBProcessingStatusServiceTest.java index 98f5adce04bc..73c1a214684d 100644 --- a/graylog2-server/src/test/java/org/graylog2/system/processing/DBProcessingStatusServiceTest.java +++ b/graylog2-server/src/test/java/org/graylog2/system/processing/DBProcessingStatusServiceTest.java @@ -18,11 +18,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.github.joschi.jadconfig.util.Duration; -import org.bson.types.ObjectId; import org.graylog.events.JobSchedulerTestClock; import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; +import org.graylog2.database.MongoCollections; import org.graylog2.plugin.BaseConfiguration; import org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange; import org.graylog2.plugin.indexer.searches.timeranges.TimeRange; @@ -38,10 +38,8 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.mongojack.JacksonDBCollection; import static org.assertj.core.api.Assertions.assertThat; -import static org.graylog2.system.processing.DBProcessingStatusService.COLLECTION_NAME; import static org.graylog2.system.processing.DBProcessingStatusService.ProcessingNodesState; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -63,7 +61,6 @@ public class DBProcessingStatusServiceTest { private DBProcessingStatusService dbService; private JobSchedulerTestClock clock; private Duration updateThreshold; - private JacksonDBCollection db; @Before public void setUp() throws Exception { @@ -72,11 +69,8 @@ public void setUp() throws Exception { clock = spy(new JobSchedulerTestClock(DateTime.parse("2019-01-01T00:00:00.000Z"))); updateThreshold = spy(Duration.minutes(1)); - dbService = new DBProcessingStatusService(mongodb.mongoConnection(), nodeId, clock, updateThreshold, 1, mapperProvider, baseConfiguration); - db = JacksonDBCollection.wrap(mongodb.mongoConnection().getDatabase().getCollection(COLLECTION_NAME), - ProcessingStatusDto.class, - ObjectId.class, - mapperProvider.get()); + dbService = new DBProcessingStatusService(new MongoCollections(mapperProvider, mongodb.mongoConnection()), + nodeId, clock, updateThreshold, 1, baseConfiguration); } @Test diff --git a/graylog2-server/src/test/java/org/graylog2/telemetry/rest/TelemetryServiceWithDbTest.java b/graylog2-server/src/test/java/org/graylog2/telemetry/rest/TelemetryServiceWithDbTest.java index 7d36edf1700e..b830f2bc2684 100644 --- a/graylog2-server/src/test/java/org/graylog2/telemetry/rest/TelemetryServiceWithDbTest.java +++ b/graylog2-server/src/test/java/org/graylog2/telemetry/rest/TelemetryServiceWithDbTest.java @@ -24,6 +24,7 @@ import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; import org.graylog2.cluster.leader.LeaderElectionService; import org.graylog2.cluster.nodes.NodeService; +import org.graylog2.database.MongoCollections; import org.graylog2.indexer.cluster.ClusterAdapter; import org.graylog2.plugin.PluginMetaData; import org.graylog2.plugin.ServerStatus; @@ -111,7 +112,7 @@ public void setUp() { elasticClusterAdapter, elasticsearchVersion, new TelemetryResponseFactory(new ObjectMapperProvider().get()), - new DBTelemetryUserSettingsService(mongodb.mongoConnection(), mongoJackObjectMapperProvider), + new DBTelemetryUserSettingsService(new MongoCollections(mongoJackObjectMapperProvider, mongodb.mongoConnection())), eventBus, telemetryClusterService, "unknown", From 4179dcb95dbaaf0de52344e8fe27454250aaf836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kami=C5=84ski?= Date: Wed, 29 Jan 2025 14:27:45 +0100 Subject: [PATCH 12/56] =?UTF-8?q?Parameters=20can=20be=20used=20for=20fiel?= =?UTF-8?q?d=20names=20in=20queries,=20not=20warnings=20are=20c=E2=80=A6?= =?UTF-8?q?=20(#21469)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog/unreleased/issue-9368.toml | 5 +++++ .../validation/validators/UnknownFieldsValidator.java | 8 ++++++-- .../validators/UnknownFieldsValidatorTest.java | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/issue-9368.toml diff --git a/changelog/unreleased/issue-9368.toml b/changelog/unreleased/issue-9368.toml new file mode 100644 index 000000000000..65831e14b8a2 --- /dev/null +++ b/changelog/unreleased/issue-9368.toml @@ -0,0 +1,5 @@ +type = "fixed" +message = "Fixed query validation with parameter usage. Parameters representing field names do not cause 'unknown field' warnings anymore." + +issues = ["9368"] +pulls = ["21469"] diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidator.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidator.java index b30637288044..7137d0477edf 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidator.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidator.java @@ -16,6 +16,7 @@ */ package org.graylog.plugins.views.search.validation.validators; +import jakarta.inject.Singleton; import org.graylog.plugins.views.search.engine.QueryPosition; import org.graylog.plugins.views.search.rest.MappedFieldTypeDTO; import org.graylog.plugins.views.search.validation.ParsedTerm; @@ -26,8 +27,6 @@ import org.graylog.plugins.views.search.validation.ValidationType; import org.graylog.plugins.views.search.validation.validators.util.UnknownFieldsListLimiter; -import jakarta.inject.Singleton; - import java.util.List; import java.util.Map; import java.util.Set; @@ -66,6 +65,7 @@ public List validate(final ValidationContext context) { List identifyUnknownFields(final Set availableFields, final List terms) { final Map> groupedByField = terms.stream() .filter(t -> !t.isDefaultField()) + .filter(term -> !isParameter(term.getRealFieldName())) .filter(term -> !SEARCHABLE_ES_FIELDS.contains(term.getRealFieldName())) .filter(term -> !RESERVED_SETTABLE_FIELDS.contains(term.getRealFieldName())) .filter(term -> !availableFields.contains(term.getRealFieldName())) @@ -74,4 +74,8 @@ List identifyUnknownFields(final Set availableFields, final return unknownFieldsListLimiter.filterElementsContainingUsefulInformation(groupedByField); } + + private boolean isParameter(final String term) { + return term.startsWith("$") && term.endsWith("$"); + } } diff --git a/graylog2-server/src/test/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidatorTest.java b/graylog2-server/src/test/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidatorTest.java index fac517243dda..bf54bb7816fe 100644 --- a/graylog2-server/src/test/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidatorTest.java +++ b/graylog2-server/src/test/java/org/graylog/plugins/views/search/validation/validators/UnknownFieldsValidatorTest.java @@ -83,6 +83,16 @@ void testDoesNotIdentifyAvailableFieldAsUnknown() { assertTrue(unknownFields.isEmpty()); } + @Test + void testDoesNotIdentifyParameterFieldAsUnknownField() { + final List unknownFields = toTest.identifyUnknownFields( + Set.of("some_normal_field"), + List.of(ParsedTerm.create("$param_representing_field$", "GET"), //param can be used for field name + ParsedTerm.create("_exists_", "$param_representing_field$")) //...even in exists query + ); + assertTrue(unknownFields.isEmpty()); + } + @Test void testIdentifiesUnknownField() { final ParsedTerm unknownField = ParsedTerm.create("strange_field", "!!!"); From 6ed9c0276326ecd607047fd8dd9533d2cb1a20ed Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:46:00 +0100 Subject: [PATCH 13/56] Updating yarn lockfile (#21479) Co-authored-by: Gary Bot --- graylog2-web-interface/yarn.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/graylog2-web-interface/yarn.lock b/graylog2-web-interface/yarn.lock index 1695e19d1160..8fd1df1e56ce 100644 --- a/graylog2-web-interface/yarn.lock +++ b/graylog2-web-interface/yarn.lock @@ -7444,7 +7444,7 @@ eslint-config-airbnb@19.0.4: eslint-config-airbnb "19.0.4" eslint-import-resolver-webpack "0.13.10" eslint-plugin-compat "4.2.0" - eslint-plugin-graylog "file:../../../../.cache/yarn/v6/npm-eslint-config-graylog-1.3.0-b018d78b-68eb-4ab9-9ab5-603b868f303c-1738066234730/node_modules/eslint-plugin-graylog" + eslint-plugin-graylog "file:../../../../.cache/yarn/v6/npm-eslint-config-graylog-1.3.0-4228572c-36c3-45ec-a426-d6ad9abe0608-1738152635323/node_modules/eslint-plugin-graylog" eslint-plugin-import "2.25.3" eslint-plugin-jest "28.11.0" eslint-plugin-jest-dom "5.5.0" @@ -9008,15 +9008,15 @@ graphemer@^1.4.0: "@tanstack/react-query" "4.36.1" "@types/jquery" "3.5.32" "@types/react" "18.3.13" - babel-preset-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-3f535fa4-a2ab-40bb-a5d5-cab3a6d949aa-1738066234677/node_modules/babel-preset-graylog" - eslint-config-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-3f535fa4-a2ab-40bb-a5d5-cab3a6d949aa-1738066234677/node_modules/eslint-config-graylog" + babel-preset-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-05f95a4e-b158-4fcb-a1d1-2428ffee0811-1738152635034/node_modules/babel-preset-graylog" + eslint-config-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-05f95a4e-b158-4fcb-a1d1-2428ffee0811-1738152635034/node_modules/eslint-config-graylog" formik "2.4.6" history "^5.3.0" html-webpack-plugin "^5.5.0" - jest-preset-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-3f535fa4-a2ab-40bb-a5d5-cab3a6d949aa-1738066234677/node_modules/jest-preset-graylog" + jest-preset-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-05f95a4e-b158-4fcb-a1d1-2428ffee0811-1738152635034/node_modules/jest-preset-graylog" jquery "3.7.1" moment "2.30.1" - moment-timezone "0.5.46" + moment-timezone "0.5.47" prop-types "15.8.1" react "18.3.1" react-dom "18.2.0" @@ -11982,10 +11982,10 @@ moment-precise-range-plugin@^1.3.0: resolved "https://registry.yarnpkg.com/moment-precise-range-plugin/-/moment-precise-range-plugin-1.3.0.tgz#60ac075fdfd14689f6d102af751d171a80b4ab60" integrity sha1-YKwHX9/RRon20QKvdR0XGoC0q2A= -moment-timezone@0.5.46: - version "0.5.46" - resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.46.tgz#a21aa6392b3c6b3ed916cd5e95858a28d893704a" - integrity sha512-ZXm9b36esbe7OmdABqIWJuBBiLLwAjrN7CE+7sYdCCx82Nabt1wHDj8TVseS59QIlfFPbOoiBPm6ca9BioG4hw== +moment-timezone@0.5.47: + version "0.5.47" + resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.47.tgz#d4d1a21b78372d914d6d69ae285454732a429749" + integrity sha512-UbNt/JAWS0m/NJOebR0QMRHBk0hu03r5dx9GK8Cs0AS3I81yDcOc9k+DytPItgVvBP7J6Mf6U2n3BPAacAV9oA== dependencies: moment "^2.29.4" From bb904464f2ca86391153886185aa25e04678e8db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 07:52:14 +0100 Subject: [PATCH 14/56] Bump the mantine group in /graylog2-web-interface with 4 updates (#21481) Bumps the mantine group in /graylog2-web-interface with 4 updates: [@mantine/core](https://github.com/mantinedev/mantine/tree/HEAD/packages/@mantine/core), [@mantine/dropzone](https://github.com/mantinedev/mantine/tree/HEAD/packages/@mantine/dropzone), [@mantine/hooks](https://github.com/mantinedev/mantine/tree/HEAD/packages/@mantine/hooks) and [@mantine/notifications](https://github.com/mantinedev/mantine/tree/HEAD/packages/@mantine/notifications). Updates `@mantine/core` from 7.16.1 to 7.16.2 - [Release notes](https://github.com/mantinedev/mantine/releases) - [Changelog](https://github.com/mantinedev/mantine/blob/master/CHANGELOG.md) - [Commits](https://github.com/mantinedev/mantine/commits/7.16.2/packages/@mantine/core) Updates `@mantine/dropzone` from 7.16.1 to 7.16.2 - [Release notes](https://github.com/mantinedev/mantine/releases) - [Changelog](https://github.com/mantinedev/mantine/blob/master/CHANGELOG.md) - [Commits](https://github.com/mantinedev/mantine/commits/7.16.2/packages/@mantine/dropzone) Updates `@mantine/hooks` from 7.16.1 to 7.16.2 - [Release notes](https://github.com/mantinedev/mantine/releases) - [Changelog](https://github.com/mantinedev/mantine/blob/master/CHANGELOG.md) - [Commits](https://github.com/mantinedev/mantine/commits/7.16.2/packages/@mantine/hooks) Updates `@mantine/notifications` from 7.16.1 to 7.16.2 - [Release notes](https://github.com/mantinedev/mantine/releases) - [Changelog](https://github.com/mantinedev/mantine/blob/master/CHANGELOG.md) - [Commits](https://github.com/mantinedev/mantine/commits/7.16.2/packages/@mantine/notifications) --- updated-dependencies: - dependency-name: "@mantine/core" dependency-type: direct:production update-type: version-update:semver-patch dependency-group: mantine - dependency-name: "@mantine/dropzone" dependency-type: direct:production update-type: version-update:semver-patch dependency-group: mantine - dependency-name: "@mantine/hooks" dependency-type: direct:production update-type: version-update:semver-patch dependency-group: mantine - dependency-name: "@mantine/notifications" dependency-type: direct:production update-type: version-update:semver-patch dependency-group: mantine ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- graylog2-web-interface/yarn.lock | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/graylog2-web-interface/yarn.lock b/graylog2-web-interface/yarn.lock index 8fd1df1e56ce..6f52fe23d1d9 100644 --- a/graylog2-web-interface/yarn.lock +++ b/graylog2-web-interface/yarn.lock @@ -2423,9 +2423,9 @@ integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== "@mantine/core@^7.13.5": - version "7.16.1" - resolved "https://registry.yarnpkg.com/@mantine/core/-/core-7.16.1.tgz#be9cb3f3288246664804c625f2340b6dbeed2548" - integrity sha512-HYdjCeMU3dUJbc1CrAAedeAASTG5kVyL/qsiuYh5b7BoG0qsRtK8WJxBpUjW6VqtJpUaE94c5tlBJ8MgAmPHTQ== + version "7.16.2" + resolved "https://registry.yarnpkg.com/@mantine/core/-/core-7.16.2.tgz#feffc178adfdae0b073c24fd758a7793d0cf95e3" + integrity sha512-6dwFz+8HrOqFan7GezgpoWyZSCxedh10S8iILGVsc3GXiD4gzo+3VZndZKccktkYZ3GVC9E3cCS3SxbiyKSAVw== dependencies: "@floating-ui/react" "^0.26.28" clsx "^2.1.1" @@ -2435,29 +2435,29 @@ type-fest "^4.27.0" "@mantine/dropzone@^7.13.5": - version "7.16.1" - resolved "https://registry.yarnpkg.com/@mantine/dropzone/-/dropzone-7.16.1.tgz#de0fb7b56513b37a63241533cd9766ba465aab4a" - integrity sha512-5lQsy2JScvaWq87fOrD2QNvlVzCErQE9nzjNdADAH9u/34fLIgGE0v5MBbVdVPI+wYxrPAwW4hahEKSa5LelXA== + version "7.16.2" + resolved "https://registry.yarnpkg.com/@mantine/dropzone/-/dropzone-7.16.2.tgz#0d8a5586a6711c5ef5f0be13343bca793199c746" + integrity sha512-iRZJI/zzRrsSES+dVdqHInXnuxHQ6a7YPBwIP1Td9pBdaVHqF6Nvd/I2OVQSYhseYTxFT5ythdw32wFeCgpRSg== dependencies: react-dropzone-esm "15.2.0" "@mantine/hooks@^7.13.5": - version "7.16.1" - resolved "https://registry.yarnpkg.com/@mantine/hooks/-/hooks-7.16.1.tgz#3956b277ac19e456a42f8dceea4933ac4a8d7cb9" - integrity sha512-+hER8E4d2ByfQ/DKIXGM3Euxb7IH5ArSjzzzoF21sG095iXIryOCob22ZanrmiXCoAzKKdxqgVj4Di67ikLYSQ== + version "7.16.2" + resolved "https://registry.yarnpkg.com/@mantine/hooks/-/hooks-7.16.2.tgz#24163bcb7b7f862bdd984e26180dbda12bae1588" + integrity sha512-ZFHQhDi9T+r6VR5NEeE47gigPPIAHVIKDOCWsCsbCqHc3yz5l8kiO2RdfUmsTKV2KD/AiXnAw4b6pjQEP58GOg== "@mantine/notifications@^7.13.5": - version "7.16.1" - resolved "https://registry.yarnpkg.com/@mantine/notifications/-/notifications-7.16.1.tgz#042e2f97f9ab9da7046a3488f18045ee05e2adcb" - integrity sha512-kCYbuanL+y/VZ0UqgE0fpQcpTznWHwLEOw4waMXHyig6z4AEEB45U3iFpBtuSXpuFjfqH0corMaaWkAVocwj2Q== + version "7.16.2" + resolved "https://registry.yarnpkg.com/@mantine/notifications/-/notifications-7.16.2.tgz#b565000043bd7503280926744ba487103403ef20" + integrity sha512-U342XWiiRI1NvOlLsI6PH/pSNe0rxNClJ2w5orvjOMXvaAfDe52mhnzRmtzRxYENp06++3b/G7MjPH+466rF9Q== dependencies: - "@mantine/store" "7.16.1" + "@mantine/store" "7.16.2" react-transition-group "4.4.5" -"@mantine/store@7.16.1": - version "7.16.1" - resolved "https://registry.yarnpkg.com/@mantine/store/-/store-7.16.1.tgz#5bfac11854a26a1c7565fef9450b178327617a38" - integrity sha512-EZjNzsLPWXB5MgBDa5FUEg5vbN+uo3hctSgplC7kkimjW7K3qfMiszwTt8cQgb7RRn7xH5sfC3U0Cm8X9h4kmA== +"@mantine/store@7.16.2": + version "7.16.2" + resolved "https://registry.yarnpkg.com/@mantine/store/-/store-7.16.2.tgz#0c1699c9c3f7871f5b1f25d3999516ad990f5351" + integrity sha512-9dEGLosrYSePlAwhfx3CxTLcWu2M98TtuYnelAiHEdNEkyafirvZxNt4paMoFXLKR1XPm5wdjDK7bdTaE0t7Og== "@mapbox/geojson-rewind@^0.5.2": version "0.5.2" @@ -7444,7 +7444,7 @@ eslint-config-airbnb@19.0.4: eslint-config-airbnb "19.0.4" eslint-import-resolver-webpack "0.13.10" eslint-plugin-compat "4.2.0" - eslint-plugin-graylog "file:../../../../.cache/yarn/v6/npm-eslint-config-graylog-1.3.0-4228572c-36c3-45ec-a426-d6ad9abe0608-1738152635323/node_modules/eslint-plugin-graylog" + eslint-plugin-graylog "file:packages/eslint-plugin-graylog" eslint-plugin-import "2.25.3" eslint-plugin-jest "28.11.0" eslint-plugin-jest-dom "5.5.0" @@ -9008,12 +9008,12 @@ graphemer@^1.4.0: "@tanstack/react-query" "4.36.1" "@types/jquery" "3.5.32" "@types/react" "18.3.13" - babel-preset-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-05f95a4e-b158-4fcb-a1d1-2428ffee0811-1738152635034/node_modules/babel-preset-graylog" - eslint-config-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-05f95a4e-b158-4fcb-a1d1-2428ffee0811-1738152635034/node_modules/eslint-config-graylog" + babel-preset-graylog "file:packages/babel-preset-graylog" + eslint-config-graylog "file:packages/eslint-config-graylog" formik "2.4.6" history "^5.3.0" html-webpack-plugin "^5.5.0" - jest-preset-graylog "file:../../../../.cache/yarn/v6/npm-graylog-web-plugin-6.2.0-SNAPSHOT-05f95a4e-b158-4fcb-a1d1-2428ffee0811-1738152635034/node_modules/jest-preset-graylog" + jest-preset-graylog "file:packages/jest-preset-graylog" jquery "3.7.1" moment "2.30.1" moment-timezone "0.5.47" From 60ef68f002b199398190cf24eac27a1551444439 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Thu, 30 Jan 2025 13:19:06 +0100 Subject: [PATCH 15/56] Removing formatting options from stylelint config. (#21375) * Removing formatting options from stylelint config. * Removing now unneeded package. --- .../packages/stylelint-config-graylog/index.js | 14 -------------- .../packages/stylelint-config-graylog/package.json | 3 +-- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/graylog2-web-interface/packages/stylelint-config-graylog/index.js b/graylog2-web-interface/packages/stylelint-config-graylog/index.js index 160a1dc8f35d..6d67b41123af 100644 --- a/graylog2-web-interface/packages/stylelint-config-graylog/index.js +++ b/graylog2-web-interface/packages/stylelint-config-graylog/index.js @@ -18,31 +18,17 @@ module.exports = { customSyntax: 'postcss-styled-syntax', extends: [ 'stylelint-config-standard', - 'stylelint-config-styled-components', ], rules: { - 'declaration-block-trailing-semicolon': 'always', - 'declaration-colon-newline-after': null, - 'declaration-colon-space-after': 'always', 'declaration-empty-line-before': null, 'function-name-case': null, - 'function-whitespace-after': null, - 'max-empty-lines': 2, 'media-query-no-invalid': null, 'no-descending-specificity': null, - 'no-empty-first-line': null, 'no-empty-source': null, - 'no-eol-whitespace': [ - true, { - ignore: ['empty-lines'], - }, - ], - 'no-missing-end-of-source-newline': null, 'property-no-vendor-prefix': [true, { ignoreProperties: ['grid-rows', 'grid-columns', 'grid-row', 'grid-column'], }], 'selector-class-pattern': null, - 'string-quotes': 'single', 'value-no-vendor-prefix': [true, { ignoreValues: ['grid', 'inline-grid'], }], diff --git a/graylog2-web-interface/packages/stylelint-config-graylog/package.json b/graylog2-web-interface/packages/stylelint-config-graylog/package.json index d56216005bdd..5037cd8e57cb 100644 --- a/graylog2-web-interface/packages/stylelint-config-graylog/package.json +++ b/graylog2-web-interface/packages/stylelint-config-graylog/package.json @@ -17,7 +17,6 @@ "postcss-styled-syntax": "0.7.1", "stylelint": "16.14.1", "stylelint-config-recommended": "15.0.0", - "stylelint-config-standard": "36.0.1", - "stylelint-config-styled-components": "0.1.1" + "stylelint-config-standard": "36.0.1" } } From 9da632f018380d126888a5b967ea8648148a8638 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:37:38 +0100 Subject: [PATCH 16/56] Bump react-ace from 12.0.0 to 13.0.0 in /graylog2-web-interface (#21488) Bumps [react-ace](https://github.com/securingsincity/react-ace) from 12.0.0 to 13.0.0. - [Release notes](https://github.com/securingsincity/react-ace/releases) - [Changelog](https://github.com/securingsincity/react-ace/blob/main/CHANGELOG.md) - [Commits](https://github.com/securingsincity/react-ace/compare/v12.0.0...v13.0.0) --- updated-dependencies: - dependency-name: react-ace dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- graylog2-web-interface/package.json | 2 +- graylog2-web-interface/yarn.lock | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/graylog2-web-interface/package.json b/graylog2-web-interface/package.json index 1687aebb4807..73ad2ff5288f 100644 --- a/graylog2-web-interface/package.json +++ b/graylog2-web-interface/package.json @@ -82,7 +82,7 @@ "plotly.js": "2.35.2", "posthog-js": "^1.52.0", "qs": "^6.3.0", - "react-ace": "12.0.0", + "react-ace": "13.0.0", "react-beautiful-dnd": "^13.1.0", "react-color": "^2.14.0", "react-day-picker": "^7.4.8", diff --git a/graylog2-web-interface/yarn.lock b/graylog2-web-interface/yarn.lock index 6f52fe23d1d9..312b6c49980f 100644 --- a/graylog2-web-interface/yarn.lock +++ b/graylog2-web-interface/yarn.lock @@ -3985,11 +3985,16 @@ accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.8: mime-types "~2.1.34" negotiator "0.6.3" -ace-builds@1.36.4, ace-builds@^1.32.8: +ace-builds@1.36.4: version "1.36.4" resolved "https://registry.yarnpkg.com/ace-builds/-/ace-builds-1.36.4.tgz#c859de4a7701aa86a1e708d38cebe66807d0d84c" integrity sha512-eE+iAsLRfNsq30yd34cezKSob6/N9mQatWs44Bp5LUDgKZ3rJtQds/YtcbnwbEWMTe7yCIxG/Cfezd4BsKIiFg== +ace-builds@^1.36.3: + version "1.37.5" + resolved "https://registry.yarnpkg.com/ace-builds/-/ace-builds-1.37.5.tgz#8cf3c3a2e869f32a193d314c8f4346e6218bfdae" + integrity sha512-VMJ4Cnhq6L9dwvOCyuyyvQuiVTSwdZC7zDKJBBBJJax0wGQ7MvzQZFoi0gMmCm2I4Zuv/ZbtwU/dlglIhCNLhw== + acorn-globals@^4.1.0: version "4.3.4" resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-4.3.4.tgz#9fa1926addc11c97308c4e66d7add0d40c3272e7" @@ -13455,12 +13460,12 @@ re-resizable@6.9.2: dependencies: fast-memoize "^2.5.1" -react-ace@12.0.0: - version "12.0.0" - resolved "https://registry.yarnpkg.com/react-ace/-/react-ace-12.0.0.tgz#d40afc7382092109eead7227d9426f55dcc2209d" - integrity sha512-PstU6CSMfYIJknb4su2Fa0WgLXzq2ufQgR6fjcSWuGT1hGTHkBzuKw+SncV8PuLCdSJBJc1VehPhyeXlWByG/g== +react-ace@13.0.0: + version "13.0.0" + resolved "https://registry.yarnpkg.com/react-ace/-/react-ace-13.0.0.tgz#e69c2aa4ccf1a81c758adba9ba2b4b3e3d929a69" + integrity sha512-PPk2O/ArHzDtbnK82QImfHYXwuiitRgHJf5AxwMQh9zciojbWsPmKJm1tMgWOYLCtGEz8/Dh3MxRxrXe7QcstQ== dependencies: - ace-builds "^1.32.8" + ace-builds "^1.36.3" diff-match-patch "^1.0.5" lodash.get "^4.4.2" lodash.isequal "^4.5.0" From fe6524ed4b628af81a65a4e1ed467d0b75d1c416 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Thu, 30 Jan 2025 16:16:28 +0100 Subject: [PATCH 17/56] Improving wording for bulk replay of events. (#21426) * Improving wording for bulk replay of events. * Changing wording of summary as well. --- .../events/bulk-replay/BulkEventReplay.tsx | 6 ++--- .../events/bulk-replay/EventListItem.tsx | 2 +- .../__tests__/BulkEventReplay.test.tsx | 24 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/graylog2-web-interface/src/components/events/bulk-replay/BulkEventReplay.tsx b/graylog2-web-interface/src/components/events/bulk-replay/BulkEventReplay.tsx index 50775a44a3e7..1c3984c9b390 100644 --- a/graylog2-web-interface/src/components/events/bulk-replay/BulkEventReplay.tsx +++ b/graylog2-web-interface/src/components/events/bulk-replay/BulkEventReplay.tsx @@ -103,7 +103,7 @@ const ReplayedSearch = ({ total, completed, selectedEvent }: React.PropsWithChil if (!selectedEvent && total === completed) { return (
    - You are done investigating all events. You can now select a bulk action to apply to all remaining events, or close the page to return to the events list. + You are done reviewing all events. You can now select a bulk action to apply to all remaining events, or close the page to return to the events list.
    ); } @@ -142,9 +142,9 @@ const BulkEventReplay = ({ initialEventIds, events: _events, onClose, BulkAction Replay Search

    The following list contains all of the events/alerts you selected in the previous step, allowing you to - investigate the replayed search for each of them. + review the replayed search for each of them.

    - Investigation of {completed}/{total} events completed. + Review of {completed}/{total} events completed. {eventIds.map(({ id: eventId, status }) => ( diff --git a/graylog2-web-interface/src/components/events/bulk-replay/__tests__/BulkEventReplay.test.tsx b/graylog2-web-interface/src/components/events/bulk-replay/__tests__/BulkEventReplay.test.tsx index 2ef205e82241..2a0920091da2 100644 --- a/graylog2-web-interface/src/components/events/bulk-replay/__tests__/BulkEventReplay.test.tsx +++ b/graylog2-web-interface/src/components/events/bulk-replay/__tests__/BulkEventReplay.test.tsx @@ -35,10 +35,10 @@ const initialEventIds = [ jest.mock('components/events/ReplaySearch', () => ({ alertId }: { alertId: string }) => Replaying search for event {alertId}); -const markEventAsInvestigated = async (eventId: string) => { - const markAsInvestigatedButton = await screen.findByRole('button', { name: new RegExp(`mark event "${eventId}" as investigated`, 'i') }); +const markEventAsReviewed = async (eventId: string) => { + const markAsReviewedButton = await screen.findByRole('button', { name: new RegExp(`mark event "${eventId}" as reviewed`, 'i') }); - return userEvent.click(markAsInvestigatedButton); + return userEvent.click(markAsReviewedButton); }; const removeEvent = async (eventId: string) => { @@ -101,17 +101,17 @@ describe('BulkEventReplay', () => { expect(screen.queryByText(eventMessage(0))).not.toBeInTheDocument(); }); - it('marking events as investigated jumps to next one', async () => { + it('marking events as reviewed jumps to next one', async () => { render(); - await markEventAsInvestigated(initialEventIds[0]); + await markEventAsReviewed(initialEventIds[0]); await expectReplayingEvent(initialEventIds[1]); - await markEventAsInvestigated(initialEventIds[1]); + await markEventAsReviewed(initialEventIds[1]); await expectReplayingEvent(initialEventIds[2]); - await markEventAsInvestigated(initialEventIds[2]); - await screen.findByText('You are done investigating all events. You can now select a bulk action to apply to all remaining events, or close the page to return to the events list.'); + await markEventAsReviewed(initialEventIds[2]); + await screen.findByText('You are done reviewing all events. You can now select a bulk action to apply to all remaining events, or close the page to return to the events list.'); }); it('allows jumping to specific events', async () => { @@ -130,14 +130,14 @@ describe('BulkEventReplay', () => { it('skips removed event when jumping to next one', async () => { render(); await removeEvent(initialEventIds[1]); - await markEventAsInvestigated(initialEventIds[0]); + await markEventAsReviewed(initialEventIds[0]); await expectReplayingEvent(initialEventIds[2]); }); - it('skips event marked as investigated when jumping to next one', async () => { + it('skips event marked as reviewed when jumping to next one', async () => { render(); - await markEventAsInvestigated(initialEventIds[1]); - await markEventAsInvestigated(initialEventIds[0]); + await markEventAsReviewed(initialEventIds[1]); + await markEventAsReviewed(initialEventIds[0]); await expectReplayingEvent(initialEventIds[2]); }); From 611bbc26883e32e6ce49fc07d4307357f5cb7413 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Thu, 30 Jan 2025 16:17:26 +0100 Subject: [PATCH 18/56] Removing `prop-types` remainders. (#21425) * Removing `prop-types` remainders. * Fixing linter hint. --- .../packages/graylog-web-plugin/package.json | 1 - .../components/indices/data-tiering/types.ts | 11 -- .../src/views/components/CustomPropTypes.ts | 129 ------------------ .../number/NumberVisualization.test.tsx | 4 +- graylog2-web-interface/src/views/types.ts | 4 + .../test/PreflightWrappingContainer.tsx | 5 - .../test/WrappingContainer.tsx | 5 - .../{MockComponent.jsx => MockComponent.tsx} | 15 +- 8 files changed, 9 insertions(+), 165 deletions(-) delete mode 100644 graylog2-web-interface/src/views/components/CustomPropTypes.ts rename graylog2-web-interface/test/helpers/mocking/{MockComponent.jsx => MockComponent.tsx} (76%) diff --git a/graylog2-web-interface/packages/graylog-web-plugin/package.json b/graylog2-web-interface/packages/graylog-web-plugin/package.json index 5d9d3b3975bc..c1f29e4ad92c 100644 --- a/graylog2-web-interface/packages/graylog-web-plugin/package.json +++ b/graylog2-web-interface/packages/graylog-web-plugin/package.json @@ -43,7 +43,6 @@ "jquery": "3.7.1", "moment": "2.30.1", "moment-timezone": "0.5.47", - "prop-types": "15.8.1", "react": "18.3.1", "react-dom": "18.2.0", "react-router-bootstrap": "0.26.3", diff --git a/graylog2-web-interface/src/components/indices/data-tiering/types.ts b/graylog2-web-interface/src/components/indices/data-tiering/types.ts index 456281705a2d..153a4b4fe0f7 100644 --- a/graylog2-web-interface/src/components/indices/data-tiering/types.ts +++ b/graylog2-web-interface/src/components/indices/data-tiering/types.ts @@ -14,7 +14,6 @@ * along with this program. If not, see * . */ -import PropTypes from 'prop-types'; export const DATA_TIERING_TYPE = { HOT_ONLY: 'hot_only', @@ -47,13 +46,3 @@ export type DataTieringStatus = { has_failed_snapshot: boolean, failed_snapshot_name: string | null, } - -export const dataTieringPropType = PropTypes.shape({ - type: PropTypes.oneOf(['hot_only', 'hot_warm']).isRequired, - index_lifetime_min: PropTypes.string.isRequired, - index_lifetime_max: PropTypes.string.isRequired, - index_hot_lifetime_min: PropTypes.string, - warm_tier_enabled: PropTypes.bool, - archive_before_deletion: PropTypes.bool, - warm_tier_repository_name: PropTypes.string, -}); diff --git a/graylog2-web-interface/src/views/components/CustomPropTypes.ts b/graylog2-web-interface/src/views/components/CustomPropTypes.ts deleted file mode 100644 index 087f6c42d030..000000000000 --- a/graylog2-web-interface/src/views/components/CustomPropTypes.ts +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import PropTypes from 'prop-types'; -import ImmutablePropTypes from 'react-immutable-proptypes'; -import get from 'lodash/get'; - -import TFieldType from 'views/logic/fieldtypes/FieldType'; -import TFieldTypeMapping from 'views/logic/fieldtypes/FieldTypeMapping'; -import View from 'views/logic/views/View'; - -const TimeRangeType = PropTypes.oneOf(['relative', 'absolute', 'keyword']); -const FieldType = PropTypes.instanceOf(TFieldType); -const FieldTypeMapping = PropTypes.instanceOf(TFieldTypeMapping); -const FieldListType = ImmutablePropTypes.listOf(FieldTypeMapping); - -const CurrentView = PropTypes.exact({ - activeQuery: PropTypes.string.isRequired, - view: PropTypes.instanceOf(View).isRequired, - dirty: PropTypes.bool.isRequired, - isNew: PropTypes.bool.isRequired, -}); - -export type CurrentViewType = { - activeQuery: string, -}; - -const BackendMessage = PropTypes.exact({ - index: PropTypes.string.isRequired, - message: PropTypes.exact({ - _id: PropTypes.string.isRequired, - }).isRequired, -}); - -const Message = PropTypes.exact({ - id: PropTypes.string.isRequired, - index: PropTypes.string.isRequired, - fields: PropTypes.object.isRequired, - formatted_fields: PropTypes.object, - highlight_ranges: PropTypes.object, - decoration_stats: PropTypes.exact({ - added_fields: PropTypes.object, - changed_fields: PropTypes.object, - removed_fields: PropTypes.object, - }), -}); - -const ValidElements = PropTypes.oneOfType([ - PropTypes.element, - PropTypes.string, -]); -const OneOrMoreChildren = PropTypes.oneOfType([ - ValidElements, - PropTypes.arrayOf(ValidElements), -]); - -const prototypesOf = (target) => { - let i = target; - const result = []; - - while (i) { - try { - const prototype = Object.getPrototypeOf(i); - - result.push(prototype); - i = prototype; - } catch { - i = undefined; - } - } - - return result; -}; - -const createInstanceOf = (expectedClass, required = false) => { - const expectedConstructorName = get(expectedClass, 'name'); - - return (props, propName, componentName) => { - const value = props[propName]; - - if (!value) { - return required - ? new Error(`Invalid prop ${propName} supplied to ${componentName}: expected to be instance of ${expectedConstructorName} but found ${value} instead`) - : undefined; - } - - const valueConstructorName = get(prototypesOf(value)[0], ['constructor', 'name']); - const constructorNames = prototypesOf(value) - .map((proto) => get(proto, ['constructor', 'name'])) - .filter((name) => name !== undefined); - - if (!constructorNames.includes(expectedConstructorName)) { - return new Error(`Invalid prop ${propName} supplied to ${componentName}: ${valueConstructorName} expected to be instance of ${expectedConstructorName}`); - } - - return undefined; - }; -}; - -const instanceOf = (expected) => Object.assign( - createInstanceOf(expected, false), - { isRequired: createInstanceOf(expected, true) }, -); - -export default ({ - ...PropTypes, - BackendMessage, - Message, - CurrentView, - FieldListType, - FieldType, - OneOrMoreChildren, - TimeRangeType, - instanceOf, - ValidElements, -}); diff --git a/graylog2-web-interface/src/views/components/visualizations/number/NumberVisualization.test.tsx b/graylog2-web-interface/src/views/components/visualizations/number/NumberVisualization.test.tsx index a9bc44576c84..c6644a609f36 100644 --- a/graylog2-web-interface/src/views/components/visualizations/number/NumberVisualization.test.tsx +++ b/graylog2-web-interface/src/views/components/visualizations/number/NumberVisualization.test.tsx @@ -24,7 +24,7 @@ import RenderCompletionCallback from 'views/components/widgets/RenderCompletionC import AggregationWidgetConfig from 'views/logic/aggregationbuilder/AggregationWidgetConfig'; import Series from 'views/logic/aggregationbuilder/Series'; import type { Rows } from 'views/logic/searchtypes/pivot/PivotHandler'; -import type { CurrentViewType } from 'views/components/CustomPropTypes'; +import type { CurrentViewType } from 'views/types'; import TestStoreProvider from 'views/test/TestStoreProvider'; import useViewsPlugin from 'views/test/testViewsPlugin'; @@ -32,7 +32,7 @@ import NumberVisualization from './NumberVisualization'; jest.mock('./AutoFontSizer', () => ({ children }: React.PropsWithChildren<{}>) => children); -jest.mock('views/components/highlighting/CustomHighlighting', () => ({ children }: React.PropsWithChildren<{}>) =>
    {children}
    ); +jest.mock('views/components/highlighting/CustomHighlighting', () => ({ children = undefined }: React.PropsWithChildren<{}>) =>
    {children}
    ); jest.mock('views/components/Value', () => ({ value }: { value: string }) =>
    {value}
    ); diff --git a/graylog2-web-interface/src/views/types.ts b/graylog2-web-interface/src/views/types.ts index 17bb863e96d4..fab736fc9644 100644 --- a/graylog2-web-interface/src/views/types.ts +++ b/graylog2-web-interface/src/views/types.ts @@ -413,6 +413,10 @@ export type CustomCommandContextProvider = provider: () => CustomCommandContext[T], } +export type CurrentViewType = { + activeQuery: string, +}; + export interface ViewState { activeQuery: QueryId; view: View; diff --git a/graylog2-web-interface/test/PreflightWrappingContainer.tsx b/graylog2-web-interface/test/PreflightWrappingContainer.tsx index 13cb2ba68a59..e8020e73bfeb 100644 --- a/graylog2-web-interface/test/PreflightWrappingContainer.tsx +++ b/graylog2-web-interface/test/PreflightWrappingContainer.tsx @@ -15,7 +15,6 @@ * . */ import React from 'react'; -import PropTypes from 'prop-types'; import { MemoryRouter } from 'react-router-dom'; import PreflightThemeProvider from 'preflight/theme/PreflightThemeProvider'; @@ -39,8 +38,4 @@ const PreflightWrappingContainer = ({ children }: Props) => ( ); -PreflightWrappingContainer.propTypes = { - children: PropTypes.node.isRequired, -}; - export default PreflightWrappingContainer; diff --git a/graylog2-web-interface/test/WrappingContainer.tsx b/graylog2-web-interface/test/WrappingContainer.tsx index 9dc3b1f08cdc..0c454971c14a 100644 --- a/graylog2-web-interface/test/WrappingContainer.tsx +++ b/graylog2-web-interface/test/WrappingContainer.tsx @@ -15,7 +15,6 @@ * . */ import React from 'react'; -import PropTypes from 'prop-types'; import { MemoryRouter } from 'react-router-dom'; import DefaultQueryClientProvider from './DefaultQueryClientProvider'; @@ -35,8 +34,4 @@ const WrappingContainer = ({ children }: Props) => ( ); -WrappingContainer.propTypes = { - children: PropTypes.node.isRequired, -}; - export default WrappingContainer; diff --git a/graylog2-web-interface/test/helpers/mocking/MockComponent.jsx b/graylog2-web-interface/test/helpers/mocking/MockComponent.tsx similarity index 76% rename from graylog2-web-interface/test/helpers/mocking/MockComponent.jsx rename to graylog2-web-interface/test/helpers/mocking/MockComponent.tsx index 72491c0761af..dbf842cdcfe1 100644 --- a/graylog2-web-interface/test/helpers/mocking/MockComponent.jsx +++ b/graylog2-web-interface/test/helpers/mocking/MockComponent.tsx @@ -14,21 +14,12 @@ * along with this program. If not, see * . */ -import React from 'react'; -import PropTypes from 'prop-types'; -import { kebabCase } from 'lodash'; +import * as React from 'react'; +import kebabCase from 'lodash/kebabCase'; -export default (name) => { +export default (name: string) => { const MockComponent = ({ children, ...rest }) => React.createElement(kebabCase(name), rest, children); - MockComponent.propTypes = { - children: PropTypes.node, - }; - - MockComponent.defaultProps = { - children: null, - }; - MockComponent.displayName = name; return MockComponent; From 593ec7c1140955f599d65042b82055c99c6881f1 Mon Sep 17 00:00:00 2001 From: Linus Pahl <46300478+linuspahl@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:35:59 +0100 Subject: [PATCH 19/56] Implement abstraction for `use-query-params` usage. (#21287) * Create `QueryParams` file which provides functions to interact with query params. * Implement new abstraction for query params usage. --- .../hooks/useUrlQueryFilters.test.tsx | 6 ++-- .../EntityFilters/hooks/useUrlQueryFilters.ts | 2 +- .../PaginatedEntityTable.tsx | 2 +- .../RemoteReindexingMigration.test.tsx | 6 ++-- .../remoteReindexing/RemoteReindexRunning.tsx | 2 +- .../IndexSetFieldTypesList.test.tsx | 6 ++-- .../src/pages/IndexSetFieldTypesPage.test.tsx | 6 ++-- .../src/routing/QueryParams.ts | 32 +++++++++++++++++++ .../DashboardsOverview.test.tsx | 6 ++-- 9 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 graylog2-web-interface/src/routing/QueryParams.ts diff --git a/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.test.tsx b/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.test.tsx index 3681ff8bbe58..751c53884afe 100644 --- a/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.test.tsx +++ b/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.test.tsx @@ -17,16 +17,16 @@ import { renderHook } from 'wrappedTestingLibrary/hooks'; import { OrderedMap } from 'immutable'; import * as React from 'react'; -import { useQueryParam } from 'use-query-params'; import { MemoryRouter } from 'react-router-dom'; +import { useQueryParam } from 'routing/QueryParams'; import DefaultQueryParamProvider from 'routing/DefaultQueryParamProvider'; import { asMock } from 'helpers/mocking'; import useUrlQueryFilters from './useUrlQueryFilters'; -jest.mock('use-query-params', () => ({ - ...jest.requireActual('use-query-params'), +jest.mock('routing/QueryParams', () => ({ + ...jest.requireActual('routing/QueryParams'), useQueryParam: jest.fn(), })); diff --git a/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.ts b/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.ts index 32bf4fb566e0..aa7fa82d6b16 100644 --- a/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.ts +++ b/graylog2-web-interface/src/components/common/EntityFilters/hooks/useUrlQueryFilters.ts @@ -14,10 +14,10 @@ * along with this program. If not, see * . */ -import { useQueryParam, ArrayParam } from 'use-query-params'; import { useMemo, useCallback } from 'react'; import { OrderedMap } from 'immutable'; +import { useQueryParam, ArrayParam } from 'routing/QueryParams'; import type { UrlQueryFilters } from 'components/common/EntityFilters/types'; const useUrlQueryFilters = (): [UrlQueryFilters, (filters: UrlQueryFilters) => void] => { diff --git a/graylog2-web-interface/src/components/common/PaginatedEntityTable/PaginatedEntityTable.tsx b/graylog2-web-interface/src/components/common/PaginatedEntityTable/PaginatedEntityTable.tsx index c494a8792294..48f4ee37adae 100644 --- a/graylog2-web-interface/src/components/common/PaginatedEntityTable/PaginatedEntityTable.tsx +++ b/graylog2-web-interface/src/components/common/PaginatedEntityTable/PaginatedEntityTable.tsx @@ -16,9 +16,9 @@ */ import * as React from 'react'; import { useMemo, useCallback } from 'react'; -import { useQueryParam, StringParam } from 'use-query-params'; import styled from 'styled-components'; +import { useQueryParam, StringParam } from 'routing/QueryParams'; import useTableLayout from 'components/common/EntityDataTable/hooks/useTableLayout'; import usePaginationQueryParameter from 'hooks/usePaginationQueryParameter'; import useUpdateUserLayoutPreferences from 'components/common/EntityDataTable/hooks/useUpdateUserLayoutPreferences'; diff --git a/graylog2-web-interface/src/components/datanode/migrations/RemoteReindexingMigration.test.tsx b/graylog2-web-interface/src/components/datanode/migrations/RemoteReindexingMigration.test.tsx index 696e9a3ea4d8..1c2d868519e8 100644 --- a/graylog2-web-interface/src/components/datanode/migrations/RemoteReindexingMigration.test.tsx +++ b/graylog2-web-interface/src/components/datanode/migrations/RemoteReindexingMigration.test.tsx @@ -16,8 +16,8 @@ */ import React from 'react'; import { render, screen } from 'wrappedTestingLibrary'; -import { useQueryParam } from 'use-query-params'; +import { useQueryParam } from 'routing/QueryParams'; import type { MigrationState, MigrationStateItem } from 'components/datanode/Types'; import { asMock } from 'helpers/mocking'; @@ -25,8 +25,8 @@ import RemoteReindexingMigration from './RemoteReindexingMigration'; import { MIGRATION_STATE } from '../Constants'; -jest.mock('use-query-params', () => ({ - ...jest.requireActual('use-query-params'), +jest.mock('routing/QueryParams', () => ({ + ...jest.requireActual('routing/QueryParams'), useQueryParam: jest.fn(), })); diff --git a/graylog2-web-interface/src/components/datanode/migrations/remoteReindexing/RemoteReindexRunning.tsx b/graylog2-web-interface/src/components/datanode/migrations/remoteReindexing/RemoteReindexRunning.tsx index d58112e5b9f1..92e8fa5da04a 100644 --- a/graylog2-web-interface/src/components/datanode/migrations/remoteReindexing/RemoteReindexRunning.tsx +++ b/graylog2-web-interface/src/components/datanode/migrations/remoteReindexing/RemoteReindexRunning.tsx @@ -18,8 +18,8 @@ import * as React from 'react'; import { useState, useEffect } from 'react'; import styled, { css } from 'styled-components'; import type { ColorVariant } from '@graylog/sawmill'; -import { useQueryParam, StringParam } from 'use-query-params'; +import { useQueryParam, StringParam } from 'routing/QueryParams'; import { ConfirmDialog } from 'components/common'; import { Alert, BootstrapModalWrapper, Button, Modal } from 'components/bootstrap'; import useSendTelemetry from 'logic/telemetry/useSendTelemetry'; diff --git a/graylog2-web-interface/src/components/indices/IndexSetFieldTypes/IndexSetFieldTypesList.test.tsx b/graylog2-web-interface/src/components/indices/IndexSetFieldTypes/IndexSetFieldTypesList.test.tsx index d7bf5a9d5157..8a9b97d792ed 100644 --- a/graylog2-web-interface/src/components/indices/IndexSetFieldTypes/IndexSetFieldTypesList.test.tsx +++ b/graylog2-web-interface/src/components/indices/IndexSetFieldTypes/IndexSetFieldTypesList.test.tsx @@ -16,8 +16,8 @@ */ import * as React from 'react'; import { render, screen, fireEvent, within } from 'wrappedTestingLibrary'; -import { useQueryParam } from 'use-query-params'; +import { useQueryParam } from 'routing/QueryParams'; import { MockStore } from 'helpers/mocking'; import useParams from 'routing/useParams'; import asMock from 'helpers/mocking/AsMock'; @@ -80,8 +80,8 @@ jest.mock('components/indices/IndexSetFieldTypeProfiles/hooks/useProfile'); jest.mock('components/indices/IndexSetFieldTypes/hooks/useIndexProfileWithMappingsByField'); jest.mock('components/indices/IndexSetFieldTypeProfiles/hooks/useProfileOptions'); -jest.mock('use-query-params', () => ({ - ...jest.requireActual('use-query-params'), +jest.mock('routing/QueryParams', () => ({ + ...jest.requireActual('routing/QueryParams'), useQueryParam: jest.fn(), })); diff --git a/graylog2-web-interface/src/pages/IndexSetFieldTypesPage.test.tsx b/graylog2-web-interface/src/pages/IndexSetFieldTypesPage.test.tsx index 07db968ae47f..4c4076df4493 100644 --- a/graylog2-web-interface/src/pages/IndexSetFieldTypesPage.test.tsx +++ b/graylog2-web-interface/src/pages/IndexSetFieldTypesPage.test.tsx @@ -16,8 +16,8 @@ */ import * as React from 'react'; import { render, screen, fireEvent, within } from 'wrappedTestingLibrary'; -import { useQueryParam } from 'use-query-params'; +import { useQueryParam } from 'routing/QueryParams'; import { MockStore } from 'helpers/mocking'; import asMock from 'helpers/mocking/AsMock'; import useFetchEntities from 'components/common/PaginatedEntityTable/useFetchEntities'; @@ -53,8 +53,8 @@ jest.mock('components/common/PaginatedEntityTable/useFetchEntities', () => jest. jest.mock('components/common/EntityDataTable/hooks/useUserLayoutPreferences'); -jest.mock('use-query-params', () => ({ - ...jest.requireActual('use-query-params'), +jest.mock('routing/QueryParams', () => ({ + ...jest.requireActual('routing/QueryParams'), useQueryParam: jest.fn(), })); diff --git a/graylog2-web-interface/src/routing/QueryParams.ts b/graylog2-web-interface/src/routing/QueryParams.ts new file mode 100644 index 000000000000..9f35eed6769b --- /dev/null +++ b/graylog2-web-interface/src/routing/QueryParams.ts @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +import { useQueryParams, useQueryParam, StringParam, NumberParam, ArrayParam } from 'use-query-params'; + +const parseNestedObject = (fieldQueryString: string) => { + try { + return JSON.parse(decodeURIComponent(fieldQueryString)); + } catch (_error) { + return undefined; + } +}; + +const NestedObjectParam = { + encode: (object: Object | null | undefined) => encodeURIComponent(JSON.stringify(object)), + decode: (objectStr: string | null | undefined) => parseNestedObject(objectStr), +}; + +export { useQueryParams, useQueryParam, StringParam, NumberParam, NestedObjectParam, ArrayParam }; diff --git a/graylog2-web-interface/src/views/components/dashboard/DashboardsOverview/DashboardsOverview.test.tsx b/graylog2-web-interface/src/views/components/dashboard/DashboardsOverview/DashboardsOverview.test.tsx index 43a4866dfe1d..3e5b8e54d09a 100644 --- a/graylog2-web-interface/src/views/components/dashboard/DashboardsOverview/DashboardsOverview.test.tsx +++ b/graylog2-web-interface/src/views/components/dashboard/DashboardsOverview/DashboardsOverview.test.tsx @@ -16,8 +16,8 @@ */ import React from 'react'; import { render, screen } from 'wrappedTestingLibrary'; -import { useQueryParam } from 'use-query-params'; +import { useQueryParam } from 'routing/QueryParams'; import View from 'views/logic/views/View'; import Search from 'views/logic/search/Search'; import { asMock } from 'helpers/mocking'; @@ -43,8 +43,8 @@ jest.mock('views/stores/ViewManagementStore', () => ({ }, })); -jest.mock('use-query-params', () => ({ - ...jest.requireActual('use-query-params'), +jest.mock('routing/QueryParams', () => ({ + ...jest.requireActual('routing/QueryParams'), useQueryParam: jest.fn(), })); From 4c741741199943e2ff45b100dbb19cd9ab358f6b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:00:12 +0100 Subject: [PATCH 20/56] Bump material-symbols from 0.22.2 to 0.28.1 in /graylog2-web-interface (#21482) * Bump material-symbols from 0.22.2 to 0.28.1 in /graylog2-web-interface Bumps [material-symbols](https://github.com/marella/material-symbols/tree/HEAD/material-symbols) from 0.22.2 to 0.28.1. - [Release notes](https://github.com/marella/material-symbols/releases) - [Commits](https://github.com/marella/material-symbols/commits/v0.28.1/material-symbols) --- updated-dependencies: - dependency-name: material-symbols dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Replacing deprecated icon. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dennis Oelkers --- graylog2-web-interface/package.json | 2 +- .../views/components/widgets/WidgetHorizontalStretch.tsx | 4 ++-- graylog2-web-interface/yarn.lock | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/graylog2-web-interface/package.json b/graylog2-web-interface/package.json index 73ad2ff5288f..8a6cb7d975c2 100644 --- a/graylog2-web-interface/package.json +++ b/graylog2-web-interface/package.json @@ -72,7 +72,7 @@ "leaflet": "^1.5.1", "lodash": "^4.17.4", "marked": "^14.0.0", - "material-symbols": "^0.22.0", + "material-symbols": "^0.28.1", "md5": "^2.2.1", "moment-duration-format": "2.3.2", "moment-precise-range-plugin": "^1.3.0", diff --git a/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx b/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx index b17468a54d06..71f872d693df 100644 --- a/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx +++ b/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx @@ -72,7 +72,7 @@ const WidgetHorizontalStretch = ({ onStretch, position, widgetId, widgetType }: const { width } = position; const stretched = width === Infinity; - const icon = stretched ? 'compress' : 'width'; + const icon = stretched ? 'compress' : 'expand'; const title = stretched ? 'Compress width' : 'Stretch width'; return ( @@ -80,7 +80,7 @@ const WidgetHorizontalStretch = ({ onStretch, position, widgetId, widgetType }: name={icon} title={title} $stretched={stretched} - rotation={stretched ? 90 : undefined} /> + rotation={90} /> ); }; diff --git a/graylog2-web-interface/yarn.lock b/graylog2-web-interface/yarn.lock index 312b6c49980f..f25307fe5d02 100644 --- a/graylog2-web-interface/yarn.lock +++ b/graylog2-web-interface/yarn.lock @@ -11729,10 +11729,10 @@ material-colors@^1.2.1: resolved "https://registry.yarnpkg.com/material-colors/-/material-colors-1.2.6.tgz#6d1958871126992ceecc72f4bcc4d8f010865f46" integrity sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg== -material-symbols@^0.22.0: - version "0.22.2" - resolved "https://registry.yarnpkg.com/material-symbols/-/material-symbols-0.22.2.tgz#a51f82aa4c3b8a0483bef186abb51f0707fd5fae" - integrity sha512-guN2+CzAwxUfdXiuVHcdogDmvhzvRYxMakKd39WmYuyTPaN73UuNC5cH4d4/JVNaLT1EMM8W/4PqHqVBye3ZiA== +material-symbols@^0.28.1: + version "0.28.1" + resolved "https://registry.yarnpkg.com/material-symbols/-/material-symbols-0.28.1.tgz#9c506b133878fc4a2faa7fd2304c371aceb115f7" + integrity sha512-oLaBgTunF04BQEcUP5z+6FStqdfXrNVnYo2CB4Ej8d2RqrhYxSKllcHvXRYWjNNl/hRmlHJF9B62YWuZ4kHYpA== math-intrinsics@^1.0.0, math-intrinsics@^1.1.0: version "1.1.0" From 39c4f387be7e62548c1f5d04ecf7426c219f96e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Thu, 30 Jan 2025 17:10:51 +0100 Subject: [PATCH 21/56] Use label instead of h3 for stream select --- .../InputSetupWizard/steps/SetupRoutingStep.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx index e98db578c56b..f194b673730c 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/SetupRoutingStep.tsx @@ -41,7 +41,7 @@ const DescriptionCol = styled(Col)(({ theme }) => css` `); const StyledHeading = styled.h3(({ theme }) => css` - margin-bottom: ${theme.spacings.md}; + margin-bottom: ${theme.spacings.sm}; `); const ExistingStreamCol = styled(Col)(({ theme }) => css` @@ -67,6 +67,15 @@ const ConntectedPipelinesList = styled.ul` padding-left: 20px; `; +const StyledLabel = styled.label(({ theme }) => css` + font-weight: normal; + line-height: 1.1; + margin-bottom: ${theme.spacings.sm}; + display: inline-block; + font-size: ${theme.fonts.size.h3}; + background: none; +`); + export type RoutingStepData = { streamId?: string, newStream?: StreamFormValues, @@ -225,7 +234,8 @@ const SetupRoutingStep = () => { ) : ( - Choose an existing Stream + Choose an existing Stream + {!isLoadingStreams && ( {field.human_name} {optionalMarker(field)}; - const handleFileRead = (fileReader: FileReader, file) => { const dataUrl = fileReader.result; @@ -120,7 +118,7 @@ const EncryptedInlineBinaryField = ({ field, title, typeName, dirty = false, onC . */ -import React from 'react'; - import type { ConfigurationField } from 'components/configurationforms/types'; export const hasAttribute = (array: Array, attribute: string): boolean => array.find((e) => e.toLowerCase() === attribute.toLowerCase()) !== undefined; -export const optionalMarker = (field: ConfigurationField): React.ReactNode | null => (field.is_optional && field.type !== 'boolean' ? (optional) : null); +export const optionableLabel = (field: ConfigurationField): string => (field.is_optional && field.type !== 'boolean' ? ` ${field.human_name} (optional)` : field.human_name); export default { hasAttribute, - optionalMarker, + optionableLabel, }; diff --git a/graylog2-web-interface/src/components/configurationforms/ListField.test.tsx b/graylog2-web-interface/src/components/configurationforms/ListField.test.tsx index 1d7bf20960c6..f9bc25f7a30c 100644 --- a/graylog2-web-interface/src/components/configurationforms/ListField.test.tsx +++ b/graylog2-web-interface/src/components/configurationforms/ListField.test.tsx @@ -40,12 +40,10 @@ describe('', () => { it('should render an empty field', async () => { render(); - const fieldLabel = await screen.findByText(listField.human_name, { exact: true }); - const optionalMarker = screen.getByText(/(optional)/); + const fieldLabel = await screen.findByText(`${listField.human_name} (optional)`); const select = screen.getByLabelText(listField.human_name, { exact: false }); expect(fieldLabel).toBeInTheDocument(); - expect(optionalMarker).toBeInTheDocument(); expect(select).toBeInTheDocument(); }); diff --git a/graylog2-web-interface/src/components/configurationforms/ListField.tsx b/graylog2-web-interface/src/components/configurationforms/ListField.tsx index dcde5138037e..7f6e5474c382 100644 --- a/graylog2-web-interface/src/components/configurationforms/ListField.tsx +++ b/graylog2-web-interface/src/components/configurationforms/ListField.tsx @@ -20,7 +20,7 @@ import React from 'react'; import type { ListField as ListFieldType } from 'components/configurationforms/types'; import { MultiSelect } from 'components/common'; import { Input } from 'components/bootstrap'; -import { optionalMarker } from 'components/configurationforms/FieldHelpers'; +import { optionableLabel } from 'components/configurationforms/FieldHelpers'; type Props = { autoFocus?: boolean, @@ -44,13 +44,11 @@ const ListField = ({ autoFocus = false, field, onChange, title, typeName, value const formattedOptions = Object.entries(options) .map(([label, optionValue]) => ({ value: optionValue, label: label })); - const label = <>{field.human_name} {optionalMarker(field)}; - const selectValue = Array.isArray(value) ? value.join(',') : value; return ( {field.human_name} {optionalMarker(field)}; - return ( (false); - const labelContent = <>{field.human_name} {optionalMarker(field)}; - const getFieldValue = () => { if (showReadOnlyEncrypted) return 'encrypted placeholder'; @@ -98,7 +96,7 @@ const TextField = ({ field, title, typeName, dirty = false, onChange, value = '' Date: Fri, 31 Jan 2025 07:50:14 +0100 Subject: [PATCH 23/56] Improve position of widget stretch icon (#21495) --- .../views/components/widgets/WidgetHorizontalStretch.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx b/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx index 71f872d693df..e2e74fa58e7f 100644 --- a/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx +++ b/graylog2-web-interface/src/views/components/widgets/WidgetHorizontalStretch.tsx @@ -16,7 +16,7 @@ */ import * as React from 'react'; import { useCallback } from 'react'; -import styled, { css } from 'styled-components'; +import styled from 'styled-components'; import Spinner from 'components/common/Spinner'; import { widgetDefinition } from 'views/logic/Widgets'; @@ -26,12 +26,12 @@ import useLocation from 'routing/useLocation'; import { getPathnameWithoutId } from 'util/URLUtils'; import { TELEMETRY_EVENT_TYPE } from 'logic/telemetry/Constants'; -const StyledIconButton = styled(IconButton)<{ $stretched: boolean }>(({ $stretched }) => css` +const StyledIconButton = styled(IconButton)` span { position: relative; - left: ${$stretched ? '-1px' : 0}; + left: -1px; } -`); +`; type PositionType = { col: number, @@ -79,7 +79,6 @@ const WidgetHorizontalStretch = ({ onStretch, position, widgetId, widgetType }: ); }; From b4d953cc830fce9101ff2bde2e6978fccaf794af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 07:50:30 +0100 Subject: [PATCH 24/56] Bump @types/lodash from 4.17.10 to 4.17.15 in /graylog2-web-interface (#21499) Bumps [@types/lodash](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/lodash) from 4.17.10 to 4.17.15. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/lodash) --- updated-dependencies: - dependency-name: "@types/lodash" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- graylog2-web-interface/yarn.lock | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/graylog2-web-interface/yarn.lock b/graylog2-web-interface/yarn.lock index f25307fe5d02..6c8de336194d 100644 --- a/graylog2-web-interface/yarn.lock +++ b/graylog2-web-interface/yarn.lock @@ -3288,9 +3288,9 @@ "@types/geojson" "*" "@types/lodash@^4.14.165": - version "4.17.10" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.10.tgz#64f3edf656af2fe59e7278b73d3e62404144a6e6" - integrity sha512-YpS0zzoduEhuOWjAotS6A5AVCva7X4lVlYLF0FYHAY9sdraBfnatttHItlWeZdGhuEkf+OzMNg2ZYAx8t+52uQ== + version "4.17.15" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.15.tgz#12d4af0ed17cc7600ce1f9980cec48fc17ad1e89" + integrity sha512-w/P33JFeySuhN6JLkysYUK2gEmy9kHHFN7E8ro0tkfmlDOgxBDzWEZ/J8cWA+fHqFevpswDTFZnDx+R9lbL6xw== "@types/mapbox__point-geometry@*", "@types/mapbox__point-geometry@^0.1.4": version "0.1.4" @@ -9022,7 +9022,6 @@ graphemer@^1.4.0: jquery "3.7.1" moment "2.30.1" moment-timezone "0.5.47" - prop-types "15.8.1" react "18.3.1" react-dom "18.2.0" react-router-bootstrap "0.26.3" @@ -13286,7 +13285,7 @@ prop-types-extra@^1.0.1: react-is "^16.3.2" warning "^4.0.0" -prop-types@15.8.1, prop-types@15.x, prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1: +prop-types@15.x, prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== @@ -15632,7 +15631,6 @@ styled-components@6.1.1: stylelint "16.14.1" stylelint-config-recommended "15.0.0" stylelint-config-standard "36.0.1" - stylelint-config-styled-components "0.1.1" stylelint-config-recommended@15.0.0: version "15.0.0" @@ -15651,11 +15649,6 @@ stylelint-config-standard@36.0.1: dependencies: stylelint-config-recommended "^14.0.1" -stylelint-config-styled-components@0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/stylelint-config-styled-components/-/stylelint-config-styled-components-0.1.1.tgz#b408388d7c687833ab4be4c4e6522d97d2827ede" - integrity sha512-z5Xz/9GmvxO6e/DLzBMwkB85zHxEEjN6K7Cj80Bi+o/9vR9eS3GX3E9VuMnX9WLFYulqbqLtTapGGY28JBiy9Q== - stylelint@16.14.1: version "16.14.1" resolved "https://registry.yarnpkg.com/stylelint/-/stylelint-16.14.1.tgz#32d3df8c5ce7ba0275ce6a4a966b6099d7a828e3" From 31e093a971da73dfcd8cc299fd685de83aaf5da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Fri, 31 Jan 2025 09:46:54 +0100 Subject: [PATCH 25/56] Add test id to input diagnosis button --- .../components/inputs/InputSetupWizard/steps/StartInputStep.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx index 2390fea0bdc6..5472311249fd 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/steps/StartInputStep.tsx @@ -317,7 +317,7 @@ const StartInputStep = () => { if (hasNextStep) { return ( - + ); } From ec5161cb5261ad4ed1ae4ab22ef19767fa5f1862 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 09:49:08 +0100 Subject: [PATCH 26/56] Bump react-window-infinite-loader in /graylog2-web-interface (#21502) Bumps [react-window-infinite-loader](https://github.com/bvaughn/react-window-infinite-loader) from 1.0.9 to 1.0.10. - [Changelog](https://github.com/bvaughn/react-window-infinite-loader/blob/master/CHANGELOG.md) - [Commits](https://github.com/bvaughn/react-window-infinite-loader/compare/1.0.9...1.0.10) --- updated-dependencies: - dependency-name: react-window-infinite-loader dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- graylog2-web-interface/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graylog2-web-interface/yarn.lock b/graylog2-web-interface/yarn.lock index 6c8de336194d..bf6a753be6a6 100644 --- a/graylog2-web-interface/yarn.lock +++ b/graylog2-web-interface/yarn.lock @@ -13862,9 +13862,9 @@ react-ultimate-pagination@^1.2.0: ultimate-pagination "1.0.0" react-window-infinite-loader@^1.0.8: - version "1.0.9" - resolved "https://registry.yarnpkg.com/react-window-infinite-loader/-/react-window-infinite-loader-1.0.9.tgz#d861c03d5cbc550e2f185371af820fd22d46c099" - integrity sha512-5Hg89IdU4Vrp0RT8kZYKeTIxWZYhNkVXeI1HbKo01Vm/Z7qztDvXljwx16sMzsa9yapRJQW3ODZfMUw38SOWHw== + version "1.0.10" + resolved "https://registry.yarnpkg.com/react-window-infinite-loader/-/react-window-infinite-loader-1.0.10.tgz#30aa264c6b2cc6d41153a65377e337cb83c9bdca" + integrity sha512-NO/csdHlxjWqA2RJZfzQgagAjGHspbO2ik9GtWZb0BY1Nnapq0auG8ErI+OhGCzpjYJsCYerqUlK6hkq9dfAAA== react-window@^1.8.2: version "1.8.11" From cfa43bf04e80fad03c8431bf768481508bb225e0 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Fri, 31 Jan 2025 09:54:05 +0100 Subject: [PATCH 27/56] Consistent Number Formatting in Data Table & Number Visualization. (#21401) * Consistent Number Formatting in Data Table & Number Visualization. * Improving typing/fixing linter hints. * Using one fractional digit. * Adjusting tests. --- .../src/util/NumberFormatting.test.ts | 73 ++++++++++++------- .../src/util/NumberFormatting.ts | 27 ++++--- .../views/components/SearchResult.test.tsx | 2 +- .../components/TypeSpecificValue.test.tsx | 2 +- .../fieldtypes/PercentageField.test.tsx | 2 +- .../highlighting/PossiblyHighlight.tsx | 8 +- .../components/messagelist/FormatNumber.ts | 21 ------ .../visualizations/number/Trend.test.tsx | 10 +-- .../visualizations/number/Trend.tsx | 8 +- .../utils/__tests__/fixtures.ts | 1 + .../utils/formatValueWithUnitLabel.ts | 4 +- .../visualizations/utils/unitConverters.ts | 4 - 12 files changed, 85 insertions(+), 77 deletions(-) delete mode 100644 graylog2-web-interface/src/views/components/messagelist/FormatNumber.ts diff --git a/graylog2-web-interface/src/util/NumberFormatting.test.ts b/graylog2-web-interface/src/util/NumberFormatting.test.ts index dacc4b74e3c6..efa588289408 100644 --- a/graylog2-web-interface/src/util/NumberFormatting.test.ts +++ b/graylog2-web-interface/src/util/NumberFormatting.test.ts @@ -16,50 +16,71 @@ */ import { formatNumber, formatPercentage, formatTrend } from './NumberFormatting'; +// eslint-disable-next-line jest/valid-expect +const expectFormattedNumber = (num: number) => expect(formatNumber(num)); +// eslint-disable-next-line jest/valid-expect +const expectFormattedTrend = (num: number, options?: Parameters[1]) => expect(formatTrend(num, options)); +// eslint-disable-next-line jest/valid-expect +const expectFormattedPercentage = (num: number) => expect(formatPercentage(num / 100)); + describe('NumberFormatting', () => { describe('formatNumber', () => { it('formats with 2 fraction digits by default', () => { - expect(formatNumber(42.23)).toEqual('42.23'); - expect(formatNumber(42)).toEqual('42'); - expect(formatNumber(137.991)).toEqual('137.99'); - expect(formatNumber(137.999)).toEqual('138'); - expect(formatNumber(137.111)).toEqual('137.11'); - expect(formatNumber(137.115)).toEqual('137.12'); + expectFormattedNumber(42.23).toEqual('42.2'); + expectFormattedNumber(42).toEqual('42'); + expectFormattedNumber(137.991).toEqual('138'); + expectFormattedNumber(137.999).toEqual('138'); + expectFormattedNumber(137.111).toEqual('137.1'); + expectFormattedNumber(137.115).toEqual('137.1'); + expectFormattedNumber(0.23).toEqual('0.23'); + }); + + it('uses more fraction digits for very small values', () => { + expectFormattedNumber(0.023).toEqual('0.023'); + expectFormattedNumber(0.0236).toEqual('0.024'); + expectFormattedNumber(0.000818).toEqual('0.00082'); }); }); describe('formatTrend', () => { it('does show sign', () => { - expect(formatTrend(42.23)).toEqual('+42.23'); - expect(formatTrend(-42)).toEqual('-42'); - expect(formatTrend(-137.991)).toEqual('-137.99'); - expect(formatTrend(137.999)).toEqual('+138'); - expect(formatTrend(-137.111)).toEqual('-137.11'); - expect(formatTrend(137.115)).toEqual('+137.12'); - expect(formatTrend(0)).toEqual('0'); + expectFormattedTrend(42.23).toEqual('+42.2'); + expectFormattedTrend(-42).toEqual('-42'); + expectFormattedTrend(-137.991).toEqual('-138'); + expectFormattedTrend(137.999).toEqual('+138'); + expectFormattedTrend(-137.111).toEqual('-137.1'); + expectFormattedTrend(137.115).toEqual('+137.1'); + expectFormattedTrend(0).toEqual('0'); }); it('does show percentage', () => { const options = { percentage: true }; - expect(formatTrend(42.23 / 100, options)).toEqual('+42.23%'); - expect(formatTrend(-42 / 100, options)).toEqual('-42.00%'); - expect(formatTrend(-137.991 / 100, options)).toEqual('-137.99%'); - expect(formatTrend(137.999 / 100, options)).toEqual('+138.00%'); - expect(formatTrend(-137.111 / 100, options)).toEqual('-137.11%'); - expect(formatTrend(137.115 / 100, options)).toEqual('+137.12%'); - expect(formatTrend(0 / 100, options)).toEqual('0.00%'); + expectFormattedTrend(42.23 / 100, options).toEqual('+42.2%'); + expectFormattedTrend(-42 / 100, options).toEqual('-42.0%'); + expectFormattedTrend(-137.991 / 100, options).toEqual('-138.0%'); + expectFormattedTrend(137.999 / 100, options).toEqual('+138.0%'); + expectFormattedTrend(-137.111 / 100, options).toEqual('-137.1%'); + expectFormattedTrend(137.115 / 100, options).toEqual('+137.1%'); + expectFormattedTrend(0 / 100, options).toEqual('0.0%'); }); }); describe('formatPercentage', () => { it('formats with 2 fraction digits by default', () => { - expect(formatPercentage(42.23 / 100)).toEqual('42.23%'); - expect(formatPercentage(42 / 100)).toEqual('42.00%'); - expect(formatPercentage(137.991 / 100)).toEqual('137.99%'); - expect(formatPercentage(137.999 / 100)).toEqual('138.00%'); - expect(formatPercentage(137.111 / 100)).toEqual('137.11%'); - expect(formatPercentage(137.115 / 100)).toEqual('137.12%'); + expectFormattedPercentage(42.23).toEqual('42.2%'); + expectFormattedPercentage(42).toEqual('42.0%'); + expectFormattedPercentage(137.991).toEqual('138.0%'); + expectFormattedPercentage(137.999).toEqual('138.0%'); + expectFormattedPercentage(137.111).toEqual('137.1%'); + expectFormattedPercentage(137.115).toEqual('137.1%'); + expectFormattedPercentage(0.684).toEqual('0.68%'); + }); + + it('uses more fraction digits for very small values', () => { + expectFormattedPercentage(0.023).toEqual('0.023%'); + expectFormattedPercentage(0.0236).toEqual('0.024%'); + expectFormattedPercentage(0.000818).toEqual('0.00082%'); }); }); }); diff --git a/graylog2-web-interface/src/util/NumberFormatting.ts b/graylog2-web-interface/src/util/NumberFormatting.ts index bc04bcd899e2..e92e491ee933 100644 --- a/graylog2-web-interface/src/util/NumberFormatting.ts +++ b/graylog2-web-interface/src/util/NumberFormatting.ts @@ -16,22 +16,31 @@ */ type Options = { signDisplay?: 'auto' | 'always' | 'exceptZero', - maximumFractionDigits?: number, - minimumFractionDigits?: number, + digits?: number, + minimumDigits?: number, }; -const defaultOptions = { - maximumFractionDigits: 2, -} as const; +const desiredFractionDigits = 1; const defaultPercentageOptions = { - ...defaultOptions, - minimumFractionDigits: 2, + minimumFractionDigits: desiredFractionDigits, style: 'percent', } as const; -export const formatNumber = (num: number, options: Options = {}) => new Intl.NumberFormat(undefined, { ...defaultOptions, ...options }).format(num); -export const formatPercentage = (num: number, options: Options = {}) => new Intl.NumberFormat(undefined, { ...defaultPercentageOptions, ...options }).format(num); +const exponent = (s: string | number) => Number(Number(s).toExponential().split('e')[1]); + +const fractionDigitsFor = (s: string | number, defaultDigits: number) => { + const e = exponent(s); + + return e <= (-1 * defaultDigits) + ? (-1 * e) + 1 + : defaultDigits; +}; + +const format = (num: number, options: Intl.NumberFormatOptions) => new Intl.NumberFormat(undefined, options).format(num); + +export const formatNumber = (num: number, { digits, ...options }: Options = {}) => format(num, { minimumFractionDigits: options.minimumDigits, maximumFractionDigits: fractionDigitsFor(num, digits ?? desiredFractionDigits), ...options }); +export const formatPercentage = (num: number, { digits, ...options }: Options = {}) => format(num, { ...defaultPercentageOptions, maximumFractionDigits: fractionDigitsFor(num * 100, digits ?? desiredFractionDigits), ...options }); type TrendOptions = { percentage?: boolean, diff --git a/graylog2-web-interface/src/views/components/SearchResult.test.tsx b/graylog2-web-interface/src/views/components/SearchResult.test.tsx index b2dcf34690d8..d4ff71f29665 100644 --- a/graylog2-web-interface/src/views/components/SearchResult.test.tsx +++ b/graylog2-web-interface/src/views/components/SearchResult.test.tsx @@ -14,7 +14,7 @@ * along with this program. If not, see * . */ -import React from 'react'; +import * as React from 'react'; import { act } from 'react'; import { render } from 'wrappedTestingLibrary'; diff --git a/graylog2-web-interface/src/views/components/TypeSpecificValue.test.tsx b/graylog2-web-interface/src/views/components/TypeSpecificValue.test.tsx index 4aee78b84841..2dedbb837c69 100644 --- a/graylog2-web-interface/src/views/components/TypeSpecificValue.test.tsx +++ b/graylog2-web-interface/src/views/components/TypeSpecificValue.test.tsx @@ -24,7 +24,7 @@ import useFeature from 'hooks/useFeature'; jest.mock('hooks/useFeature'); -describe('SearchResult', () => { +describe('TypeSpecificValue', () => { beforeEach(() => { asMock(useFeature).mockReturnValue(true); }); diff --git a/graylog2-web-interface/src/views/components/fieldtypes/PercentageField.test.tsx b/graylog2-web-interface/src/views/components/fieldtypes/PercentageField.test.tsx index e18d10fc5361..06a05d8fb266 100644 --- a/graylog2-web-interface/src/views/components/fieldtypes/PercentageField.test.tsx +++ b/graylog2-web-interface/src/views/components/fieldtypes/PercentageField.test.tsx @@ -22,6 +22,6 @@ import PercentageField from './PercentageField'; describe('PercentageField', () => { it('does not show very small values as `NaN%`', async () => { render(); - await screen.findByText('0.00%'); + await screen.findByText('0.00000027%'); }); }); diff --git a/graylog2-web-interface/src/views/components/highlighting/PossiblyHighlight.tsx b/graylog2-web-interface/src/views/components/highlighting/PossiblyHighlight.tsx index a722e2072d94..59b7beb7d365 100644 --- a/graylog2-web-interface/src/views/components/highlighting/PossiblyHighlight.tsx +++ b/graylog2-web-interface/src/views/components/highlighting/PossiblyHighlight.tsx @@ -23,8 +23,8 @@ import StringUtils from 'util/StringUtils'; import { DEFAULT_HIGHLIGHT_COLOR } from 'views/Constants'; import { isFunction } from 'views/logic/aggregationbuilder/Series'; import type HighlightingColor from 'views/logic/views/formatting/highlighting/HighlightingColor'; +import { formatNumber } from 'util/NumberFormatting'; -import formatNumber from '../messagelist/FormatNumber'; import isNumeric from '../messagelist/IsNumeric'; export type HighlightRange = { @@ -34,12 +34,12 @@ export type HighlightRange = { type Ranges = { [key: string]: Array }; -const highlight = (value: any, idx: number, style = {}) => {value}; +const highlight = (value: any, idx: number, style: React.CSSProperties = {}) => {value}; type Props = { color?: HighlightingColor field: string, - value?: any, + value: string | number, highlightRanges?: Ranges }; @@ -54,7 +54,7 @@ function highlightCompleteValue(ranges: Array, value) { return start === 0 && length === stringifiedValue.length; } -const shouldBeFormatted = (field: string, value: any) => isFunction(field) && isNumeric(value); +const shouldBeFormatted = (field: string, value: any): value is number => isFunction(field) && isNumeric(value); const PossiblyHighlight = ({ color = DEFAULT_HIGHLIGHT_COLOR, field, value, highlightRanges = {} }: Props) => { const theme = useTheme(); diff --git a/graylog2-web-interface/src/views/components/messagelist/FormatNumber.ts b/graylog2-web-interface/src/views/components/messagelist/FormatNumber.ts deleted file mode 100644 index 9a52e25a84d7..000000000000 --- a/graylog2-web-interface/src/views/components/messagelist/FormatNumber.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import { formatNumber as _formatNumber } from 'util/NumberFormatting'; - -const formatNumber = (value: number): string => _formatNumber(value, { maximumFractionDigits: 7 }); - -export default formatNumber; diff --git a/graylog2-web-interface/src/views/components/visualizations/number/Trend.test.tsx b/graylog2-web-interface/src/views/components/visualizations/number/Trend.test.tsx index 66f8c738502d..803ff8079386 100644 --- a/graylog2-web-interface/src/views/components/visualizations/number/Trend.test.tsx +++ b/graylog2-web-interface/src/views/components/visualizations/number/Trend.test.tsx @@ -41,19 +41,19 @@ describe('Trend', () => { it('shows relative delta as percentage', async () => { renderTrend({ previous: 23 }); - expect(await findTrend()).toMatch(/\+82.61%/); + expect(await findTrend()).toMatch(/\+82.6%/); }); it('shows absolute delta if values are equal', async () => { renderTrend(); - expect(await findTrend()).toMatch(/\+0/); + expect(await findTrend()).toMatch(/^0 \//); }); it('shows relative delta as percentage if values are equal', async () => { renderTrend(); - expect(await findTrend()).toMatch(/\+0%/); + expect(await findTrend()).toMatch(/0\.0%/); }); it('shows negative absolute delta', async () => { @@ -65,7 +65,7 @@ describe('Trend', () => { it('shows negative relative delta as percentage', async () => { renderTrend({ current: 23 }); - expect(await findTrend()).toMatch(/-45.24%/); + expect(await findTrend()).toMatch(/-45.2%/); }); it('shows adequate results if previous value is 0', async () => { @@ -83,7 +83,7 @@ describe('Trend', () => { it('shows adequate results if current value is 0', async () => { renderTrend({ current: 0, previous: 42 }); - expect(await findTrend()).toMatch(/-42 \/ -100%/); + expect(await findTrend()).toMatch(/-42 \/ -100\.0%/); }); it('shows adequate results if current value is NaN', async () => { diff --git a/graylog2-web-interface/src/views/components/visualizations/number/Trend.tsx b/graylog2-web-interface/src/views/components/visualizations/number/Trend.tsx index c632d99b32f4..4470c758d896 100644 --- a/graylog2-web-interface/src/views/components/visualizations/number/Trend.tsx +++ b/graylog2-web-interface/src/views/components/visualizations/number/Trend.tsx @@ -17,7 +17,6 @@ import * as React from 'react'; import type { DefaultTheme } from 'styled-components'; import styled, { css } from 'styled-components'; -import numeral from 'numeral'; import Icon from 'components/common/Icon'; import type { TrendPreference } from 'views/logic/aggregationbuilder/visualizations/NumberVisualizationConfig'; @@ -28,6 +27,7 @@ import { } from 'views/components/visualizations/utils/unitConverters'; import formatValueWithUnitLabel from 'views/components/visualizations/utils/formatValueWithUnitLabel'; import getUnitTextLabel from 'views/components/visualizations/utils/getUnitTextLabel'; +import { formatTrend } from 'util/NumberFormatting'; type TrendDirection = 'good' | 'bad' | 'neutral'; @@ -35,6 +35,7 @@ type Props = { current: number, previous: number | undefined | null, trendPreference: TrendPreference, + // eslint-disable-next-line react/require-default-props unit?: FieldUnit, }; @@ -143,8 +144,8 @@ const Trend = React.forwardRef(({ current, previous, tre const backgroundTrend = _trendDirection(differenceConverted, trendPreference); const trendIcon = _trendIcon(differenceConverted); - const absoluteDifference = Number.isFinite(differenceConverted) ? `${numeral(differenceConverted).format('+0,0[.]0[000]')}${unitAbbrevString}` : '--'; - const relativeDifference = Number.isFinite(differencePercent) ? numeral(differencePercent).format('+0[.]0[0]%') : '--'; + const absoluteDifference = Number.isFinite(differenceConverted) ? `${formatTrend(differenceConverted)}${unitAbbrevString}` : '--'; + const relativeDifference = Number.isFinite(differencePercent) ? formatTrend(differencePercent, { percentage: true }) : '--'; return ( @@ -157,5 +158,6 @@ const Trend = React.forwardRef(({ current, previous, tre ); }); +Trend.displayName = 'Trend'; export default Trend; diff --git a/graylog2-web-interface/src/views/components/visualizations/utils/__tests__/fixtures.ts b/graylog2-web-interface/src/views/components/visualizations/utils/__tests__/fixtures.ts index 255c44104348..ac52589ffa1a 100644 --- a/graylog2-web-interface/src/views/components/visualizations/utils/__tests__/fixtures.ts +++ b/graylog2-web-interface/src/views/components/visualizations/utils/__tests__/fixtures.ts @@ -380,6 +380,7 @@ export const layoutsFor4axis = { autoshift: true, fixedrange: true, gridcolor: '#000', + overlaying: undefined, position: 0, rangemode: 'tozero', side: 'left', diff --git a/graylog2-web-interface/src/views/components/visualizations/utils/formatValueWithUnitLabel.ts b/graylog2-web-interface/src/views/components/visualizations/utils/formatValueWithUnitLabel.ts index e45e81d51cad..c87313410650 100644 --- a/graylog2-web-interface/src/views/components/visualizations/utils/formatValueWithUnitLabel.ts +++ b/graylog2-web-interface/src/views/components/visualizations/utils/formatValueWithUnitLabel.ts @@ -15,9 +15,9 @@ * . */ -import { DECIMAL_PLACES } from 'views/components/visualizations/Constants'; import getUnitTextLabel from 'views/components/visualizations/utils/getUnitTextLabel'; +import { formatNumber } from 'util/NumberFormatting'; -const formatValueWithUnitLabel = (value: number | string, abbrev: string) => `${Number(value).toFixed(DECIMAL_PLACES)} ${getUnitTextLabel(abbrev)}`; +const formatValueWithUnitLabel = (value: number | string, abbrev: string) => `${formatNumber(Number(value), { minimumDigits: 1 })} ${getUnitTextLabel(abbrev)}`; export default formatValueWithUnitLabel; diff --git a/graylog2-web-interface/src/views/components/visualizations/utils/unitConverters.ts b/graylog2-web-interface/src/views/components/visualizations/utils/unitConverters.ts index 2772c2437a37..e9676de24754 100644 --- a/graylog2-web-interface/src/views/components/visualizations/utils/unitConverters.ts +++ b/graylog2-web-interface/src/views/components/visualizations/utils/unitConverters.ts @@ -18,8 +18,6 @@ import minBy from 'lodash/minBy'; import maxBy from 'lodash/maxBy'; import mapValues from 'lodash/mapValues'; -import get from 'lodash/get'; -import keyBy from 'lodash/keyBy'; import isNumber from 'lodash/isNumber'; import toNumber from 'lodash/toNumber'; @@ -159,5 +157,3 @@ export const convertValueToBaseUnit = (value: number, params: ConversionParams) export const convertValueToUnit: ConvertValueToUnit = (value, fromParams, toParams) => _convertValueToUnit(mappedUnitsFromJSON, value, fromParams, toParams); export const getPrettifiedValue = (value: number, params: ConversionParams) => _getPrettifiedValue(mappedUnitsFromJSON, value, params); export const getBaseUnit = (fieldType: FieldUnitType) => _getBaseUnit(mappedUnitsFromJSON, fieldType); -export const unitsByAbbrev = mapValues(mappedUnitsFromJSON, (list) => keyBy(list, 'abbrev')); -export const getUnitInfo = (unitType: FieldUnitType, abbrev: string) => get(unitsByAbbrev, [unitType, abbrev]); From f839a9300b0c22d34b8659923d8a05b31b419620 Mon Sep 17 00:00:00 2001 From: Florian Petersen <188503754+fpetersen-gl@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:00:44 +0100 Subject: [PATCH 28/56] Provide endpoint for token usage overview page (#21315) * Initial commit for providing an overview of token usages * Add id's for user and token, also inject interface instead of implementation to TokenUsageResource and deal with errors while parsing a search-query. * Added some tests * apidoc * Removed unused methods * Added license header * Fix build errors * Made TokenUsage a record-class * Add changelog * Flipped names of TokenUsage and TokenUsageDTO; corrected allowedValues in Resource. * Corrected allowedValues in Resource. Again. This time it should work(tm). * Renamed TokenUsage to AccessTokenEntity and restructured things a bit. --------- Co-authored-by: Matthias Oesterheld <33032967+moesterheld@users.noreply.github.com> --- changelog/unreleased/issue-21321.toml | 5 + .../bindings/PersistenceServicesBindings.java | 3 + .../rest/models/tokenusage/TokenUsageDTO.java | 52 ++++ .../rest/resources/RestResourcesModule.java | 5 +- .../tokenusage/TokenUsageResource.java | 102 ++++++++ .../org/graylog2/security/AccessToken.java | 4 + .../graylog2/security/AccessTokenEntity.java | 98 ++++++++ .../graylog2/security/AccessTokenImpl.java | 19 +- .../graylog2/security/AccessTokenService.java | 10 +- .../security/AccessTokenServiceImpl.java | 12 +- .../PaginatedAccessTokenEntityService.java | 45 ++++ .../shared/security/RestPermissions.java | 1 + .../shared/tokenusage/TokenUsageService.java | 44 ++++ .../tokenusage/TokenUsageServiceImpl.java | 114 +++++++++ .../tokenusage/TokenUsageResourceTest.java | 78 ++++++ .../security/AccessTokenServiceImplTest.java | 6 +- .../AccessTokenEntityServiceImplTest.java | 230 ++++++++++++++++++ 17 files changed, 820 insertions(+), 8 deletions(-) create mode 100644 changelog/unreleased/issue-21321.toml create mode 100644 graylog2-server/src/main/java/org/graylog2/rest/models/tokenusage/TokenUsageDTO.java create mode 100644 graylog2-server/src/main/java/org/graylog2/rest/resources/tokenusage/TokenUsageResource.java create mode 100644 graylog2-server/src/main/java/org/graylog2/security/AccessTokenEntity.java create mode 100644 graylog2-server/src/main/java/org/graylog2/security/PaginatedAccessTokenEntityService.java create mode 100644 graylog2-server/src/main/java/org/graylog2/shared/tokenusage/TokenUsageService.java create mode 100644 graylog2-server/src/main/java/org/graylog2/tokenusage/TokenUsageServiceImpl.java create mode 100644 graylog2-server/src/test/java/org/graylog2/rest/resources/tokenusage/TokenUsageResourceTest.java create mode 100644 graylog2-server/src/test/java/org/graylog2/tokenusage/AccessTokenEntityServiceImplTest.java diff --git a/changelog/unreleased/issue-21321.toml b/changelog/unreleased/issue-21321.toml new file mode 100644 index 000000000000..43698954c920 --- /dev/null +++ b/changelog/unreleased/issue-21321.toml @@ -0,0 +1,5 @@ +type = "added" +message = "Added overview-page for access-tokens, accessible by admins." + +issues = ["21321", "21396"] +pulls = ["21315"] diff --git a/graylog2-server/src/main/java/org/graylog2/bindings/PersistenceServicesBindings.java b/graylog2-server/src/main/java/org/graylog2/bindings/PersistenceServicesBindings.java index 3dd2cd247d53..9136fd378ad1 100644 --- a/graylog2-server/src/main/java/org/graylog2/bindings/PersistenceServicesBindings.java +++ b/graylog2-server/src/main/java/org/graylog2/bindings/PersistenceServicesBindings.java @@ -51,10 +51,12 @@ import org.graylog2.security.AccessTokenServiceImpl; import org.graylog2.security.MongoDBSessionService; import org.graylog2.security.MongoDBSessionServiceImpl; +import org.graylog2.shared.tokenusage.TokenUsageService; import org.graylog2.shared.users.UserManagementService; import org.graylog2.shared.users.UserService; import org.graylog2.system.activities.SystemMessageService; import org.graylog2.system.activities.SystemMessageServiceImpl; +import org.graylog2.tokenusage.TokenUsageServiceImpl; import org.graylog2.users.UserManagementServiceImpl; import org.graylog2.users.UserServiceImpl; @@ -75,6 +77,7 @@ protected void configure() { OptionalBinder.newOptionalBinder(binder(), UserManagementService.class) .setDefault().to(UserManagementServiceImpl.class); bind(AccessTokenService.class).to(AccessTokenServiceImpl.class).asEagerSingleton(); + bind(TokenUsageService.class).to(TokenUsageServiceImpl.class).asEagerSingleton(); bind(MongoDBSessionService.class).to(MongoDBSessionServiceImpl.class).asEagerSingleton(); bind(InputStatusService.class).to(MongoInputStatusService.class).asEagerSingleton(); bind(EntityListPreferencesService.class).to(EntityListPreferencesServiceImpl.class); diff --git a/graylog2-server/src/main/java/org/graylog2/rest/models/tokenusage/TokenUsageDTO.java b/graylog2-server/src/main/java/org/graylog2/rest/models/tokenusage/TokenUsageDTO.java new file mode 100644 index 000000000000..6d1849cd2a4e --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/rest/models/tokenusage/TokenUsageDTO.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.rest.models.tokenusage; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.graylog.autovalue.WithBeanGetter; +import org.joda.time.DateTime; + +import javax.annotation.Nullable; + +@WithBeanGetter +public record TokenUsageDTO( + @JsonProperty("token_id") String tokenId, + @JsonProperty("username") String username, + @JsonProperty("user_id") String userId, + @JsonProperty("token_name") String tokenName, + @Nullable @JsonProperty("created_at") DateTime createdAt, + @JsonProperty("last_access") DateTime lastAccess, + @JsonProperty("user_is_external") boolean userIsExternal, + @JsonProperty("auth_backend") String authBackend) { + + public static TokenUsageDTO create(@JsonProperty("token_id") String tokenId, + @JsonProperty("username") String username, + @JsonProperty("user_id") String userId, + @JsonProperty("token_name") String tokenName, + @Nullable @JsonProperty("created_at") DateTime createdAt, + @JsonProperty("last_access") DateTime lastAccess, + @JsonProperty("user_is_external") boolean userIsExternal, + @Nullable @JsonProperty("auth_backend") String authBackend) { + return new TokenUsageDTO(tokenId, username, userId, + tokenName, + createdAt, + lastAccess, + userIsExternal, + authBackend); + } + +} diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/RestResourcesModule.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/RestResourcesModule.java index af93cb11607b..253404fd43d8 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/RestResourcesModule.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/RestResourcesModule.java @@ -18,10 +18,10 @@ import org.graylog.plugins.views.search.engine.monitoring.data.histogram.rest.HistogramResponseWriter; import org.graylog.plugins.views.storage.migration.RemoteReindexResource; -import org.graylog.security.rest.ClientCertResource; import org.graylog.security.rest.CAResource; import org.graylog.security.rest.CertificateRenewalResource; import org.graylog.security.rest.CertificatesResource; +import org.graylog.security.rest.ClientCertResource; import org.graylog2.Configuration; import org.graylog2.contentstream.rest.ContentStreamResource; import org.graylog2.plugin.inject.Graylog2Module; @@ -106,6 +106,7 @@ import org.graylog2.rest.resources.system.outputs.OutputResource; import org.graylog2.rest.resources.system.processing.ClusterProcessingStatusResource; import org.graylog2.rest.resources.system.processing.SystemProcessingStatusResource; +import org.graylog2.rest.resources.tokenusage.TokenUsageResource; import org.graylog2.rest.resources.tools.ContainsStringTesterResource; import org.graylog2.rest.resources.tools.GrokTesterResource; import org.graylog2.rest.resources.tools.JsonTesterResource; @@ -171,6 +172,8 @@ protected void configure() { addSystemRestResource(CAResource.class); addSystemRestResource(ClientCertResource.class); addSystemRestResource(CertificatesResource.class); + + addSystemRestResource(TokenUsageResource.class); } private void addDebugResources() { diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/tokenusage/TokenUsageResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/tokenusage/TokenUsageResource.java new file mode 100644 index 000000000000..69231a013fd2 --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/tokenusage/TokenUsageResource.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.rest.resources.tokenusage; + +import com.codahale.metrics.annotation.Timed; +import com.google.common.collect.ImmutableMap; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import jakarta.inject.Inject; +import jakarta.ws.rs.BadRequestException; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DefaultValue; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.MediaType; +import org.apache.shiro.authz.annotation.RequiresAuthentication; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.graylog2.database.PaginatedList; +import org.graylog2.rest.models.PaginatedResponse; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.rest.models.tokenusage.TokenUsageDTO; +import org.graylog2.search.SearchQuery; +import org.graylog2.search.SearchQueryField; +import org.graylog2.search.SearchQueryParser; +import org.graylog2.security.AccessTokenEntity; +import org.graylog2.shared.rest.resources.RestResource; +import org.graylog2.shared.security.RestPermissions; +import org.graylog2.shared.tokenusage.TokenUsageService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.graylog2.shared.rest.documentation.generator.Generator.CLOUD_VISIBLE; + +@RequiresAuthentication +@Path("/token_usage") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Api(value = "Token-Usage", description = "Listing usage of Tokens", tags = {CLOUD_VISIBLE}) +public class TokenUsageResource extends RestResource { + private static final Logger LOG = LoggerFactory.getLogger(TokenUsageResource.class); + + private final TokenUsageService tokenUsageService; + private final SearchQueryParser searchQueryParser; + + protected static final ImmutableMap SEARCH_FIELD_MAPPING = ImmutableMap.builder() + .put(AccessTokenEntity.FIELD_ID, SearchQueryField.create("_id", SearchQueryField.Type.OBJECT_ID)) + .put(AccessTokenEntity.FIELD_USERNAME, SearchQueryField.create(AccessTokenEntity.FIELD_USERNAME)) + .put(AccessTokenEntity.FIELD_NAME, SearchQueryField.create(AccessTokenEntity.FIELD_NAME)) + .build(); + + @Inject + public TokenUsageResource(TokenUsageService tokenUsageService) { + this.tokenUsageService = tokenUsageService; + this.searchQueryParser = new SearchQueryParser(AccessTokenEntity.FIELD_NAME, SEARCH_FIELD_MAPPING); + } + + @GET + @Timed + @Path("/paginated") + @ApiOperation(value = "Get paginated list of tokens") + @RequiresPermissions(RestPermissions.TOKEN_USAGE_READ) + @Produces(MediaType.APPLICATION_JSON) + public PaginatedResponse getPage(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, + @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, + @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query, + @ApiParam(name = "sort", + value = "The field to sort the result on", + required = true, + allowableValues = "username,NAME") + @DefaultValue(AccessTokenEntity.FIELD_NAME) @QueryParam("sort") String sort, + @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") + @DefaultValue("asc") @QueryParam("order") SortOrder order) { + LOG.debug("Incoming request to list token usages{}, on page {} with {} items per page.", query.isEmpty() ? "" : " matching " + query, page, perPage); + final SearchQuery searchQuery; + try { + searchQuery = searchQueryParser.parse(query); + } catch (IllegalArgumentException e) { + throw new BadRequestException("Invalid argument in search query: " + e.getMessage()); + } + final PaginatedList tokenUsages = tokenUsageService.loadTokenUsage(page, perPage, searchQuery, sort, order); + LOG.debug("Found {} token usages for incoming request. Converting to response.", tokenUsages.size()); + return PaginatedResponse.create("token_usage", tokenUsages, query); + } + +} diff --git a/graylog2-server/src/main/java/org/graylog2/security/AccessToken.java b/graylog2-server/src/main/java/org/graylog2/security/AccessToken.java index 8a4184b90000..93bbee62b4a5 100644 --- a/graylog2-server/src/main/java/org/graylog2/security/AccessToken.java +++ b/graylog2-server/src/main/java/org/graylog2/security/AccessToken.java @@ -23,8 +23,12 @@ * @author Dennis Oelkers */ public interface AccessToken extends Persisted { + DateTime getCreatedAt(); + DateTime getLastAccess(); + DateTime getExpiresAt(); + String getUserName(); void setUserName(String userName); diff --git a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenEntity.java b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenEntity.java new file mode 100644 index 000000000000..a238713f8d13 --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenEntity.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.security; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import org.graylog2.database.MongoEntity; +import org.joda.time.DateTime; +import org.mongojack.Id; +import org.mongojack.ObjectId; + +import javax.annotation.Nullable; + +@AutoValue +@JsonDeserialize(builder = AccessTokenEntity.Builder.class) +public abstract class AccessTokenEntity implements MongoEntity { + + public static final String FIELD_ID = "_id"; + public static final String FIELD_USERNAME = "username"; + public static final String FIELD_NAME = "NAME"; + + public static final String FIELD_CREATED_AT = "created_at"; + public static final String FIELD_LAST_ACCESS = "last_access"; + public static final String FIELD_EXPIRES_AT = "expires_at"; + + @Id + @ObjectId + @Nullable + @Override + @JsonProperty(FIELD_ID) + public abstract String id(); + + @JsonProperty(FIELD_USERNAME) + public abstract String userName(); + + @JsonProperty(FIELD_NAME) + public abstract String name(); + + @Nullable + @JsonProperty(FIELD_CREATED_AT) + public abstract DateTime createdAt(); + + @JsonProperty(FIELD_LAST_ACCESS) + public abstract DateTime lastAccess(); + + @Nullable + @JsonProperty(FIELD_EXPIRES_AT) + public abstract DateTime expiresAt(); + + @AutoValue.Builder + @JsonIgnoreProperties({"token", "token_type"}) + public abstract static class Builder { + + @JsonCreator + public static AccessTokenEntity.Builder create() { + return new AutoValue_AccessTokenEntity.Builder(); + } + + @Id + @ObjectId + @JsonProperty(FIELD_ID) + public abstract Builder id(String id); + + @JsonProperty(FIELD_USERNAME) + public abstract Builder userName(String username); + + @JsonProperty(FIELD_NAME) + public abstract Builder name(String name); + + @JsonProperty(FIELD_CREATED_AT) + public abstract Builder createdAt(@Nullable DateTime createdAt); + + @JsonProperty(FIELD_LAST_ACCESS) + public abstract Builder lastAccess(DateTime lastAccess); + + @JsonProperty(FIELD_EXPIRES_AT) + public abstract Builder expiresAt(@Nullable DateTime expiresAt); + + public abstract AccessTokenEntity build(); + } +} diff --git a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenImpl.java b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenImpl.java index 79fd31335f26..e398eb7e4b8d 100644 --- a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenImpl.java @@ -51,7 +51,9 @@ public int getIntValue() { public static final String TOKEN_TYPE = "token_type"; public static final String NAME = "NAME"; + public static final String CREATED_AT = "created_at"; public static final String LAST_ACCESS = "last_access"; + public static final String EXPIRES_AT = "expires_at"; public AccessTokenImpl(Map fields) { super(fields); @@ -75,10 +77,19 @@ public Map getEmbeddedValidations(String key) { return null; } + @Override + public DateTime getCreatedAt() { + return getDateTimeField(CREATED_AT); + } + @Override public DateTime getLastAccess() { - final Object o = fields.get(LAST_ACCESS); - return (DateTime) o; + return getDateTimeField(LAST_ACCESS); + } + + @Override + public DateTime getExpiresAt() { + return getDateTimeField(EXPIRES_AT); } @Override @@ -112,4 +123,8 @@ public String getName() { public void setName(String name) { fields.put(NAME, name); } + + private DateTime getDateTimeField(String fileName) { + return (DateTime) fields.get(fileName); + } } diff --git a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenService.java b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenService.java index 525e1789978c..5fb1ef2797ce 100644 --- a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenService.java +++ b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenService.java @@ -16,8 +16,11 @@ */ package org.graylog2.security; +import org.graylog2.database.PaginatedList; import org.graylog2.plugin.database.PersistedService; import org.graylog2.plugin.database.ValidationException; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.search.SearchQuery; import org.joda.time.DateTime; import javax.annotation.Nullable; @@ -28,13 +31,11 @@ * @author Dennis Oelkers */ public interface AccessTokenService extends PersistedService { - @SuppressWarnings("unchecked") AccessToken load(String token); @Nullable AccessToken loadById(String id); - @SuppressWarnings("unchecked") List loadAll(String username); AccessToken create(String username, String name); @@ -45,5 +46,8 @@ public interface AccessTokenService extends PersistedService { int deleteAllForUser(String username); - public void setLastAccessCache(long duration, TimeUnit unit); + void setLastAccessCache(long duration, TimeUnit unit); + + PaginatedList findPaginated(SearchQuery searchQuery, int page, + int perPage, String sortField, SortOrder order); } diff --git a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java index 48aa7276b71e..046ad5685248 100644 --- a/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/security/AccessTokenServiceImpl.java @@ -30,10 +30,13 @@ import org.apache.commons.lang3.StringUtils; import org.bson.types.ObjectId; import org.graylog2.database.MongoConnection; +import org.graylog2.database.PaginatedList; import org.graylog2.database.PersistedServiceImpl; import org.graylog2.database.utils.MongoUtils; import org.graylog2.plugin.Tools; import org.graylog2.plugin.database.ValidationException; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.search.SearchQuery; import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,12 +62,14 @@ public class AccessTokenServiceImpl extends PersistedServiceImpl implements Acce private static final Logger LOG = LoggerFactory.getLogger(AccessTokenServiceImpl.class); private static final SecureRandom RANDOM = new SecureRandom(); + private final PaginatedAccessTokenEntityService paginatedAccessTokenEntityService; private final AccessTokenCipher cipher; private LoadingCache lastAccessCache; @Inject - public AccessTokenServiceImpl(MongoConnection mongoConnection, AccessTokenCipher accessTokenCipher) { + public AccessTokenServiceImpl(MongoConnection mongoConnection, PaginatedAccessTokenEntityService paginatedAccessTokenEntityService, AccessTokenCipher accessTokenCipher) { super(mongoConnection); + this.paginatedAccessTokenEntityService = paginatedAccessTokenEntityService; this.cipher = accessTokenCipher; setLastAccessCache(30, TimeUnit.SECONDS); @@ -218,4 +223,9 @@ public DateTime load(String id) throws Exception { } }); } + + @Override + public PaginatedList findPaginated(SearchQuery searchQuery, int page, int perPage, String sortField, SortOrder order) { + return this.paginatedAccessTokenEntityService.findPaginated(searchQuery, page, perPage, sortField, order); + } } diff --git a/graylog2-server/src/main/java/org/graylog2/security/PaginatedAccessTokenEntityService.java b/graylog2-server/src/main/java/org/graylog2/security/PaginatedAccessTokenEntityService.java new file mode 100644 index 000000000000..cb0327dd5887 --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/security/PaginatedAccessTokenEntityService.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.security; + +import com.mongodb.client.MongoCollection; +import jakarta.inject.Inject; +import org.graylog2.database.MongoCollections; +import org.graylog2.database.PaginatedList; +import org.graylog2.database.pagination.MongoPaginationHelper; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.search.SearchQuery; + +public class PaginatedAccessTokenEntityService { + private static final String COLLECTION_NAME = AccessTokenImpl.COLLECTION_NAME; + private final MongoPaginationHelper paginationHelper; + + @Inject + public PaginatedAccessTokenEntityService(MongoCollections mongoCollections) { + MongoCollection collection = mongoCollections.collection(COLLECTION_NAME, AccessTokenEntity.class); + paginationHelper = mongoCollections.paginationHelper(collection); + } + + public PaginatedList findPaginated(SearchQuery searchQuery, int page, + int perPage, String sortField, SortOrder order) { + return paginationHelper + .filter(searchQuery.toBson()) + .sort(order.toBsonSort(sortField)) + .perPage(perPage) + .page(page); + } +} diff --git a/graylog2-server/src/main/java/org/graylog2/shared/security/RestPermissions.java b/graylog2-server/src/main/java/org/graylog2/shared/security/RestPermissions.java index 4f116f5d2a2d..5e766711a4a1 100644 --- a/graylog2-server/src/main/java/org/graylog2/shared/security/RestPermissions.java +++ b/graylog2-server/src/main/java/org/graylog2/shared/security/RestPermissions.java @@ -162,6 +162,7 @@ public class RestPermissions implements PluginPermissions { public static final String THREADS_DUMP = "threads:dump"; public static final String PROCESSBUFFER_DUMP = "processbuffer:dump"; public static final String THROUGHPUT_READ = "throughput:read"; + public static final String TOKEN_USAGE_READ = "tokenusage:read"; public static final String TYPE_MAPPINGS_CREATE = "typemappings:create"; public static final String TYPE_MAPPINGS_DELETE = "typemappings:delete"; public static final String TYPE_MAPPINGS_EDIT = "typemappings:edit"; diff --git a/graylog2-server/src/main/java/org/graylog2/shared/tokenusage/TokenUsageService.java b/graylog2-server/src/main/java/org/graylog2/shared/tokenusage/TokenUsageService.java new file mode 100644 index 000000000000..d9f855c22a0a --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/shared/tokenusage/TokenUsageService.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.shared.tokenusage; + +import org.graylog2.database.PaginatedList; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.rest.models.tokenusage.TokenUsageDTO; +import org.graylog2.search.SearchQuery; + +public interface TokenUsageService { + + /** + * Loads entries of {@link TokenUsageDTO} for the given parameters. + *

    + * The idea is that all tokens are listed, enriched with information about its owner. This provides an overview of + * possibly expired tokens or those whose owner doesn't exist on the system anymore. + * + * @param page The page to load, starting at 1. + * @param perPage Number of items per page. + * @param searchQuery The search to perform - only items matching this query are returned. + * @param sort Sort by this given field. + * @param order The order of sorting ({@code asc} or {@code desc}. + * @return A page of matching {@link TokenUsageDTO}, sorted by the specified field and order. + */ + PaginatedList loadTokenUsage(int page, + int perPage, + SearchQuery searchQuery, + String sort, + SortOrder order); +} diff --git a/graylog2-server/src/main/java/org/graylog2/tokenusage/TokenUsageServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/tokenusage/TokenUsageServiceImpl.java new file mode 100644 index 000000000000..8d6111f0fce0 --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/tokenusage/TokenUsageServiceImpl.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.tokenusage; + +import jakarta.annotation.Nonnull; +import jakarta.inject.Inject; +import org.graylog.security.authservice.AuthServiceBackendDTO; +import org.graylog.security.authservice.DBAuthServiceBackendService; +import org.graylog2.database.PaginatedList; +import org.graylog2.plugin.database.users.User; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.rest.models.tokenusage.TokenUsageDTO; +import org.graylog2.search.SearchQuery; +import org.graylog2.security.AccessTokenEntity; +import org.graylog2.security.AccessTokenService; +import org.graylog2.shared.tokenusage.TokenUsageService; +import org.graylog2.shared.users.UserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class TokenUsageServiceImpl implements TokenUsageService { + private static final Logger LOG = LoggerFactory.getLogger(TokenUsageServiceImpl.class); + + private final AccessTokenService accessTokenService; + private final UserService userService; + private final DBAuthServiceBackendService dbAuthServiceBackendService; + + @Inject + public TokenUsageServiceImpl(AccessTokenService accessTokenService, UserService userService, DBAuthServiceBackendService dbAuthServiceBackendService) { + this.accessTokenService = accessTokenService; + this.userService = userService; + this.dbAuthServiceBackendService = dbAuthServiceBackendService; + } + + @Override + public PaginatedList loadTokenUsage(int page, + int perPage, + SearchQuery searchQuery, + String sort, + SortOrder order) { + final PaginatedList currentPage = this.accessTokenService.findPaginated(searchQuery, page, perPage, sort, order); + if (LOG.isInfoEnabled()) { + final String logSearch = searchQuery.getQueryMap().isEmpty() ? "" : ", query \"" + searchQuery.getQueryString() + "\", sort by " + sort + ", ordering " + order; + LOG.info("Loaded {} tokens in page {} containing max {} items{}.", currentPage.pagination().count(), page, perPage, logSearch); + } + + //We loaded all matching tokens, let's now extract the respective users having created these tokens and (if applicable) their authentication-backend: + final Map usersOfThisPage = currentPage.stream() + .map(AccessTokenEntity::userName) + .distinct() + .map(userService::load) + .filter(Objects::nonNull) + .collect(Collectors.toMap(User::getName, Function.identity())); + LOG.debug("Found {} distinct users for current page of access tokens.", usersOfThisPage.size()); + + //Collect all auth-service ids of the current page's users: + final Set allAuthServiceIds = usersOfThisPage.values().stream() + .map(User::getAuthServiceId) + .filter(Objects::nonNull) + .collect(Collectors.toUnmodifiableSet()); + LOG.debug("Found {} distinct authentication services used by users of current page of access tokens.", allAuthServiceIds.size()); + + //Load corresponding auth-services and extract the title: + final Map authServiceIdToTitle = dbAuthServiceBackendService.streamByIds(allAuthServiceIds) + .collect(Collectors.toMap(AuthServiceBackendDTO::id, AuthServiceBackendDTO::title)); + + //Build up the resulting objects: + final List tokenUsage = currentPage.stream() + .map(usage -> toDTO(usage, usersOfThisPage, authServiceIdToTitle)) + .toList(); + + return new PaginatedList<>(tokenUsage, currentPage.pagination().total(), page, perPage); + + } + + @Nonnull + private TokenUsageDTO toDTO(AccessTokenEntity dto, Map usersOfThisPage, Map authServiceIdToTitle) { + final String username = dto.userName(); + final User user = usersOfThisPage.get(username); + final boolean isExternal = user.isExternalUser(); + final String authBackend; + if (isExternal) { + authBackend = Optional.ofNullable(authServiceIdToTitle.get(user.getAuthServiceId())) + .orElse("<" + user.getAuthServiceId() + "> (DELETED)"); + } else { + //User is not external, so this field stays blank. + authBackend = ""; + } + + return TokenUsageDTO.create(dto.id(), username, user.getId(), dto.name(), dto.createdAt(), dto.lastAccess(), isExternal, authBackend); + } +} diff --git a/graylog2-server/src/test/java/org/graylog2/rest/resources/tokenusage/TokenUsageResourceTest.java b/graylog2-server/src/test/java/org/graylog2/rest/resources/tokenusage/TokenUsageResourceTest.java new file mode 100644 index 000000000000..4ad407500b33 --- /dev/null +++ b/graylog2-server/src/test/java/org/graylog2/rest/resources/tokenusage/TokenUsageResourceTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.rest.resources.tokenusage; + +import org.graylog2.database.PaginatedList; +import org.graylog2.rest.models.PaginatedResponse; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.rest.models.tokenusage.TokenUsageDTO; +import org.graylog2.search.SearchQuery; +import org.graylog2.security.AccessTokenEntity; +import org.graylog2.shared.tokenusage.TokenUsageService; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.internal.matchers.apachecommons.ReflectionEquals; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class TokenUsageResourceTest { + public static final int PAGE = 1; + public static final int PER_PAGE = 10; + + + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private TokenUsageService tokenUsageService; + + private TokenUsageResource testee; + + @Before + public void setUp() { + testee = new TokenUsageResource(tokenUsageService); + } + + @Test + public void callingEndpointCallsService() { + final String query = ""; + when(tokenUsageService.loadTokenUsage(eq(PAGE), eq(PER_PAGE), any(SearchQuery.class), eq(AccessTokenEntity.FIELD_NAME), eq(SortOrder.ASCENDING))) + .thenReturn(mkPaginatedList()); + + final PaginatedResponse actual = testee.getPage(PAGE, PER_PAGE, query, AccessTokenEntity.FIELD_NAME, SortOrder.ASCENDING); + + final PaginatedResponse expected = PaginatedResponse.create("token_usage", mkPaginatedList(), query); + //Sorry. the PaginatedResponse doesn't have a proper equals(): + assertTrue(new ReflectionEquals(expected).matches(actual)); + + verify(tokenUsageService, times(1)).loadTokenUsage(eq(PAGE), eq(PER_PAGE), any(SearchQuery.class), eq(AccessTokenEntity.FIELD_NAME), eq(SortOrder.ASCENDING)); + } + + private PaginatedList mkPaginatedList() { + return PaginatedList.emptyList(PAGE, PER_PAGE); + } +} diff --git a/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java b/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java index 430211aadcba..53102574d08c 100644 --- a/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java +++ b/graylog2-server/src/test/java/org/graylog2/security/AccessTokenServiceImplTest.java @@ -32,6 +32,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.mockito.Mock; import java.util.List; import java.util.concurrent.TimeUnit; @@ -49,6 +50,9 @@ public class AccessTokenServiceImplTest { @Rule public final MongoDBInstance mongodb = MongoDBInstance.createForClass(); + @Mock + private PaginatedAccessTokenEntityService paginatedAccessTokenEntityService; + private AccessTokenService accessTokenService; @Before @@ -58,7 +62,7 @@ public void setupService() { when(accessTokenCipher.encrypt(anyString())).then(inv -> StringUtils.reverse(inv.getArgument(0))); when(accessTokenCipher.decrypt(anyString())).then(inv -> StringUtils.reverse(inv.getArgument(0))); - this.accessTokenService = new AccessTokenServiceImpl(mongodb.mongoConnection(), accessTokenCipher); + this.accessTokenService = new AccessTokenServiceImpl(mongodb.mongoConnection(), paginatedAccessTokenEntityService, accessTokenCipher); } @After diff --git a/graylog2-server/src/test/java/org/graylog2/tokenusage/AccessTokenEntityServiceImplTest.java b/graylog2-server/src/test/java/org/graylog2/tokenusage/AccessTokenEntityServiceImplTest.java new file mode 100644 index 000000000000..96f77ade949c --- /dev/null +++ b/graylog2-server/src/test/java/org/graylog2/tokenusage/AccessTokenEntityServiceImplTest.java @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +package org.graylog2.tokenusage; + +import com.google.common.collect.ImmutableSet; +import org.bson.types.ObjectId; +import org.graylog.security.authservice.AuthServiceBackendConfig; +import org.graylog.security.authservice.AuthServiceBackendDTO; +import org.graylog.security.authservice.DBAuthServiceBackendService; +import org.graylog2.database.PaginatedList; +import org.graylog2.plugin.Tools; +import org.graylog2.plugin.cluster.ClusterConfigService; +import org.graylog2.plugin.database.users.User; +import org.graylog2.rest.models.SortOrder; +import org.graylog2.rest.models.tokenusage.TokenUsageDTO; +import org.graylog2.search.SearchQuery; +import org.graylog2.security.AccessTokenEntity; +import org.graylog2.security.AccessTokenService; +import org.graylog2.security.PasswordAlgorithmFactory; +import org.graylog2.security.hashing.SHA1HashPasswordAlgorithm; +import org.graylog2.shared.security.Permissions; +import org.graylog2.shared.security.RestPermissions; +import org.graylog2.shared.users.UserService; +import org.graylog2.users.UserImpl; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class AccessTokenEntityServiceImplTest { + private static final int PAGE = 1; + private static final int PER_PAGE = 10; + private static final String SORT = AccessTokenEntity.FIELD_NAME; + private static final SortOrder SORT_ORDER = SortOrder.ASCENDING; + + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private AccessTokenService accessTokenService; + @Mock + private UserService userService; + @Mock + private DBAuthServiceBackendService dbAuthServiceBackendService; + + private TokenUsageServiceImpl testee; + private UserFactory userFactory; + private Object[] allMocks; + + @Before + public void setUp() { + testee = new TokenUsageServiceImpl(accessTokenService, userService, dbAuthServiceBackendService); + userFactory = new AccessTokenEntityServiceImplTest.UserFactory( + new Permissions(ImmutableSet.of(new RestPermissions()))); + allMocks = new Object[]{accessTokenService, userService, dbAuthServiceBackendService}; + } + + @Test + public void noAvailableTokensReturnEmptyResponse() { + when(accessTokenService.findPaginated(any(SearchQuery.class), eq(PAGE), eq(PER_PAGE), eq(SORT), eq(SORT_ORDER))) + .thenReturn(PaginatedList.emptyList(PAGE, PER_PAGE)); + when(dbAuthServiceBackendService.streamByIds(Collections.emptySet())).thenReturn(Stream.empty()); + final PaginatedList expected = new PaginatedList<>(Collections.emptyList(), 0, PAGE, PER_PAGE); + + final PaginatedList actual = testee.loadTokenUsage(PAGE, PER_PAGE, new SearchQuery(""), SORT, SORT_ORDER); + assertEquals(expected, actual); + + verify(accessTokenService).findPaginated(any(SearchQuery.class), eq(PAGE), eq(PER_PAGE), eq(SORT), eq(SORT_ORDER)); + verify(dbAuthServiceBackendService).streamByIds(Collections.emptySet()); + verifyNoMoreInteractions(allMocks); + } + + @Test + public void onlyLocalUsersDoesntHitTheAuthBackendService() { + final AccessTokenEntity token1 = mkToken(1); + final AccessTokenEntity token2 = mkToken(2); + final User user1 = mkUser(1, false); + final User user2 = mkUser(2, false); + when(accessTokenService.findPaginated(any(SearchQuery.class), eq(PAGE), eq(PER_PAGE), eq(SORT), eq(SORT_ORDER))) + .thenReturn(new PaginatedList<>(List.of(token1, token2), 2, PAGE, PER_PAGE)); + when(userService.load("userName1")).thenReturn(user1); + when(userService.load("userName2")).thenReturn(user2); + when(dbAuthServiceBackendService.streamByIds(Collections.emptySet())).thenReturn(Stream.empty()); + final PaginatedList expected = new PaginatedList<>(List.of(mkTokenUsage(token1, user1, null), mkTokenUsage(token2, user2, null)), 2, PAGE, PER_PAGE); + + final PaginatedList actual = testee.loadTokenUsage(PAGE, PER_PAGE, new SearchQuery(""), SORT, SORT_ORDER); + assertEquals(expected, actual); + + verify(accessTokenService).findPaginated(any(SearchQuery.class), eq(PAGE), eq(PER_PAGE), eq(SORT), eq(SORT_ORDER)); + verify(userService).load("userName1"); + verify(userService).load("userName2"); + verify(dbAuthServiceBackendService).streamByIds(Collections.emptySet()); + verifyNoMoreInteractions(allMocks); + } + + @Test + public void tokensFromExternalUsersShowAuthBackends() { + final AccessTokenEntity token1 = mkToken(1); + final AccessTokenEntity token2 = mkToken(2); + final User user1 = mkUser(1, true); + final User user2 = mkUser(2, true); + final AuthServiceBackendDTO authService1 = mkAuthService(); + when(accessTokenService.findPaginated(any(SearchQuery.class), eq(PAGE), eq(PER_PAGE), eq(SORT), eq(SORT_ORDER))) + .thenReturn(new PaginatedList<>(List.of(token1, token2), 2, PAGE, PER_PAGE)); + when(userService.load("userName1")).thenReturn(user1); + when(userService.load("userName2")).thenReturn(user2); + when(dbAuthServiceBackendService.streamByIds(Set.of("auth-backend-id1", "auth-backend-id2"))).thenReturn(Stream.of(mkAuthService())); + final PaginatedList expected = new PaginatedList<>(List.of(mkTokenUsage(token1, user1, authService1.title()), mkTokenUsage(token2, user2, " (DELETED)")), 2, PAGE, PER_PAGE); + + final PaginatedList actual = testee.loadTokenUsage(PAGE, PER_PAGE, new SearchQuery(""), SORT, SORT_ORDER); + assertEquals(expected, actual); + + verify(accessTokenService).findPaginated(any(SearchQuery.class), eq(PAGE), eq(PER_PAGE), eq(SORT), eq(SORT_ORDER)); + verify(userService).load("userName1"); + verify(userService).load("userName2"); + verify(dbAuthServiceBackendService).streamByIds(Set.of("auth-backend-id1", "auth-backend-id2")); + verifyNoMoreInteractions(allMocks); + } + + + //Just some helper methods + + + private AccessTokenEntity mkToken(int number) { + return AccessTokenEntity.Builder.create() + .id("tokenId" + number) + .name("tokenName" + number) + .userName("userName" + number) + .createdAt(Tools.nowUTC().minusDays(number)) + .lastAccess(Tools.nowUTC()) + .expiresAt(Tools.nowUTC().plusDays(number)) + .build(); + } + + private User mkUser(int number, boolean external) { + final ObjectId id = new ObjectId(number, number); + final Map fields = new HashMap<>(3); + fields.put(UserImpl.EXTERNAL_USER, external); + fields.put(UserImpl.USERNAME, "userName" + number); + + if (external) { + fields.put(UserImpl.AUTH_SERVICE_ID, "auth-backend-id" + number); + } + return userFactory.create(id, fields); + } + + private AuthServiceBackendDTO mkAuthService() { + return AuthServiceBackendDTO.builder() + .id("auth-backend-id1") + .title("auth-backend-title1") + .config(mock(AuthServiceBackendConfig.class)) + .build(); + } + + private TokenUsageDTO mkTokenUsage(AccessTokenEntity dto, User user, @Nullable String authBackendName) { + final String username = dto.userName(); + final boolean isExternal = user.isExternalUser(); + final String authBackend; + if (isExternal) { + authBackend = Optional.ofNullable(authBackendName) + .orElse("<" + user.getAuthServiceId() + "> (DELETED)"); + } else { + //User is not external, so this field stays empty. + authBackend = ""; + } + + return TokenUsageDTO.create(dto.id(), username, user.getId(), dto.name(), dto.createdAt(), dto.lastAccess(), isExternal, authBackend); + } + + public static class UserFactory implements UserImpl.Factory { + private final Permissions permissions; + private final PasswordAlgorithmFactory passwordAlgorithmFactory; + + public UserFactory(Permissions permissions) { + this.permissions = permissions; + this.passwordAlgorithmFactory = new PasswordAlgorithmFactory(Collections.emptyMap(), + new SHA1HashPasswordAlgorithm("TESTSECRET")); + } + + @Override + public UserImpl create(Map fields) { + return new UserImpl(passwordAlgorithmFactory, permissions, mock(ClusterConfigService.class), fields); + } + + @Override + public UserImpl create(ObjectId id, Map fields) { + return new UserImpl(passwordAlgorithmFactory, permissions, mock(ClusterConfigService.class), id, fields); + } + + // Not used. + @Override + public UserImpl.LocalAdminUser createLocalAdminUser(String adminRoleObjectId) { + return null; + } + } + +} From 4b9477f93b3108f14d237c2c7183d97f9e708f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Fri, 31 Jan 2025 13:19:14 +0100 Subject: [PATCH 29/56] Update tab names in wizard --- .../src/components/inputs/InputSetupWizard/Wizard.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx index 689a44b8c1e2..ae4ab32cb097 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx @@ -62,7 +62,7 @@ const Wizard = ({ show, input, onClose }: Props) => { key: INPUT_WIZARD_STEPS.SETUP_ROUTING, title: ( <> - Setup Routing + Routing ), component: ( @@ -74,7 +74,7 @@ const Wizard = ({ show, input, onClose }: Props) => { key: INPUT_WIZARD_STEPS.START_INPUT, title: ( <> - Start Input + Launch ), component: ( @@ -86,7 +86,7 @@ const Wizard = ({ show, input, onClose }: Props) => { key: INPUT_WIZARD_STEPS.INPUT_DIAGNOSIS, title: ( <> - Input Diagnosis + Diagnosis ), component: ( From 8d81c790bda35cb0d4b001d1a62e645e3f67f768 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Fri, 31 Jan 2025 14:29:44 +0100 Subject: [PATCH 30/56] Adding prettier for code formatting, disabling ESLint formatting rules. (#18325) * Adding prettier + shared config. * Removing formatting rules from ESLint. * Removing formatting rules conflicting with prettier from ESLint preset. * Run `prettier` in auto-fixing job as well. * Fixing typo. * Including `test` & `docs` directories. --- .github/workflows/fix-linter-hints.yml | 5 ++++- graylog2-web-interface/.prettierrc.json | 1 + graylog2-web-interface/package.json | 5 ++++- .../packages/eslint-config-graylog/index.js | 12 +++--------- .../packages/eslint-config-graylog/package.json | 1 + 5 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 graylog2-web-interface/.prettierrc.json diff --git a/.github/workflows/fix-linter-hints.yml b/.github/workflows/fix-linter-hints.yml index 8830a5f46f3e..45971d832a85 100644 --- a/.github/workflows/fix-linter-hints.yml +++ b/.github/workflows/fix-linter-hints.yml @@ -36,6 +36,9 @@ jobs: continue-on-error: true working-directory: graylog2-web-interface run: yarn lint --fix -o /tmp/report.json -f json + - name: Run prettier + working-directory: graylog2-web-interface + run: yarn format - name: Run lint:styles --fix continue-on-error: true working-directory: graylog2-web-interface @@ -54,7 +57,7 @@ jobs: author: Dr. Lint-a-lot branch: fix/linter-hints committer: Dr. Lint-a-lot - commit-message: Running lint --fix + commit-message: Running lint --fix & prettier delete-branch: true - name: Get headRef and SHA of PR diff --git a/graylog2-web-interface/.prettierrc.json b/graylog2-web-interface/.prettierrc.json new file mode 100644 index 000000000000..567aa914522e --- /dev/null +++ b/graylog2-web-interface/.prettierrc.json @@ -0,0 +1 @@ +"@graylog/prettier-config" diff --git a/graylog2-web-interface/package.json b/graylog2-web-interface/package.json index 8a6cb7d975c2..d31bafdb97c9 100644 --- a/graylog2-web-interface/package.json +++ b/graylog2-web-interface/package.json @@ -23,7 +23,8 @@ "lint:styles:path": "stylelint", "lint:changes": "./dev/lintChanges.sh", "test": "jest --maxWorkers=50%", - "check-production-build": "node checkProductionBuild.js" + "check-production-build": "node checkProductionBuild.js", + "format": "prettier --write src test docs" }, "eslintConfig": { "extends": "graylog" @@ -116,6 +117,7 @@ "devDependencies": { "@cfaester/enzyme-adapter-react-18": "0.7.1", "@cyclonedx/webpack-plugin": "^3.9.1", + "@graylog/prettier-config": "^1.0.2", "@types/chroma-js": "^2.1.3", "@types/crossfilter": "0.0.38", "@types/enzyme-adapter-react-16": "^1.0.6", @@ -162,6 +164,7 @@ "less": "^4.1.2", "less-loader": "^12.0.0", "node-fetch": "^2.6.1", + "prettier": "^3.3.3", "puppeteer": "^23.0.2", "react-bootstrap": "0.33.1", "style-loader": "3.3.4", diff --git a/graylog2-web-interface/packages/eslint-config-graylog/index.js b/graylog2-web-interface/packages/eslint-config-graylog/index.js index 6c8e22bb97df..0530a8827df5 100644 --- a/graylog2-web-interface/packages/eslint-config-graylog/index.js +++ b/graylog2-web-interface/packages/eslint-config-graylog/index.js @@ -83,6 +83,7 @@ module.exports = { 'plugin:import/react', 'plugin:jest-formatting/strict', 'plugin:graylog/recommended', + 'prettier', ], plugins: [ 'import', @@ -93,7 +94,6 @@ module.exports = { rules: { 'arrow-body-style': ['error', 'as-needed'], camelcase: 'off', - 'function-paren-newline': 'off', 'import/extensions': 'off', 'import/no-extraneous-dependencies': 'off', 'import/no-unresolved': 'off', @@ -131,18 +131,12 @@ module.exports = { }], }], 'no-underscore-dangle': 'off', - 'object-curly-newline': ['error', { multiline: true, consistent: true }], 'object-shorthand': ['error', 'methods'], 'react/destructuring-assignment': 'off', 'react/forbid-prop-types': 'off', 'react/function-component-definition': 'off', - 'react/jsx-closing-bracket-location': ['warn', 'after-props'], - 'react/jsx-curly-spacing': ['warn', { when: 'never', children: true }], 'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }], - 'react/jsx-first-prop-new-line': ['warn', 'never'], - 'react/jsx-indent-props': ['error', 'first'], 'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }], - 'react/jsx-one-expression-per-line': 'off', 'react/jsx-props-no-spreading': 'off', 'react/prefer-es6-class': 'off', 'react/prefer-stateless-function': 'warn', @@ -172,13 +166,13 @@ module.exports = { }, { blankLine: 'always', - prev: ['block', 'multiline-block-like', 'cjs-export', 'class', 'multiline-expression'], + prev: ['block', 'cjs-export', 'class'], next: '*', }, { blankLine: 'always', prev: '*', - next: ['block', 'multiline-block-like', 'class', 'multiline-expression', 'return'], + next: ['block', 'class', 'return'], }, ], }, diff --git a/graylog2-web-interface/packages/eslint-config-graylog/package.json b/graylog2-web-interface/packages/eslint-config-graylog/package.json index ec701d7e36b7..1f2d9dd1c147 100644 --- a/graylog2-web-interface/packages/eslint-config-graylog/package.json +++ b/graylog2-web-interface/packages/eslint-config-graylog/package.json @@ -20,6 +20,7 @@ "@typescript-eslint/parser": "8.22.0", "eslint": "8.57.0", "eslint-config-airbnb": "19.0.4", + "eslint-config-prettier": "9.1.0", "eslint-import-resolver-webpack": "0.13.10", "eslint-plugin-compat": "4.2.0", "eslint-plugin-graylog": "file:../eslint-plugin-graylog", From ad6dcf6abaac89361ce41e0fcc12e767072ab145 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Fri, 31 Jan 2025 14:46:23 +0100 Subject: [PATCH 31/56] Creating advanced field type for event definition ids. (#21136) * Creating advanced field type for event definition ids. * Adding license header. * Batching Event Definition fetching, indicate missing Event Definitions. * Adding changelog snippet. * Fixing file. --- changelog/unreleased/pr-21136.toml | 4 ++ .../indexer/fieldtypes/FieldTypeMapper.java | 8 ++-- .../views/components/TypeSpecificValue.tsx | 6 ++- .../components/fieldtypes/EventDefinition.tsx | 43 +++++++++++++++++++ .../sidebar/fields/FieldTypeIcon.tsx | 2 + 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/pr-21136.toml create mode 100644 graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx diff --git a/changelog/unreleased/pr-21136.toml b/changelog/unreleased/pr-21136.toml new file mode 100644 index 000000000000..f7d20bdccb16 --- /dev/null +++ b/changelog/unreleased/pr-21136.toml @@ -0,0 +1,4 @@ +type = "a" +message = "Adding advanced field type for event definitions, looking up titles in aggregations and message table." + +pulls = ["21136"] diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java b/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java index 3c1fb4df6b2f..c8aa36f024b4 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java @@ -18,9 +18,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.graylog2.plugin.Message; - import jakarta.inject.Singleton; +import org.graylog.events.event.EventDto; +import org.graylog2.plugin.Message; import java.util.Map; import java.util.Optional; @@ -58,6 +58,7 @@ public class FieldTypeMapper { public static final FieldTypes.Type STREAMS_TYPE = createType("streams", of(PROP_ENUMERABLE)); public static final FieldTypes.Type INPUT_TYPE = createType("input", of(PROP_ENUMERABLE)); public static final FieldTypes.Type NODE_TYPE = createType("node", of(PROP_ENUMERABLE)); + public static final FieldTypes.Type EVENT_DEFINITION_ID_TYPE = createType("event-definition-id", of(PROP_ENUMERABLE)); /** @@ -85,7 +86,8 @@ public class FieldTypeMapper { Message.FIELD_STREAMS, STREAMS_TYPE, Message.FIELD_FAILED_MESSAGE_STREAMS, STREAMS_TYPE, Message.FIELD_GL2_SOURCE_INPUT, INPUT_TYPE, - Message.FIELD_GL2_SOURCE_NODE, NODE_TYPE + Message.FIELD_GL2_SOURCE_NODE, NODE_TYPE, + EventDto.FIELD_EVENT_DEFINITION_ID, EVENT_DEFINITION_ID_TYPE ); /** diff --git a/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx b/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx index c9662fa255da..64c84f9965ca 100644 --- a/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx +++ b/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx @@ -31,6 +31,7 @@ import { UNIT_FEATURE_FLAG } from 'views/components/visualizations/Constants'; import useFeature from 'hooks/useFeature'; import { MISSING_BUCKET_NAME } from 'views/Constants'; import formatValueWithUnitLabel from 'views/components/visualizations/utils/formatValueWithUnitLabel'; +import EventDefinition from 'views/components/fieldtypes/EventDefinition'; import EmptyValue from './EmptyValue'; import type { ValueRendererProps, ValueRenderer } from './messagelist/decoration/ValueRenderer'; @@ -62,7 +63,7 @@ const ValueWithUnitRenderer = ({ value, unit }: { value: number, unit: FieldUnit return {formatValueWithUnitLabel(prettified?.value, prettified.unit.abbrev)}; }; -const FormattedValue = ({ field, value, truncate = false, render = defaultComponent, unit, type }: TypeSpecificValueProps) => { +const FormattedValue = ({ field, value = undefined, truncate = false, render = defaultComponent, unit = undefined, type = undefined }: TypeSpecificValueProps) => { const unitFeatureEnabled = useFeature(UNIT_FEATURE_FLAG); const shouldRenderValueWithUnit = unitFeatureEnabled && unit?.isDefined && value && value !== MISSING_BUCKET_NAME && unitFeatureEnabled; if (shouldRenderValueWithUnit) return ; @@ -70,7 +71,7 @@ const FormattedValue = ({ field, value, truncate = false, render = defaultCompon return _formatValue(field, value, truncate, render, type); }; -const TypeSpecificValue = ({ field, value, render = defaultComponent, type = FieldType.Unknown, truncate = false, unit }: TypeSpecificValueProps) => { +const TypeSpecificValue = ({ field, value = undefined, render = defaultComponent, type = FieldType.Unknown, truncate = false, unit = undefined }: TypeSpecificValueProps) => { const Component = render; if (value === undefined) { @@ -88,6 +89,7 @@ const TypeSpecificValue = ({ field, value, render = defaultComponent, type = Fie case 'node': return ; case 'streams': return ; case 'percentage': return ; + case 'event-definition-id': return ; default: return ; } }; diff --git a/graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx b/graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx new file mode 100644 index 000000000000..889a83714bbd --- /dev/null +++ b/graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 Graylog, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + */ +import * as React from 'react'; +import { create, keyResolver, windowScheduler } from '@yornaath/batshit'; +import { useQuery } from '@tanstack/react-query'; + +import { EventsDefinitions } from '@graylog/server-api'; + +import Spinner from 'components/common/Spinner'; + +const fetchEventDefinition = create({ + fetcher: async (ids: Array) => EventsDefinitions.getById({ event_definition_ids: ids }), + resolver: keyResolver('id'), + scheduler: windowScheduler(10), +}); + +const EventDefinition = ({ value }: { value: string }) => { + const { data: eventDefinition, isLoading } = useQuery(['event-definitions', 'batched', value], () => fetchEventDefinition.fetch(value)); + + if (isLoading) { + return ; + } + + return eventDefinition?.title + ? {eventDefinition.title} + : Missing Event Definition: {value}; +}; + +export default EventDefinition; diff --git a/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx b/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx index 499f704f0f2d..f81ab4a6974e 100644 --- a/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx +++ b/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx @@ -45,6 +45,8 @@ const iconName = (type: string) => { return 'fork_right'; case 'input': return 'cell_tower'; + case 'event-definition-id': + return 'edit_document'; default: return 'help'; } From c24a12ef66a87dae5e09293823b96cf17f77432f Mon Sep 17 00:00:00 2001 From: Maksym Yadlovskyi Date: Fri, 31 Jan 2025 14:56:02 +0100 Subject: [PATCH 32/56] Improving Hotkeys for query input (#21336) * Add a feature flag which hides the Executive Dashboard from the user. * Revert "Add a feature flag which hides the Executive Dashboard from the user." This reverts commit 2bee26679ebe739e518dbf3e0854191d1edb5ce2. * Improving Hotkeys for query input * changelog --- changelog/unreleased/issue-20423.toml | 5 +++++ .../src/components/hotkeys/HotkeyCollectionSection.tsx | 3 +++ graylog2-web-interface/src/contexts/HotkeysProvider.tsx | 3 ++- graylog2-web-interface/src/util/OSUtils.ts | 2 +- .../src/views/components/searchbar/queryinput/QueryInput.tsx | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/issue-20423.toml diff --git a/changelog/unreleased/issue-20423.toml b/changelog/unreleased/issue-20423.toml new file mode 100644 index 000000000000..926db481139a --- /dev/null +++ b/changelog/unreleased/issue-20423.toml @@ -0,0 +1,5 @@ +type = "f" +message = "Fixing keyboard shortcut conflicts for opening query history by changing it to ctrl+space on win and linux os" + +issues = ["20423"] +pulls = ["21336"] diff --git a/graylog2-web-interface/src/components/hotkeys/HotkeyCollectionSection.tsx b/graylog2-web-interface/src/components/hotkeys/HotkeyCollectionSection.tsx index 4f85f991582f..4e62a8e22dd8 100644 --- a/graylog2-web-interface/src/components/hotkeys/HotkeyCollectionSection.tsx +++ b/graylog2-web-interface/src/components/hotkeys/HotkeyCollectionSection.tsx @@ -53,6 +53,9 @@ const KeySeparator = styled.div` const keyMapper = (key: string, isMacOS: boolean) => { const keyMap = { mod: isMacOS ? '⌘' : 'Ctrl', + alt: isMacOS ? '⌥' : 'Alt', + ctrl: isMacOS ? '⌃' : 'Ctrl', + meta: isMacOS ? '⌘' : 'Win', }; return keyMap[key] || key; diff --git a/graylog2-web-interface/src/contexts/HotkeysProvider.tsx b/graylog2-web-interface/src/contexts/HotkeysProvider.tsx index f3685adecc48..793e3fd55fc0 100644 --- a/graylog2-web-interface/src/contexts/HotkeysProvider.tsx +++ b/graylog2-web-interface/src/contexts/HotkeysProvider.tsx @@ -25,6 +25,7 @@ import Immutable from 'immutable'; import type { ScopeName, ActiveHotkeys, HotkeyCollections, Options } from 'contexts/HotkeysContext'; import HotkeysContext from 'contexts/HotkeysContext'; +import { isMacOS } from 'util/OSUtils'; const viewActions = { undo: { keys: 'mod+shift+z', description: 'Undo last action' }, @@ -68,7 +69,7 @@ export const hotKeysCollections: HotkeyCollections = { 'submit-search': { keys: 'return', description: 'Execute the search' }, 'insert-newline': { keys: 'shift+return', description: 'Create a new line' }, 'create-search-filter': { keys: 'alt+return', description: 'Create search filter based on current query' }, - 'show-suggestions': { keys: 'alt+space', description: 'Show suggestions, displays query history when input is empty' }, + 'show-suggestions': { keys: isMacOS() ? 'alt+space' : 'mod+space', description: 'Show suggestions, displays query history when input is empty' }, 'show-history': { keys: 'alt+shift+h', description: 'View your search query history' }, }, }, diff --git a/graylog2-web-interface/src/util/OSUtils.ts b/graylog2-web-interface/src/util/OSUtils.ts index 21d9b3a9708c..b18097275d98 100644 --- a/graylog2-web-interface/src/util/OSUtils.ts +++ b/graylog2-web-interface/src/util/OSUtils.ts @@ -16,4 +16,4 @@ */ // eslint-disable-next-line import/prefer-default-export -export const isMacOS = () => navigator.userAgent.indexOf('Mac OS X') !== -1; +export const isMacOS = () => /Macintosh|MacIntel/.test(navigator.userAgent); diff --git a/graylog2-web-interface/src/views/components/searchbar/queryinput/QueryInput.tsx b/graylog2-web-interface/src/views/components/searchbar/queryinput/QueryInput.tsx index 20bc8ce4d39e..62efd155a480 100644 --- a/graylog2-web-interface/src/views/components/searchbar/queryinput/QueryInput.tsx +++ b/graylog2-web-interface/src/views/components/searchbar/queryinput/QueryInput.tsx @@ -255,7 +255,7 @@ const QueryInput = React.forwardRef(({ }, { name: 'Show completions', - bindKey: { win: 'Alt-Space', mac: 'Alt-Space' }, + bindKey: { win: 'Ctrl-Space', mac: 'Alt-Space' }, exec: async (editor: Editor) => { if (editor.getValue()) { startAutocomplete(editor); From 54ecf1cff87c3cad730191d437e423419bfadefd Mon Sep 17 00:00:00 2001 From: Maksym Yadlovskyi Date: Fri, 31 Jan 2025 15:10:01 +0100 Subject: [PATCH 33/56] Add dependency array to useCreateSavedSearch hook (#21338) * Add a feature flag which hides the Executive Dashboard from the user. * Revert "Add a feature flag which hides the Executive Dashboard from the user." This reverts commit 2bee26679ebe739e518dbf3e0854191d1edb5ce2. * Add dependency array to useCreateSavedSearch hook * changelog --- changelog/unreleased/issue-20465.toml | 5 +++++ .../views/logic/views/UseCreateSavedSearch.ts | 19 +++++++++++-------- .../src/views/pages/StreamSearchPage.test.tsx | 11 ++++++----- .../src/views/pages/StreamSearchPage.tsx | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 changelog/unreleased/issue-20465.toml diff --git a/changelog/unreleased/issue-20465.toml b/changelog/unreleased/issue-20465.toml new file mode 100644 index 000000000000..80bc3da35f75 --- /dev/null +++ b/changelog/unreleased/issue-20465.toml @@ -0,0 +1,5 @@ +type = "f" +message = "Fixed the issue when the streams link in the message table was not working on the streams page." + +issues=["20465"] +pulls = ["21338"] diff --git a/graylog2-web-interface/src/views/logic/views/UseCreateSavedSearch.ts b/graylog2-web-interface/src/views/logic/views/UseCreateSavedSearch.ts index 57ab09a9872b..d6bc718f796f 100644 --- a/graylog2-web-interface/src/views/logic/views/UseCreateSavedSearch.ts +++ b/graylog2-web-interface/src/views/logic/views/UseCreateSavedSearch.ts @@ -21,22 +21,25 @@ import type { ElasticsearchQueryString, TimeRange } from 'views/logic/queries/Qu import ViewGenerator from 'views/logic/views/ViewGenerator'; import type Parameter from 'views/logic/parameters/Parameter'; +type Props = { + streamId?: string | string[], + streamCategory?: string | string[], + timeRange?: TimeRange, + queryString?: ElasticsearchQueryString, + parameters?: Array, +} + +type Deps = Array | []; const useCreateSavedSearch = ({ streamId, streamCategory, timeRange, queryString, parameters, -}:{ - streamId?: string | string[], - streamCategory?: string | string[], - timeRange?: TimeRange, - queryString?: ElasticsearchQueryString, - parameters?: Array, -}) => useMemo( +}:Props, deps: Deps = []) => useMemo( () => ViewGenerator({ type: View.Type.Search, streamId, streamCategory, timeRange, queryString, parameters }), // eslint-disable-next-line react-hooks/exhaustive-deps - [], + deps, ); export default useCreateSavedSearch; diff --git a/graylog2-web-interface/src/views/pages/StreamSearchPage.test.tsx b/graylog2-web-interface/src/views/pages/StreamSearchPage.test.tsx index af500aba9364..9815a4952109 100644 --- a/graylog2-web-interface/src/views/pages/StreamSearchPage.test.tsx +++ b/graylog2-web-interface/src/views/pages/StreamSearchPage.test.tsx @@ -86,19 +86,20 @@ describe('StreamSearchPage', () => { queryString: undefined, streamId: 'stream-id-1', timeRange: undefined, - })); + }, [streamId])); }); - it('should recreate view when streamId passed from props changes', async () => { + it('should rerender hook when streamId passed from props changes', async () => { const { rerender } = render(); await waitFor(() => expect(useCreateSavedSearch).toHaveBeenCalledWith({ queryString: undefined, streamId: 'stream-id-1', timeRange: undefined, - })); + }, [streamId])); - asMock(useParams).mockReturnValue({ streamId: 'stream-id-2' }); + const secondStream = 'stream-id-2'; + asMock(useParams).mockReturnValue({ streamId: secondStream }); rerender(); @@ -106,7 +107,7 @@ describe('StreamSearchPage', () => { queryString: undefined, streamId: 'stream-id-2', timeRange: undefined, - })); + }, [secondStream])); }); describe('loading another view', () => { diff --git a/graylog2-web-interface/src/views/pages/StreamSearchPage.tsx b/graylog2-web-interface/src/views/pages/StreamSearchPage.tsx index 0ae1bebb966a..67f064609f9b 100644 --- a/graylog2-web-interface/src/views/pages/StreamSearchPage.tsx +++ b/graylog2-web-interface/src/views/pages/StreamSearchPage.tsx @@ -35,7 +35,7 @@ const StreamSearchPage = () => { } const { timeRange, queryString } = useSearchURLQueryParams(); - const viewPromise = useCreateSavedSearch({ streamId, timeRange, queryString }); + const viewPromise = useCreateSavedSearch({ streamId, timeRange, queryString }, [streamId]); const view = useCreateSearch(viewPromise); const _loadNewView = useCallback(() => loadNewViewForStream(history, streamId), [history, streamId]); From d4c325e0f44b477f575b284ba4c146a00c68be74 Mon Sep 17 00:00:00 2001 From: Zack King <91903901+kingzacko1@users.noreply.github.com> Date: Fri, 31 Jan 2025 08:18:15 -0600 Subject: [PATCH 34/56] Add SystemEntity caches and new forceUpdate method to ScopedEntityMongoUtils (#21439) --- .../utils/ScopedEntityMongoUtils.java | 14 +++++++++++++ .../org/graylog2/lookup/LookupModule.java | 2 ++ .../graylog2/lookup/LookupTableService.java | 20 ++++++++++++------- .../utils/ScopedEntityMongoUtilsTest.java | 1 + 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/graylog2-server/src/main/java/org/graylog2/database/utils/ScopedEntityMongoUtils.java b/graylog2-server/src/main/java/org/graylog2/database/utils/ScopedEntityMongoUtils.java index 81ab2aaa98e5..79cb2ec09329 100644 --- a/graylog2-server/src/main/java/org/graylog2/database/utils/ScopedEntityMongoUtils.java +++ b/graylog2-server/src/main/java/org/graylog2/database/utils/ScopedEntityMongoUtils.java @@ -97,6 +97,20 @@ public final long forceDelete(String id) { return collection.deleteOne(idEq(id)).getDeletedCount(); } + /** + * Updates an existing entity without checking for mutability. Do not call this method for API requests for the user + * interface. + * + * @param entity ScopedEntity to be updated + * @return the newly updated entity + */ + public T forceUpdate(T entity) { + Objects.requireNonNull(entity.id()); + ensureValidScope(entity); + collection.replaceOne(idEq(Objects.requireNonNull(entity.id())), entity); + return entity; + } + public final boolean isMutable(T scopedEntity) { Objects.requireNonNull(scopedEntity, "Entity must not be null"); diff --git a/graylog2-server/src/main/java/org/graylog2/lookup/LookupModule.java b/graylog2-server/src/main/java/org/graylog2/lookup/LookupModule.java index c2bbd1b2b483..15f3e99f68cb 100644 --- a/graylog2-server/src/main/java/org/graylog2/lookup/LookupModule.java +++ b/graylog2-server/src/main/java/org/graylog2/lookup/LookupModule.java @@ -27,6 +27,7 @@ import org.graylog2.lookup.caches.NullCache; import org.graylog2.lookup.db.DBLookupTableConfigService; import org.graylog2.plugin.inject.Graylog2Module; +import org.graylog2.plugin.lookup.LookupCache; import org.graylog2.plugin.lookup.LookupDataAdapter; import org.graylog2.system.SystemEntity; import org.graylog2.system.urlwhitelist.UrlWhitelistNotificationService; @@ -48,6 +49,7 @@ protected void configure() { bind(LookupTableConfigService.class).to(DBLookupTableConfigService.class).asEagerSingleton(); // Triggering map binder once, so it does not break injection when no instance is bound. MapBinder.newMapBinder(binder(), String.class, LookupDataAdapter.Factory2.class, SystemEntity.class); + MapBinder.newMapBinder(binder(), String.class, LookupCache.Factory.class, SystemEntity.class); serviceBinder().addBinding().to(LookupTableService.class).asEagerSingleton(); installLookupCache(NullCache.NAME, diff --git a/graylog2-server/src/main/java/org/graylog2/lookup/LookupTableService.java b/graylog2-server/src/main/java/org/graylog2/lookup/LookupTableService.java index 8e1806d49f6d..05b3a21fac59 100644 --- a/graylog2-server/src/main/java/org/graylog2/lookup/LookupTableService.java +++ b/graylog2-server/src/main/java/org/graylog2/lookup/LookupTableService.java @@ -23,6 +23,9 @@ import com.google.common.eventbus.Subscribe; import com.google.common.util.concurrent.AbstractIdleService; import com.google.common.util.concurrent.Service; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Singleton; import org.graylog2.lookup.dto.CacheDto; import org.graylog2.lookup.dto.DataAdapterDto; import org.graylog2.lookup.dto.LookupTableDto; @@ -43,11 +46,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; - -import jakarta.inject.Inject; -import jakarta.inject.Named; -import jakarta.inject.Singleton; - import java.util.Collection; import java.util.Collections; import java.util.List; @@ -84,6 +82,7 @@ public class LookupTableService extends AbstractIdleService { private final Map adapterFactories; private final Map adapterFactories2; private final Map systemAdapterFactories; + private final Map systemCacheFactories; private final ScheduledExecutorService scheduler; private final EventBus eventBus; private final LookupDataAdapterRefreshService adapterRefreshService; @@ -102,6 +101,7 @@ public LookupTableService(LookupTableConfigService configService, Map adapterFactories, Map adapterFactories2, @SystemEntity Map systemAdapterFactories, + @SystemEntity Map systemCacheFactories, @Named("daemonScheduler") ScheduledExecutorService scheduler, EventBus eventBus) { this.configService = configService; @@ -109,6 +109,7 @@ public LookupTableService(LookupTableConfigService configService, this.adapterFactories = adapterFactories; this.adapterFactories2 = adapterFactories2; this.systemAdapterFactories = systemAdapterFactories; + this.systemCacheFactories = systemCacheFactories; this.scheduler = scheduler; this.eventBus = eventBus; this.adapterRefreshService = new LookupDataAdapterRefreshService(scheduler, liveTables); @@ -451,12 +452,17 @@ private Map createCaches(Collection cacheDtos) private LookupCache createCache(CacheDto dto) { try { final LookupCache.Factory factory = cacheFactories.get(dto.config().type()); - if (factory == null) { + final LookupCache.Factory systemFactory = systemCacheFactories.get(dto.config().type()); + final LookupCache cache; + if (factory != null) { + cache = factory.create(dto.id(), dto.name(), dto.config()); + } else if (systemFactory != null) { + cache = systemFactory.create(dto.id(), dto.name(), dto.config()); + } else { LOG.warn("Unable to load cache {} of type {}, missing a factory. Is a required plugin missing?", dto.name(), dto.config().type()); // TODO system notification return null; } - final LookupCache cache = factory.create(dto.id(), dto.name(), dto.config()); cache.addListener(new LoggingServiceListener( "Cache", String.format(Locale.ENGLISH, "%s/%s [@%s]", dto.name(), dto.id(), objectId(cache)), diff --git a/graylog2-server/src/test/java/org/graylog2/database/utils/ScopedEntityMongoUtilsTest.java b/graylog2-server/src/test/java/org/graylog2/database/utils/ScopedEntityMongoUtilsTest.java index fc0abaac8678..72713f02ddc6 100644 --- a/graylog2-server/src/test/java/org/graylog2/database/utils/ScopedEntityMongoUtilsTest.java +++ b/graylog2-server/src/test/java/org/graylog2/database/utils/ScopedEntityMongoUtilsTest.java @@ -78,6 +78,7 @@ void testImmutableScope() { assertThatThrownBy(() -> scopedEntityMongoUtils.deleteById(id)) .isExactlyInstanceOf(IllegalArgumentException.class); assertThat(scopedEntityMongoUtils.forceDelete(id)).isEqualTo(1L); + assertThat(scopedEntityMongoUtils.forceUpdate(updated)).isEqualTo(updated); } @Test From cbf20a75b89868aff834c94f08eb9693fd6ab7fa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:25:19 +0100 Subject: [PATCH 35/56] Bump nl.jqno.equalsverifier:equalsverifier from 3.18.1 to 3.18.2 (#21497) Bumps [nl.jqno.equalsverifier:equalsverifier](https://github.com/jqno/equalsverifier) from 3.18.1 to 3.18.2. - [Release notes](https://github.com/jqno/equalsverifier/releases) - [Changelog](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md) - [Commits](https://github.com/jqno/equalsverifier/compare/equalsverifier-3.18.1...equalsverifier-3.18.2) --- updated-dependencies: - dependency-name: nl.jqno.equalsverifier:equalsverifier dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 54376b2ec99f..a30143b1ed28 100644 --- a/pom.xml +++ b/pom.xml @@ -191,7 +191,7 @@ 3.27.3 2.2.0 4.2.2 - 3.18.1 + 3.18.2 1.5 4.13.2 5.11.4 From 190b715b5f86baf4a4fc66d533f5d1edff39f9f8 Mon Sep 17 00:00:00 2001 From: Maksym Yadlovskyi Date: Fri, 31 Jan 2025 15:31:26 +0100 Subject: [PATCH 36/56] Add definition id when render summaryComponent in event definition (#21359) * Add definition id when render summaryComponent in event definition * changelog --- changelog/unreleased/pr-21359.toml | 5 +++++ .../event-definition-form/EventDefinitionSummary.tsx | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/pr-21359.toml diff --git a/changelog/unreleased/pr-21359.toml b/changelog/unreleased/pr-21359.toml new file mode 100644 index 000000000000..f9728c836250 --- /dev/null +++ b/changelog/unreleased/pr-21359.toml @@ -0,0 +1,5 @@ +type = "f" +message = "Fix error when clicking the Replay search link in event definition summary in edit modal on security events page" + +issues = ["graylog-plugin-enterprise#9289"] +pulls = ["21359"] diff --git a/graylog2-web-interface/src/components/event-definitions/event-definition-form/EventDefinitionSummary.tsx b/graylog2-web-interface/src/components/event-definitions/event-definition-form/EventDefinitionSummary.tsx index bf5844ff13af..b6ece0b8a505 100644 --- a/graylog2-web-interface/src/components/event-definitions/event-definition-form/EventDefinitionSummary.tsx +++ b/graylog2-web-interface/src/components/event-definitions/event-definition-form/EventDefinitionSummary.tsx @@ -38,7 +38,7 @@ import commonStyles from '../common/commonStyles.css'; import { SYSTEM_EVENT_DEFINITION_TYPE } from '../constants'; type Props = { - eventDefinition: Omit, + eventDefinition: EventDefinition, notifications: Array, validation?: { errors: { @@ -91,12 +91,13 @@ const EventDefinitionSummary = ({ eventDefinition, notifications, validation, cu return PluginStore.exports(name).find((edt) => edt.type === type); }; - const renderCondition = (config: EventDefinition['config']) => { + const renderCondition = (config: EventDefinition['config'], definitionId: string) => { const conditionPlugin = getPlugin('eventDefinitionTypes', config.type); const component = (conditionPlugin?.summaryComponent ? React.createElement(conditionPlugin.summaryComponent, { config, currentUser, + definitionId, }) :

    Condition plugin {config.type} does not provide a summary.

    ); @@ -252,7 +253,7 @@ const EventDefinitionSummary = ({ eventDefinition, notifications, validation, cu {!isSystemEventDefinition && ( - {renderCondition(eventDefinition.config)} + {renderCondition(eventDefinition.config, eventDefinition.id)} )}
    From d4d10b73662d2baa6226ecaeddb5d342fce37839 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 08:15:45 +0100 Subject: [PATCH 37/56] Bump jakarta.validation:jakarta.validation-api from 3.1.0 to 3.1.1 (#21518) Bumps [jakarta.validation:jakarta.validation-api](https://github.com/jakartaee/validation) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/jakartaee/validation/releases) - [Commits](https://github.com/jakartaee/validation/compare/3.1.0...3.1.1) --- updated-dependencies: - dependency-name: jakarta.validation:jakarta.validation-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a30143b1ed28..3b9c8b38e8e3 100644 --- a/pom.xml +++ b/pom.xml @@ -178,7 +178,7 @@ 8.3.0 7.0.2 3.2.1 - 3.1.0 + 3.1.1 1.5.6-9 9.2.1 0.3.2 From 812fc0462ed70e15d9f5e169062739a083ba321f Mon Sep 17 00:00:00 2001 From: Florian Petersen <188503754+fpetersen-gl@users.noreply.github.com> Date: Mon, 3 Feb 2025 09:19:05 +0100 Subject: [PATCH 38/56] New configuration to (dis-)allow external users create access tokens (#21438) * Introduce new configuration for allowing external users to create an access token (or not). Starting with graylog 6.2, this is set to not allow. * Add changelog * Clean up test a bit --- changelog/unreleased/issue-21322.toml | 5 + .../rest/resources/users/UsersResource.java | 61 +++++----- .../org/graylog2/users/UserConfiguration.java | 17 ++- .../resources/users/UsersResourceTest.java | 110 +++++++++++++++--- 4 files changed, 147 insertions(+), 46 deletions(-) create mode 100644 changelog/unreleased/issue-21322.toml diff --git a/changelog/unreleased/issue-21322.toml b/changelog/unreleased/issue-21322.toml new file mode 100644 index 000000000000..b9773596fca4 --- /dev/null +++ b/changelog/unreleased/issue-21322.toml @@ -0,0 +1,5 @@ +type="a" +message="Added new Configuration to define default for allowing access tokens for external users." + +issues=["21322"] +pulls=["21438"] diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java index 5bc563b229dc..a43972c3e617 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/users/UsersResource.java @@ -27,6 +27,27 @@ import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import jakarta.inject.Inject; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.BadRequestException; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.DefaultValue; +import jakarta.ws.rs.ForbiddenException; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.InternalServerErrorException; +import jakarta.ws.rs.NotFoundException; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.apache.commons.lang.StringUtils; import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -42,6 +63,7 @@ import org.graylog2.audit.AuditEventTypes; import org.graylog2.audit.jersey.AuditEvent; import org.graylog2.database.PaginatedList; +import org.graylog2.plugin.cluster.ClusterConfigService; import org.graylog2.plugin.database.ValidationException; import org.graylog2.plugin.database.users.User; import org.graylog2.rest.models.PaginatedResponse; @@ -73,37 +95,13 @@ import org.graylog2.users.PaginatedUserService; import org.graylog2.users.RoleService; import org.graylog2.users.RoleServiceImpl; +import org.graylog2.users.UserConfiguration; import org.graylog2.users.UserOverviewDTO; import org.joda.time.DateTimeZone; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nullable; - -import jakarta.inject.Inject; - -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - -import jakarta.ws.rs.BadRequestException; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.DELETE; -import jakarta.ws.rs.DefaultValue; -import jakarta.ws.rs.ForbiddenException; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.InternalServerErrorException; -import jakarta.ws.rs.NotFoundException; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.PUT; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; - import java.net.URI; import java.util.ArrayList; import java.util.Collection; @@ -147,6 +145,7 @@ public class UsersResource extends RestResource { private final UserSessionTerminationService sessionTerminationService; private final DefaultSecurityManager securityManager; private final GlobalAuthServiceConfig globalAuthServiceConfig; + private final ClusterConfigService clusterConfigService; protected static final ImmutableMap SEARCH_FIELD_MAPPING = ImmutableMap.builder() .put(UserOverviewDTO.FIELD_ID, SearchQueryField.create("_id", SearchQueryField.Type.OBJECT_ID)) @@ -162,7 +161,7 @@ public UsersResource(UserManagementService userManagementService, RoleService roleService, MongoDBSessionService sessionService, UserSessionTerminationService sessionTerminationService, DefaultSecurityManager securityManager, - GlobalAuthServiceConfig globalAuthServiceConfig) { + GlobalAuthServiceConfig globalAuthServiceConfig, ClusterConfigService clusterConfigService) { this.userManagementService = userManagementService; this.accessTokenService = accessTokenService; this.roleService = roleService; @@ -172,6 +171,7 @@ public UsersResource(UserManagementService userManagementService, this.securityManager = securityManager; this.searchQueryParser = new SearchQueryParser(UserOverviewDTO.FIELD_FULL_NAME, SEARCH_FIELD_MAPPING); this.globalAuthServiceConfig = globalAuthServiceConfig; + this.clusterConfigService = clusterConfigService; } /** @@ -720,7 +720,9 @@ public Token generateNewToken( @ApiParam(name = "JSON Body", value = "Placeholder because POST requests should have a body. Set to '{}', the content will be ignored.", defaultValue = "{}") String body) { final User user = loadUserById(userId); final String username = user.getName(); - if (!isPermitted(USERS_TOKENCREATE, username)) { + + if (!isPermitted(USERS_TOKENCREATE, username) || + isExternalUserDenied(user)) { throw new ForbiddenException("Not allowed to create tokens for user " + username); } final AccessToken accessToken = accessTokenService.create(user.getName(), name); @@ -755,6 +757,11 @@ public void revokeToken( } } + private boolean isExternalUserDenied(User user) { + return user.isExternalUser() + && !clusterConfigService.getOrDefault(UserConfiguration.class, UserConfiguration.DEFAULT_VALUES).allowAccessTokenForExternalUsers(); + } + private User loadUserById(String userId) { final User user = userManagementService.loadById(userId); if (user == null) { diff --git a/graylog2-server/src/main/java/org/graylog2/users/UserConfiguration.java b/graylog2-server/src/main/java/org/graylog2/users/UserConfiguration.java index 985b9b357daa..f4924a41a2ee 100644 --- a/graylog2-server/src/main/java/org/graylog2/users/UserConfiguration.java +++ b/graylog2-server/src/main/java/org/graylog2/users/UserConfiguration.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import org.graylog.autovalue.WithBeanGetter; +import org.graylog2.plugin.Version; import java.time.Duration; import java.time.temporal.ChronoUnit; @@ -29,18 +30,26 @@ @AutoValue @WithBeanGetter public abstract class UserConfiguration { - public static final UserConfiguration DEFAULT_VALUES = create(false, Duration.of(8, ChronoUnit.HOURS)); + private static final boolean IS_BEFORE_VERSION_6_2 = !Version.CURRENT_CLASSPATH.sameOrHigher(Version.from(6, 2, 0)); + + //Starting with graylog version 6.2, external users are not allowed to own access tokens by default. + // Before this version, it is allowed, to not introduce a breaking change: + public static final UserConfiguration DEFAULT_VALUES = create(false, Duration.of(8, ChronoUnit.HOURS), IS_BEFORE_VERSION_6_2); @JsonProperty("enable_global_session_timeout") public abstract boolean enableGlobalSessionTimeout(); @JsonProperty("global_session_timeout_interval") - public abstract java.time.Duration globalSessionTimeoutInterval(); + public abstract Duration globalSessionTimeoutInterval(); + + @JsonProperty("allow_access_token_for_external_user") + public abstract boolean allowAccessTokenForExternalUsers(); @JsonCreator public static UserConfiguration create( @JsonProperty("enable_global_session_timeout") boolean enableGlobalSessionTimeout, - @JsonProperty("global_session_timeout_interval") java.time.Duration globalSessionTimeoutInterval) { - return new AutoValue_UserConfiguration(enableGlobalSessionTimeout, globalSessionTimeoutInterval); + @JsonProperty("global_session_timeout_interval") Duration globalSessionTimeoutInterval, + @JsonProperty("allow_access_token_for_external_user") boolean allowAccessTokenForExternalUsers) { + return new AutoValue_UserConfiguration(enableGlobalSessionTimeout, globalSessionTimeoutInterval, allowAccessTokenForExternalUsers); } } diff --git a/graylog2-server/src/test/java/org/graylog2/rest/resources/users/UsersResourceTest.java b/graylog2-server/src/test/java/org/graylog2/rest/resources/users/UsersResourceTest.java index 148063672633..d5c28e0b5b23 100644 --- a/graylog2-server/src/test/java/org/graylog2/rest/resources/users/UsersResourceTest.java +++ b/graylog2-server/src/test/java/org/graylog2/rest/resources/users/UsersResourceTest.java @@ -17,6 +17,8 @@ package org.graylog2.rest.resources.users; import com.google.common.collect.ImmutableSet; +import jakarta.ws.rs.ForbiddenException; +import jakarta.ws.rs.core.Response; import org.apache.shiro.mgt.DefaultSecurityManager; import org.apache.shiro.subject.Subject; import org.bson.types.ObjectId; @@ -24,11 +26,15 @@ import org.graylog.testing.mongodb.MongoDBInstance; import org.graylog2.Configuration; import org.graylog2.configuration.HttpConfiguration; +import org.graylog2.plugin.Tools; import org.graylog2.plugin.cluster.ClusterConfigService; import org.graylog2.plugin.database.ValidationException; import org.graylog2.rest.models.users.requests.CreateUserRequest; import org.graylog2.rest.models.users.requests.Startpage; import org.graylog2.rest.models.users.requests.UpdateUserPreferences; +import org.graylog2.rest.models.users.responses.Token; +import org.graylog2.security.AccessToken; +import org.graylog2.security.AccessTokenImpl; import org.graylog2.security.AccessTokenService; import org.graylog2.security.MongoDBSessionService; import org.graylog2.security.PasswordAlgorithmFactory; @@ -39,7 +45,9 @@ import org.graylog2.shared.users.UserManagementService; import org.graylog2.users.PaginatedUserService; import org.graylog2.users.RoleService; +import org.graylog2.users.UserConfiguration; import org.graylog2.users.UserImpl; +import org.joda.time.DateTime; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -48,29 +56,32 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import jakarta.ws.rs.core.Response; - +import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import static org.graylog2.shared.security.RestPermissions.USERS_TOKENCREATE; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; public class UsersResourceTest { - public static final String USERNAME = "username"; - public static final String PASSWORD = "password"; - public static final String EMAIL = "test@graylog.com"; - public static final String FIRST_NAME = "First"; - public static final String LAST_NAME = "Last"; - public static final String TIMEZONE = "Europe/Berlin"; - public static final long SESSION_TIMEOUT = 0L; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String EMAIL = "test@graylog.com"; + private static final String FIRST_NAME = "First"; + private static final String LAST_NAME = "Last"; + private static final String TIMEZONE = "Europe/Berlin"; + private static final long SESSION_TIMEOUT = 0L; + private static final String TOKEN_NAME = "tokenName"; @Rule public MockitoRule rule = MockitoJUnit.rule(); @@ -100,16 +111,18 @@ public class UsersResourceTest { private DefaultSecurityManager securityManager; @Mock private GlobalAuthServiceConfig globalAuthServiceConfig; + @Mock + private ClusterConfigService clusterConfigService; UserImplFactory userImplFactory; @Before - public void setUp() throws Exception { + public void setUp() { userImplFactory = new UserImplFactory(new Configuration(), new Permissions(ImmutableSet.of(new RestPermissions()))); usersResource = new TestUsersResource(userManagementService, paginatedUserService, accessTokenService, roleService, sessionService, new HttpConfiguration(), subject, - sessionTerminationService, securityManager, globalAuthServiceConfig); + sessionTerminationService, securityManager, globalAuthServiceConfig, clusterConfigService); } /** @@ -127,11 +140,57 @@ public void createSuccess() throws ValidationException { @Test public void savePreferencesSuccess() throws ValidationException { when(subject.isPermitted(anyString())).thenReturn(true); - when(userManagementService.load(eq(USERNAME))).thenReturn(userImplFactory.create(new HashMap<>())); + when(userManagementService.load(USERNAME)).thenReturn(userImplFactory.create(new HashMap<>())); usersResource.savePreferences(USERNAME, UpdateUserPreferences.create(new HashMap<>())); verify(userManagementService, times(1)).save(isA(UserImpl.class)); } + @Test + public void createTokenForInternalUserSucceeds() { + final Map userProps = Map.of(UserImpl.USERNAME, USERNAME); + final Token expected = createTokenAndPrepareMocks(userProps); + + try { + final Token actual = usersResource.generateNewToken(USERNAME, UsersResourceTest.TOKEN_NAME, "{}"); + assertEquals(expected, actual); + } finally { + verify(subject).isPermitted(USERS_TOKENCREATE + ":" + USERNAME); + verify(accessTokenService).create(USERNAME, UsersResourceTest.TOKEN_NAME); + verifyNoMoreInteractions(clusterConfigService, accessTokenService); + } + } + + @Test(expected = ForbiddenException.class) + public void createTokenForExternalUserFailsIfConfigured() { + final Map userProps = Map.of(UserImpl.USERNAME, USERNAME, UserImpl.EXTERNAL_USER, "TRUE"); + + prepareMocks(userProps, null, false); + + try { + usersResource.generateNewToken(USERNAME, TOKEN_NAME, "{}"); + } finally { + verify(subject).isPermitted(USERS_TOKENCREATE + ":" + USERNAME); + verify(clusterConfigService).getOrDefault(UserConfiguration.class, UserConfiguration.DEFAULT_VALUES); + verifyNoMoreInteractions(clusterConfigService, accessTokenService); + } + } + + @Test + public void createTokenForExternalUserSucceedsIfConfigured() { + final Map userProps = Map.of(UserImpl.USERNAME, USERNAME, UserImpl.EXTERNAL_USER, "TRUE"); + final Token expected = createTokenAndPrepareMocks(userProps); + + try { + final Token actual = usersResource.generateNewToken(USERNAME, TOKEN_NAME, "{}"); + assertEquals(expected, actual); + } finally { + verify(subject).isPermitted(USERS_TOKENCREATE + ":" + USERNAME); + verify(clusterConfigService).getOrDefault(UserConfiguration.class, UserConfiguration.DEFAULT_VALUES); + verify(accessTokenService).create(USERNAME, TOKEN_NAME); + verifyNoMoreInteractions(clusterConfigService, accessTokenService); + } + } + private CreateUserRequest buildCreateUserRequest() { return CreateUserRequest.create(USERNAME, PASSWORD, EMAIL, FIRST_NAME, LAST_NAME, Collections.singletonList(""), @@ -139,6 +198,26 @@ private CreateUserRequest buildCreateUserRequest() { startPage, Collections.emptyList(), false); } + private Token createTokenAndPrepareMocks(Map userProps) { + final String token = "someToken"; + final DateTime lastAccess = Tools.nowUTC(); + final Map tokenProps = Map.of(AccessTokenImpl.NAME, TOKEN_NAME, AccessTokenImpl.TOKEN, token, AccessTokenImpl.LAST_ACCESS, lastAccess); + final ObjectId tokenId = new ObjectId(); + final AccessToken accessToken = new AccessTokenImpl(tokenId, tokenProps); + + prepareMocks(userProps, accessToken, true); + + return Token.create(tokenId.toHexString(), TOKEN_NAME, token, lastAccess); + } + + private void prepareMocks(Map userProps, AccessToken accessToken, boolean allowExternalUser) { + when(userManagementService.loadById(USERNAME)).thenReturn(userImplFactory.create(userProps)); + when(subject.isPermitted(USERS_TOKENCREATE + ":" + USERNAME)).thenReturn(true); + when(clusterConfigService.getOrDefault(UserConfiguration.class, UserConfiguration.DEFAULT_VALUES)) + .thenReturn(UserConfiguration.create(false, Duration.of(8, ChronoUnit.HOURS), allowExternalUser)); + when(accessTokenService.create(USERNAME, UsersResourceTest.TOKEN_NAME)).thenReturn(accessToken); + } + /** * Test implementation of UsersResource is needed to set superclass configuration property * (which is directly injected without a constructor). @@ -151,9 +230,10 @@ public TestUsersResource(UserManagementService userManagementService, PaginatedU AccessTokenService accessTokenService, RoleService roleService, MongoDBSessionService sessionService, HttpConfiguration configuration, Subject subject, UserSessionTerminationService sessionTerminationService, - DefaultSecurityManager securityManager, GlobalAuthServiceConfig globalAuthServiceConfig) { + DefaultSecurityManager securityManager, GlobalAuthServiceConfig globalAuthServiceConfig, + ClusterConfigService clusterConfigService) { super(userManagementService, paginatedUserService, accessTokenService, roleService, sessionService, - sessionTerminationService, securityManager, globalAuthServiceConfig); + sessionTerminationService, securityManager, globalAuthServiceConfig, clusterConfigService); this.subject = subject; super.configuration = configuration; } From 9fb8b32d6a932a75c3dcfb166c93caabfcd7f835 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:10:48 +0100 Subject: [PATCH 39/56] Bump bouncycastle.version from 1.79 to 1.80 (#21352) * Bump bouncycastle.version from 1.79 to 1.80 Bumps `bouncycastle.version` from 1.79 to 1.80. Updates `org.bouncycastle:bcprov-jdk18on` from 1.79 to 1.80 - [Changelog](https://github.com/bcgit/bc-java/blob/main/docs/releasenotes.html) - [Commits](https://github.com/bcgit/bc-java/commits) Updates `org.bouncycastle:bcpkix-jdk18on` from 1.79 to 1.80 - [Changelog](https://github.com/bcgit/bc-java/blob/main/docs/releasenotes.html) - [Commits](https://github.com/bcgit/bc-java/commits) --- updated-dependencies: - dependency-name: org.bouncycastle:bcprov-jdk18on dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.bouncycastle:bcpkix-jdk18on dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Manage bcutil-jdk18on to avoid dynamic version. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Othello Maurer --- pom.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3b9c8b38e8e3..9417537804cb 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,8 @@ 2.30.4 2.6.0 2.2.0 - 1.79 + + 1.80 1.16.1 3.2.0 0.0.1.10 @@ -474,6 +475,14 @@ bcpkix-jdk18on ${bouncycastle.version} + + + org.bouncycastle + bcutil-jdk18on + ${bouncycastle.version} + From e6560825583cd054b09da189abe9f23d3e89ca46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:12:38 +0100 Subject: [PATCH 40/56] Bump com.google.protobuf:protobuf-bom from 3.25.5 to 3.25.6 (#21446) * Bump com.google.protobuf:protobuf-bom from 3.25.5 to 3.25.6 Bumps [com.google.protobuf:protobuf-bom](https://github.com/protocolbuffers/protobuf) from 3.25.5 to 3.25.6. - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/protobuf_release.bzl) - [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.25.5...v3.25.6) --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Add cause to ipfix processing exception * Fix warning * Recompile protobuf files with protoc 3.25.6 (libprotoc 25.6) --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Othello Maurer --- .../integrations/ipfix/IpfixJournal.java | 4604 ++++++++--------- .../integrations/ipfix/codecs/IpfixCodec.java | 2 +- .../plugins/netflow/v9/NetFlowV9Journal.java | 571 +- .../plugin/journal/JournalMessages.java | 3251 +++++++----- .../src/main/resources/ipfix_journal.proto | 2 +- .../src/main/resources/netflow_v9.proto | 2 +- .../graylog2/plugin/journal/raw_message.proto | 2 +- .../plugin/journal/RawMessageTest.java | 3 +- pom.xml | 2 +- 9 files changed, 4553 insertions(+), 3886 deletions(-) diff --git a/graylog2-server/src/main/java/org/graylog/integrations/ipfix/IpfixJournal.java b/graylog2-server/src/main/java/org/graylog/integrations/ipfix/IpfixJournal.java index 4a25cd2547d5..d9327a79156a 100644 --- a/graylog2-server/src/main/java/org/graylog/integrations/ipfix/IpfixJournal.java +++ b/graylog2-server/src/main/java/org/graylog/integrations/ipfix/IpfixJournal.java @@ -17,2407 +17,2339 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: src/main/resources/ipfix_journal.proto +// Protobuf Java Version: 3.25.6 package org.graylog.integrations.ipfix; -import com.google.protobuf.RepeatedFieldBuilderV3; - -import java.util.List; - public final class IpfixJournal { - private IpfixJournal() { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - - public interface RawIpfixOrBuilder extends - // @@protoc_insertion_point(interface_extends:org.graylog.plugins.ipfix.RawIpfix) - com.google.protobuf.MessageOrBuilder { - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - int getTemplatesCount(); - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - boolean containsTemplates( - int key); - - /** - * Use {@link #getTemplatesMap()} instead. - */ - @Deprecated - java.util.Map - getTemplates(); - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - java.util.Map - getTemplatesMap(); - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - - com.google.protobuf.ByteString getTemplatesOrDefault( - int key, - com.google.protobuf.ByteString defaultValue); - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - - com.google.protobuf.ByteString getTemplatesOrThrow( - int key); - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - int getOptionTemplatesCount(); - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - boolean containsOptionTemplates( - int key); - - /** - * Use {@link #getOptionTemplatesMap()} instead. - */ - @Deprecated - java.util.Map - getOptionTemplates(); - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - java.util.Map - getOptionTemplatesMap(); - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - com.google.protobuf.ByteString getOptionTemplatesOrDefault( - int key, - com.google.protobuf.ByteString defaultValue); - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - com.google.protobuf.ByteString getOptionTemplatesOrThrow( - int key); - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - java.util.List - getDataSetsList(); - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - org.graylog.integrations.ipfix.IpfixJournal.DataSet getDataSets(int index); - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - int getDataSetsCount(); - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - java.util.List - getDataSetsOrBuilderList(); - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder getDataSetsOrBuilder( - int index); - } + private IpfixJournal() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + public interface RawIpfixOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.graylog.integrations.ipfix.RawIpfix) + com.google.protobuf.MessageOrBuilder { /** - * Protobuf type {@code org.graylog.plugins.ipfix.RawIpfix} + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; */ - public static final class RawIpfix extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:org.graylog.plugins.ipfix.RawIpfix) - RawIpfixOrBuilder { - // Use RawIpfix.newBuilder() to construct. - private RawIpfix(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - - private RawIpfix() { - dataSets_ = java.util.Collections.emptyList(); - } - - @Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - - private RawIpfix( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - templates_ = com.google.protobuf.MapField.newMapField( - TemplatesDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - templates = input.readMessage( - TemplatesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - templates_.getMutableMap().put(templates.getKey(), templates.getValue()); - break; - } - case 18: { - if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - optionTemplates_ = com.google.protobuf.MapField.newMapField( - OptionTemplatesDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000002; - } - com.google.protobuf.MapEntry - optionTemplates = input.readMessage( - OptionTemplatesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - optionTemplates_.getMutableMap().put(optionTemplates.getKey(), optionTemplates.getValue()); - break; - } - case 26: { - if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - dataSets_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000004; - } - dataSets_.add( - input.readMessage(org.graylog.integrations.ipfix.IpfixJournal.DataSet.PARSER, extensionRegistry)); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - dataSets_ = java.util.Collections.unmodifiableList(dataSets_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 1: - return internalGetTemplates(); - case 2: - return internalGetOptionTemplates(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_RawIpfix_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.class, org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.Builder.class); - } - - public static final int TEMPLATES_FIELD_NUMBER = 1; - - private static final class TemplatesDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - Integer, com.google.protobuf.ByteString> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_RawIpfix_TemplatesEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.UINT32, - 0, - com.google.protobuf.WireFormat.FieldType.BYTES, - com.google.protobuf.ByteString.EMPTY); - } - - private com.google.protobuf.MapField< - Integer, com.google.protobuf.ByteString> templates_; - - private com.google.protobuf.MapField - internalGetTemplates() { - if (templates_ == null) { - return com.google.protobuf.MapField.emptyMapField( - TemplatesDefaultEntryHolder.defaultEntry); - } - return templates_; - } - - public int getTemplatesCount() { - return internalGetTemplates().getMap().size(); - } - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public boolean containsTemplates( - int key) { - - return internalGetTemplates().getMap().containsKey(key); - } - - /** - * Use {@link #getTemplatesMap()} instead. - */ - @Deprecated - public java.util.Map getTemplates() { - return getTemplatesMap(); - } - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public java.util.Map getTemplatesMap() { - return internalGetTemplates().getMap(); - } - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public com.google.protobuf.ByteString getTemplatesOrDefault( - int key, - com.google.protobuf.ByteString defaultValue) { - - java.util.Map map = - internalGetTemplates().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - - /** - *
    -         * all applicable templates that are referenced by the data sets
    -         * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public com.google.protobuf.ByteString getTemplatesOrThrow( - int key) { - - java.util.Map map = - internalGetTemplates().getMap(); - if (!map.containsKey(key)) { - throw new IllegalArgumentException(); - } - return map.get(key); - } - - public static final int OPTIONTEMPLATES_FIELD_NUMBER = 2; - - private static final class OptionTemplatesDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - Integer, com.google.protobuf.ByteString> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_RawIpfix_OptionTemplatesEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.UINT32, - 0, - com.google.protobuf.WireFormat.FieldType.BYTES, - com.google.protobuf.ByteString.EMPTY); - } - - private com.google.protobuf.MapField< - Integer, com.google.protobuf.ByteString> optionTemplates_; - - private com.google.protobuf.MapField - internalGetOptionTemplates() { - if (optionTemplates_ == null) { - return com.google.protobuf.MapField.emptyMapField( - OptionTemplatesDefaultEntryHolder.defaultEntry); - } - return optionTemplates_; - } - - public int getOptionTemplatesCount() { - return internalGetOptionTemplates().getMap().size(); - } - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public boolean containsOptionTemplates( - int key) { - - return internalGetOptionTemplates().getMap().containsKey(key); - } - - /** - * Use {@link #getOptionTemplatesMap()} instead. - */ - @Deprecated - public java.util.Map getOptionTemplates() { - return getOptionTemplatesMap(); - } - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public java.util.Map getOptionTemplatesMap() { - return internalGetOptionTemplates().getMap(); - } - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public com.google.protobuf.ByteString getOptionTemplatesOrDefault( - int key, - com.google.protobuf.ByteString defaultValue) { - - java.util.Map map = - internalGetOptionTemplates().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - - /** - *
    -         * all applicable options templates that are references by the data sets
    -         * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public com.google.protobuf.ByteString getOptionTemplatesOrThrow( - int key) { - - java.util.Map map = - internalGetOptionTemplates().getMap(); - if (!map.containsKey(key)) { - throw new IllegalArgumentException(); - } - return map.get(key); - } - - public static final int DATASETS_FIELD_NUMBER = 3; - private List dataSets_; - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public java.util.List getDataSetsList() { - return dataSets_; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public java.util.List - getDataSetsOrBuilderList() { - return dataSets_; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public int getDataSetsCount() { - return dataSets_.size(); - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDataSets(int index) { - return dataSets_.get(index); - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder getDataSetsOrBuilder( - int index) { - return dataSets_.get(index); - } - - private byte memoizedIsInitialized = -1; - - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - for (int i = 0; i < getDataSetsCount(); i++) { - if (!getDataSets(i).isInitialized()) { - memoizedIsInitialized = 0; - return false; - } - } - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - for (java.util.Map.Entry entry - : internalGetTemplates().getMap().entrySet()) { - com.google.protobuf.MapEntry - templates = TemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - output.writeMessage(1, templates); - } - for (java.util.Map.Entry entry - : internalGetOptionTemplates().getMap().entrySet()) { - com.google.protobuf.MapEntry - optionTemplates = OptionTemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - output.writeMessage(2, optionTemplates); - } - for (int i = 0; i < dataSets_.size(); i++) { - output.writeMessage(3, dataSets_.get(i)); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - for (java.util.Map.Entry entry - : internalGetTemplates().getMap().entrySet()) { - com.google.protobuf.MapEntry - templates = TemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, templates); - } - for (java.util.Map.Entry entry - : internalGetOptionTemplates().getMap().entrySet()) { - com.google.protobuf.MapEntry - optionTemplates = OptionTemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, optionTemplates); - } - for (int i = 0; i < dataSets_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, dataSets_.get(i)); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof org.graylog.integrations.ipfix.IpfixJournal.RawIpfix)) { - return super.equals(obj); - } - org.graylog.integrations.ipfix.IpfixJournal.RawIpfix other = (org.graylog.integrations.ipfix.IpfixJournal.RawIpfix) obj; - - boolean result = true; - result = result && internalGetTemplates().equals( - other.internalGetTemplates()); - result = result && internalGetOptionTemplates().equals( - other.internalGetOptionTemplates()); - result = result && getDataSetsList() - .equals(other.getDataSetsList()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptorForType().hashCode(); - if (!internalGetTemplates().getMap().isEmpty()) { - hash = (37 * hash) + TEMPLATES_FIELD_NUMBER; - hash = (53 * hash) + internalGetTemplates().hashCode(); - } - if (!internalGetOptionTemplates().getMap().isEmpty()) { - hash = (37 * hash) + OPTIONTEMPLATES_FIELD_NUMBER; - hash = (53 * hash) + internalGetOptionTemplates().hashCode(); - } - if (getDataSetsCount() > 0) { - hash = (37 * hash) + DATASETS_FIELD_NUMBER; - hash = (53 * hash) + getDataSetsList().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { - return newBuilder(); - } - - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - - public static Builder newBuilder(org.graylog.integrations.ipfix.IpfixJournal.RawIpfix prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - - /** - * Protobuf type {@code org.graylog.plugins.ipfix.RawIpfix} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:org.graylog.plugins.ipfix.RawIpfix) - org.graylog.integrations.ipfix.IpfixJournal.RawIpfixOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 1: - return internalGetTemplates(); - case 2: - return internalGetOptionTemplates(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 1: - return internalGetMutableTemplates(); - case 2: - return internalGetMutableOptionTemplates(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_RawIpfix_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.class, org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.Builder.class); - } - - // Construct using org.graylog.plugins.ipfix.IpfixJournal.RawIpfix.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - getDataSetsFieldBuilder(); - } - } - - public Builder clear() { - super.clear(); - internalGetMutableTemplates().clear(); - internalGetMutableOptionTemplates().clear(); - if (dataSetsBuilder_ == null) { - dataSets_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000004); - } else { - dataSetsBuilder_.clear(); - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor; - } - - public org.graylog.integrations.ipfix.IpfixJournal.RawIpfix getDefaultInstanceForType() { - return org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.getDefaultInstance(); - } - - public RawIpfix build() { - org.graylog.integrations.ipfix.IpfixJournal.RawIpfix result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public org.graylog.integrations.ipfix.IpfixJournal.RawIpfix buildPartial() { - org.graylog.integrations.ipfix.IpfixJournal.RawIpfix result = new org.graylog.integrations.ipfix.IpfixJournal.RawIpfix(this); - int from_bitField0_ = bitField0_; - result.templates_ = internalGetTemplates(); - result.templates_.makeImmutable(); - result.optionTemplates_ = internalGetOptionTemplates(); - result.optionTemplates_.makeImmutable(); - if (dataSetsBuilder_ == null) { - if (((bitField0_ & 0x00000004) == 0x00000004)) { - dataSets_ = java.util.Collections.unmodifiableList(dataSets_); - bitField0_ = (bitField0_ & ~0x00000004); - } - result.dataSets_ = dataSets_; - } else { - result.dataSets_ = dataSetsBuilder_.build(); - } - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - Object value) { - return (Builder) super.setField(field, value); - } - - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - Object value) { - return (Builder) super.addRepeatedField(field, value); - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.graylog.integrations.ipfix.IpfixJournal.RawIpfix) { - return mergeFrom((org.graylog.integrations.ipfix.IpfixJournal.RawIpfix) other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(org.graylog.integrations.ipfix.IpfixJournal.RawIpfix other) { - if (other == org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.getDefaultInstance()) return this; - internalGetMutableTemplates().mergeFrom( - other.internalGetTemplates()); - internalGetMutableOptionTemplates().mergeFrom( - other.internalGetOptionTemplates()); - if (dataSetsBuilder_ == null) { - if (!other.dataSets_.isEmpty()) { - if (dataSets_.isEmpty()) { - dataSets_ = other.dataSets_; - bitField0_ = (bitField0_ & ~0x00000004); - } else { - ensureDataSetsIsMutable(); - dataSets_.addAll(other.dataSets_); - } - onChanged(); - } - } else { - if (!other.dataSets_.isEmpty()) { - if (dataSetsBuilder_.isEmpty()) { - dataSetsBuilder_.dispose(); - dataSetsBuilder_ = null; - dataSets_ = other.dataSets_; - bitField0_ = (bitField0_ & ~0x00000004); - dataSetsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? - getDataSetsFieldBuilder() : null; - } else { - dataSetsBuilder_.addAllMessages(other.dataSets_); - } - } - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - for (int i = 0; i < getDataSetsCount(); i++) { - if (!getDataSets(i).isInitialized()) { - return false; - } - } - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.graylog.integrations.ipfix.IpfixJournal.RawIpfix) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int bitField0_; - - private com.google.protobuf.MapField< - Integer, com.google.protobuf.ByteString> templates_; - - private com.google.protobuf.MapField - internalGetTemplates() { - if (templates_ == null) { - return com.google.protobuf.MapField.emptyMapField( - TemplatesDefaultEntryHolder.defaultEntry); - } - return templates_; - } - - private com.google.protobuf.MapField - internalGetMutableTemplates() { - onChanged(); - ; - if (templates_ == null) { - templates_ = com.google.protobuf.MapField.newMapField( - TemplatesDefaultEntryHolder.defaultEntry); - } - if (!templates_.isMutable()) { - templates_ = templates_.copy(); - } - return templates_; - } - - public int getTemplatesCount() { - return internalGetTemplates().getMap().size(); - } - - /** - *
    -             * all applicable templates that are referenced by the data sets
    -             * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public boolean containsTemplates( - int key) { - - return internalGetTemplates().getMap().containsKey(key); - } - - /** - * Use {@link #getTemplatesMap()} instead. - */ - @Deprecated - public java.util.Map getTemplates() { - return getTemplatesMap(); - } - - /** - *
    -             * all applicable templates that are referenced by the data sets
    -             * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public java.util.Map getTemplatesMap() { - return internalGetTemplates().getMap(); - } - - /** - *
    -             * all applicable templates that are referenced by the data sets
    -             * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public com.google.protobuf.ByteString getTemplatesOrDefault( - int key, - com.google.protobuf.ByteString defaultValue) { - - java.util.Map map = - internalGetTemplates().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - - /** - *
    -             * all applicable templates that are referenced by the data sets
    -             * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public com.google.protobuf.ByteString getTemplatesOrThrow( - int key) { - - java.util.Map map = - internalGetTemplates().getMap(); - if (!map.containsKey(key)) { - throw new IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearTemplates() { - getMutableTemplates().clear(); - return this; - } - - /** - *
    -             * all applicable templates that are referenced by the data sets
    -             * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public Builder removeTemplates( - int key) { - - getMutableTemplates().remove(key); - return this; - } - - /** - * Use alternate mutation accessors instead. - */ - @Deprecated - public java.util.Map - getMutableTemplates() { - return internalGetMutableTemplates().getMutableMap(); - } - - /** - *
    -             * all applicable templates that are referenced by the data sets
    -             * 
    - * - * map<uint32, bytes> templates = 1; - */ - public Builder putTemplates( - int key, - com.google.protobuf.ByteString value) { - - if (value == null) { - throw new NullPointerException(); - } - getMutableTemplates().put(key, value); - return this; - } - - /** - *
    -             * all applicable templates that are referenced by the data sets
    -             * 
    - * - * map<uint32, bytes> templates = 1; - */ - - public Builder putAllTemplates( - java.util.Map values) { - getMutableTemplates().putAll(values); - return this; - } - - private com.google.protobuf.MapField< - Integer, com.google.protobuf.ByteString> optionTemplates_; - - private com.google.protobuf.MapField - internalGetOptionTemplates() { - if (optionTemplates_ == null) { - return com.google.protobuf.MapField.emptyMapField( - OptionTemplatesDefaultEntryHolder.defaultEntry); - } - return optionTemplates_; - } - - private com.google.protobuf.MapField - internalGetMutableOptionTemplates() { - onChanged(); - ; - if (optionTemplates_ == null) { - optionTemplates_ = com.google.protobuf.MapField.newMapField( - OptionTemplatesDefaultEntryHolder.defaultEntry); - } - if (!optionTemplates_.isMutable()) { - optionTemplates_ = optionTemplates_.copy(); - } - return optionTemplates_; - } - - public int getOptionTemplatesCount() { - return internalGetOptionTemplates().getMap().size(); - } - - /** - *
    -             * all applicable options templates that are references by the data sets
    -             * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public boolean containsOptionTemplates( - int key) { - - return internalGetOptionTemplates().getMap().containsKey(key); - } - - /** - * Use {@link #getOptionTemplatesMap()} instead. - */ - @Deprecated - public java.util.Map getOptionTemplates() { - return getOptionTemplatesMap(); - } - - /** - *
    -             * all applicable options templates that are references by the data sets
    -             * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public java.util.Map getOptionTemplatesMap() { - return internalGetOptionTemplates().getMap(); - } - - /** - *
    -             * all applicable options templates that are references by the data sets
    -             * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public com.google.protobuf.ByteString getOptionTemplatesOrDefault( - int key, - com.google.protobuf.ByteString defaultValue) { - - java.util.Map map = - internalGetOptionTemplates().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - - /** - *
    -             * all applicable options templates that are references by the data sets
    -             * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public com.google.protobuf.ByteString getOptionTemplatesOrThrow( - int key) { - - java.util.Map map = - internalGetOptionTemplates().getMap(); - if (!map.containsKey(key)) { - throw new IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearOptionTemplates() { - getMutableOptionTemplates().clear(); - return this; - } - - /** - *
    -             * all applicable options templates that are references by the data sets
    -             * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public Builder removeOptionTemplates( - int key) { - - getMutableOptionTemplates().remove(key); - return this; - } - - /** - * Use alternate mutation accessors instead. - */ - @Deprecated - public java.util.Map - getMutableOptionTemplates() { - return internalGetMutableOptionTemplates().getMutableMap(); - } - - /** - *
    -             * all applicable options templates that are references by the data sets
    -             * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - public Builder putOptionTemplates( - int key, - com.google.protobuf.ByteString value) { - - if (value == null) { - throw new NullPointerException(); - } - getMutableOptionTemplates().put(key, value); - return this; - } - - /** - *
    -             * all applicable options templates that are references by the data sets
    -             * 
    - * - * map<uint32, bytes> optionTemplates = 2; - */ - - public Builder putAllOptionTemplates( - java.util.Map values) { - getMutableOptionTemplates().putAll(values); - return this; - } - - private java.util.List dataSets_ = - java.util.Collections.emptyList(); - - private void ensureDataSetsIsMutable() { - if (!((bitField0_ & 0x00000004) == 0x00000004)) { - dataSets_ = new java.util.ArrayList(dataSets_); - bitField0_ |= 0x00000004; - } - } - - private RepeatedFieldBuilderV3 dataSetsBuilder_; - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public java.util.List getDataSetsList() { - if (dataSetsBuilder_ == null) { - return java.util.Collections.unmodifiableList(dataSets_); - } else { - return dataSetsBuilder_.getMessageList(); - } - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public int getDataSetsCount() { - if (dataSetsBuilder_ == null) { - return dataSets_.size(); - } else { - return dataSetsBuilder_.getCount(); - } - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDataSets(int index) { - if (dataSetsBuilder_ == null) { - return dataSets_.get(index); - } else { - return dataSetsBuilder_.getMessage(index); - } - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder setDataSets( - int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet value) { - if (dataSetsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureDataSetsIsMutable(); - dataSets_.set(index, value); - onChanged(); - } else { - dataSetsBuilder_.setMessage(index, value); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder setDataSets( - int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder builderForValue) { - if (dataSetsBuilder_ == null) { - ensureDataSetsIsMutable(); - dataSets_.set(index, builderForValue.build()); - onChanged(); - } else { - dataSetsBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder addDataSets(org.graylog.integrations.ipfix.IpfixJournal.DataSet value) { - if (dataSetsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureDataSetsIsMutable(); - dataSets_.add(value); - onChanged(); - } else { - dataSetsBuilder_.addMessage(value); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder addDataSets( - int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet value) { - if (dataSetsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureDataSetsIsMutable(); - dataSets_.add(index, value); - onChanged(); - } else { - dataSetsBuilder_.addMessage(index, value); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder addDataSets( - org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder builderForValue) { - if (dataSetsBuilder_ == null) { - ensureDataSetsIsMutable(); - dataSets_.add(builderForValue.build()); - onChanged(); - } else { - dataSetsBuilder_.addMessage(builderForValue.build()); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder addDataSets( - int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder builderForValue) { - if (dataSetsBuilder_ == null) { - ensureDataSetsIsMutable(); - dataSets_.add(index, builderForValue.build()); - onChanged(); - } else { - dataSetsBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder addAllDataSets( - Iterable values) { - if (dataSetsBuilder_ == null) { - ensureDataSetsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, dataSets_); - onChanged(); - } else { - dataSetsBuilder_.addAllMessages(values); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder clearDataSets() { - if (dataSetsBuilder_ == null) { - dataSets_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000004); - onChanged(); - } else { - dataSetsBuilder_.clear(); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public Builder removeDataSets(int index) { - if (dataSetsBuilder_ == null) { - ensureDataSetsIsMutable(); - dataSets_.remove(index); - onChanged(); - } else { - dataSetsBuilder_.remove(index); - } - return this; - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder getDataSetsBuilder( - int index) { - return getDataSetsFieldBuilder().getBuilder(index); - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder getDataSetsOrBuilder( - int index) { - if (dataSetsBuilder_ == null) { - return dataSets_.get(index); - } else { - return dataSetsBuilder_.getMessageOrBuilder(index); - } - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public java.util.List - getDataSetsOrBuilderList() { - if (dataSetsBuilder_ != null) { - return dataSetsBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(dataSets_); - } - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder addDataSetsBuilder() { - return getDataSetsFieldBuilder().addBuilder( - org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance()); - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder addDataSetsBuilder( - int index) { - return getDataSetsFieldBuilder().addBuilder( - index, org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance()); - } - - /** - * repeated .org.graylog.plugins.ipfix.DataSet dataSets = 3; - */ - public java.util.List - getDataSetsBuilderList() { - return getDataSetsFieldBuilder().getBuilderList(); - } - - private RepeatedFieldBuilderV3 - getDataSetsFieldBuilder() { - if (dataSetsBuilder_ == null) { - dataSetsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< - org.graylog.integrations.ipfix.IpfixJournal.DataSet, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder, org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder>( - dataSets_, - ((bitField0_ & 0x00000004) == 0x00000004), - getParentForChildren(), - isClean()); - dataSets_ = null; - } - return dataSetsBuilder_; - } - - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:org.graylog.plugins.ipfix.RawIpfix) - } - - // @@protoc_insertion_point(class_scope:org.graylog.plugins.ipfix.RawIpfix) - private static final org.graylog.integrations.ipfix.IpfixJournal.RawIpfix DEFAULT_INSTANCE; - - static { - DEFAULT_INSTANCE = new org.graylog.integrations.ipfix.IpfixJournal.RawIpfix(); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - @Deprecated - public static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public RawIpfix parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new RawIpfix(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public org.graylog.integrations.ipfix.IpfixJournal.RawIpfix getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface DataSetOrBuilder extends - // @@protoc_insertion_point(interface_extends:org.graylog.plugins.ipfix.DataSet) - com.google.protobuf.MessageOrBuilder { - - /** - * required uint64 timestampEpochSeconds = 1; - */ - boolean hasTimestampEpochSeconds(); - - /** - * required uint64 timestampEpochSeconds = 1; - */ - long getTimestampEpochSeconds(); - - /** - * required uint32 templateId = 2; - */ - boolean hasTemplateId(); - - /** - * required uint32 templateId = 2; - */ - int getTemplateId(); - - /** - * required bytes dataRecords = 3; - */ - boolean hasDataRecords(); - - /** - * required bytes dataRecords = 3; - */ - com.google.protobuf.ByteString getDataRecords(); - } - + int getTemplatesCount(); /** - * Protobuf type {@code org.graylog.plugins.ipfix.DataSet} + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; */ - public static final class DataSet extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:org.graylog.plugins.ipfix.DataSet) - DataSetOrBuilder { - // Use DataSet.newBuilder() to construct. - private DataSet(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - - private DataSet() { - timestampEpochSeconds_ = 0L; - templateId_ = 0; - dataRecords_ = com.google.protobuf.ByteString.EMPTY; - } - - @Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - - private DataSet( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - bitField0_ |= 0x00000001; - timestampEpochSeconds_ = input.readUInt64(); - break; - } - case 16: { - bitField0_ |= 0x00000002; - templateId_ = input.readUInt32(); - break; - } - case 26: { - bitField0_ |= 0x00000004; - dataRecords_ = input.readBytes(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_DataSet_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_DataSet_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.graylog.integrations.ipfix.IpfixJournal.DataSet.class, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder.class); - } - - private int bitField0_; - public static final int TIMESTAMPEPOCHSECONDS_FIELD_NUMBER = 1; - private long timestampEpochSeconds_; - - /** - * required uint64 timestampEpochSeconds = 1; - */ - public boolean hasTimestampEpochSeconds() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - - /** - * required uint64 timestampEpochSeconds = 1; - */ - public long getTimestampEpochSeconds() { - return timestampEpochSeconds_; - } - - public static final int TEMPLATEID_FIELD_NUMBER = 2; - private int templateId_; - - /** - * required uint32 templateId = 2; - */ - public boolean hasTemplateId() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - - /** - * required uint32 templateId = 2; - */ - public int getTemplateId() { - return templateId_; - } - - public static final int DATARECORDS_FIELD_NUMBER = 3; - private com.google.protobuf.ByteString dataRecords_; - - /** - * required bytes dataRecords = 3; - */ - public boolean hasDataRecords() { - return ((bitField0_ & 0x00000004) == 0x00000004); - } - - /** - * required bytes dataRecords = 3; - */ - public com.google.protobuf.ByteString getDataRecords() { - return dataRecords_; - } - - private byte memoizedIsInitialized = -1; - - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - if (!hasTimestampEpochSeconds()) { - memoizedIsInitialized = 0; - return false; - } - if (!hasTemplateId()) { - memoizedIsInitialized = 0; - return false; - } - if (!hasDataRecords()) { - memoizedIsInitialized = 0; - return false; - } - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeUInt64(1, timestampEpochSeconds_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeUInt32(2, templateId_); - } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - output.writeBytes(3, dataRecords_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeUInt64Size(1, timestampEpochSeconds_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - size += com.google.protobuf.CodedOutputStream - .computeUInt32Size(2, templateId_); - } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(3, dataRecords_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof org.graylog.integrations.ipfix.IpfixJournal.DataSet)) { - return super.equals(obj); - } - org.graylog.integrations.ipfix.IpfixJournal.DataSet other = (org.graylog.integrations.ipfix.IpfixJournal.DataSet) obj; - - boolean result = true; - result = result && (hasTimestampEpochSeconds() == other.hasTimestampEpochSeconds()); - if (hasTimestampEpochSeconds()) { - result = result && (getTimestampEpochSeconds() - == other.getTimestampEpochSeconds()); - } - result = result && (hasTemplateId() == other.hasTemplateId()); - if (hasTemplateId()) { - result = result && (getTemplateId() - == other.getTemplateId()); - } - result = result && (hasDataRecords() == other.hasDataRecords()); - if (hasDataRecords()) { - result = result && getDataRecords() - .equals(other.getDataRecords()); - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptorForType().hashCode(); - if (hasTimestampEpochSeconds()) { - hash = (37 * hash) + TIMESTAMPEPOCHSECONDS_FIELD_NUMBER; - hash = (53 * hash) + com.google.protobuf.Internal.hashLong( - getTimestampEpochSeconds()); - } - if (hasTemplateId()) { - hash = (37 * hash) + TEMPLATEID_FIELD_NUMBER; - hash = (53 * hash) + getTemplateId(); - } - if (hasDataRecords()) { - hash = (37 * hash) + DATARECORDS_FIELD_NUMBER; - hash = (53 * hash) + getDataRecords().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { - return newBuilder(); - } - - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } + boolean containsTemplates( + int key); + /** + * Use {@link #getTemplatesMap()} instead. + */ + @java.lang.Deprecated + java.util.Map + getTemplates(); + /** + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; + */ + java.util.Map + getTemplatesMap(); + /** + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; + */ + /* nullable */ +com.google.protobuf.ByteString getTemplatesOrDefault( + int key, + /* nullable */ +com.google.protobuf.ByteString defaultValue); + /** + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; + */ + com.google.protobuf.ByteString getTemplatesOrThrow( + int key); - public static Builder newBuilder(org.graylog.integrations.ipfix.IpfixJournal.DataSet prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + int getOptionTemplatesCount(); + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + boolean containsOptionTemplates( + int key); + /** + * Use {@link #getOptionTemplatesMap()} instead. + */ + @java.lang.Deprecated + java.util.Map + getOptionTemplates(); + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + java.util.Map + getOptionTemplatesMap(); + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + /* nullable */ +com.google.protobuf.ByteString getOptionTemplatesOrDefault( + int key, + /* nullable */ +com.google.protobuf.ByteString defaultValue); + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + com.google.protobuf.ByteString getOptionTemplatesOrThrow( + int key); - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + java.util.List + getDataSetsList(); + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + org.graylog.integrations.ipfix.IpfixJournal.DataSet getDataSets(int index); + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + int getDataSetsCount(); + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + java.util.List + getDataSetsOrBuilderList(); + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder getDataSetsOrBuilder( + int index); + } + /** + * Protobuf type {@code org.graylog.integrations.ipfix.RawIpfix} + */ + public static final class RawIpfix extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.graylog.integrations.ipfix.RawIpfix) + RawIpfixOrBuilder { + private static final long serialVersionUID = 0L; + // Use RawIpfix.newBuilder() to construct. + private RawIpfix(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private RawIpfix() { + dataSets_ = java.util.Collections.emptyList(); + } - @Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new RawIpfix(); + } - /** - * Protobuf type {@code org.graylog.plugins.ipfix.DataSet} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:org.graylog.plugins.ipfix.DataSet) - org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_DataSet_descriptor; - } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor; + } - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_DataSet_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.graylog.integrations.ipfix.IpfixJournal.DataSet.class, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder.class); - } + @SuppressWarnings({"rawtypes"}) + @java.lang.Override + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 1: + return internalGetTemplates(); + case 2: + return internalGetOptionTemplates(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_RawIpfix_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.class, org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.Builder.class); + } - // Construct using org.graylog.plugins.ipfix.IpfixJournal.DataSet.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } + public static final int TEMPLATES_FIELD_NUMBER = 1; + private static final class TemplatesDefaultEntryHolder { + static final com.google.protobuf.MapEntry< + java.lang.Integer, com.google.protobuf.ByteString> defaultEntry = + com.google.protobuf.MapEntry + .newDefaultInstance( + org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_RawIpfix_TemplatesEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.UINT32, + 0, + com.google.protobuf.WireFormat.FieldType.BYTES, + com.google.protobuf.ByteString.EMPTY); + } + @SuppressWarnings("serial") + private com.google.protobuf.MapField< + java.lang.Integer, com.google.protobuf.ByteString> templates_; + private com.google.protobuf.MapField + internalGetTemplates() { + if (templates_ == null) { + return com.google.protobuf.MapField.emptyMapField( + TemplatesDefaultEntryHolder.defaultEntry); + } + return templates_; + } + public int getTemplatesCount() { + return internalGetTemplates().getMap().size(); + } + /** + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public boolean containsTemplates( + int key) { - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } + return internalGetTemplates().getMap().containsKey(key); + } + /** + * Use {@link #getTemplatesMap()} instead. + */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getTemplates() { + return getTemplatesMap(); + } + /** + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public java.util.Map getTemplatesMap() { + return internalGetTemplates().getMap(); + } + /** + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getTemplatesOrDefault( + int key, + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + + java.util.Map map = + internalGetTemplates().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + *
    +     * all applicable templates that are referenced by the data sets
    +     * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public com.google.protobuf.ByteString getTemplatesOrThrow( + int key) { + + java.util.Map map = + internalGetTemplates().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } + public static final int OPTIONTEMPLATES_FIELD_NUMBER = 2; + private static final class OptionTemplatesDefaultEntryHolder { + static final com.google.protobuf.MapEntry< + java.lang.Integer, com.google.protobuf.ByteString> defaultEntry = + com.google.protobuf.MapEntry + .newDefaultInstance( + org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_RawIpfix_OptionTemplatesEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.UINT32, + 0, + com.google.protobuf.WireFormat.FieldType.BYTES, + com.google.protobuf.ByteString.EMPTY); + } + @SuppressWarnings("serial") + private com.google.protobuf.MapField< + java.lang.Integer, com.google.protobuf.ByteString> optionTemplates_; + private com.google.protobuf.MapField + internalGetOptionTemplates() { + if (optionTemplates_ == null) { + return com.google.protobuf.MapField.emptyMapField( + OptionTemplatesDefaultEntryHolder.defaultEntry); + } + return optionTemplates_; + } + public int getOptionTemplatesCount() { + return internalGetOptionTemplates().getMap().size(); + } + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public boolean containsOptionTemplates( + int key) { - public Builder clear() { - super.clear(); - timestampEpochSeconds_ = 0L; - bitField0_ = (bitField0_ & ~0x00000001); - templateId_ = 0; - bitField0_ = (bitField0_ & ~0x00000002); - dataRecords_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000004); - return this; - } + return internalGetOptionTemplates().getMap().containsKey(key); + } + /** + * Use {@link #getOptionTemplatesMap()} instead. + */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptionTemplates() { + return getOptionTemplatesMap(); + } + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public java.util.Map getOptionTemplatesMap() { + return internalGetOptionTemplates().getMap(); + } + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getOptionTemplatesOrDefault( + int key, + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + + java.util.Map map = + internalGetOptionTemplates().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + *
    +     * all applicable options templates that are references by the data sets
    +     * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public com.google.protobuf.ByteString getOptionTemplatesOrThrow( + int key) { + + java.util.Map map = + internalGetOptionTemplates().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_plugins_ipfix_DataSet_descriptor; - } + public static final int DATASETS_FIELD_NUMBER = 3; + @SuppressWarnings("serial") + private java.util.List dataSets_; + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + @java.lang.Override + public java.util.List getDataSetsList() { + return dataSets_; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + @java.lang.Override + public java.util.List + getDataSetsOrBuilderList() { + return dataSets_; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + @java.lang.Override + public int getDataSetsCount() { + return dataSets_.size(); + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDataSets(int index) { + return dataSets_.get(index); + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder getDataSetsOrBuilder( + int index) { + return dataSets_.get(index); + } - public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDefaultInstanceForType() { - return org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance(); - } + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + for (int i = 0; i < getDataSetsCount(); i++) { + if (!getDataSets(i).isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } + memoizedIsInitialized = 1; + return true; + } - public DataSet build() { - org.graylog.integrations.ipfix.IpfixJournal.DataSet result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + com.google.protobuf.GeneratedMessageV3 + .serializeIntegerMapTo( + output, + internalGetTemplates(), + TemplatesDefaultEntryHolder.defaultEntry, + 1); + com.google.protobuf.GeneratedMessageV3 + .serializeIntegerMapTo( + output, + internalGetOptionTemplates(), + OptionTemplatesDefaultEntryHolder.defaultEntry, + 2); + for (int i = 0; i < dataSets_.size(); i++) { + output.writeMessage(3, dataSets_.get(i)); + } + getUnknownFields().writeTo(output); + } - public org.graylog.integrations.ipfix.IpfixJournal.DataSet buildPartial() { - org.graylog.integrations.ipfix.IpfixJournal.DataSet result = new org.graylog.integrations.ipfix.IpfixJournal.DataSet(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { - to_bitField0_ |= 0x00000001; - } - result.timestampEpochSeconds_ = timestampEpochSeconds_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { - to_bitField0_ |= 0x00000002; - } - result.templateId_ = templateId_; - if (((from_bitField0_ & 0x00000004) == 0x00000004)) { - to_bitField0_ |= 0x00000004; - } - result.dataRecords_ = dataRecords_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + for (java.util.Map.Entry entry + : internalGetTemplates().getMap().entrySet()) { + com.google.protobuf.MapEntry + templates__ = TemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(1, templates__); + } + for (java.util.Map.Entry entry + : internalGetOptionTemplates().getMap().entrySet()) { + com.google.protobuf.MapEntry + optionTemplates__ = OptionTemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(2, optionTemplates__); + } + for (int i = 0; i < dataSets_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(3, dataSets_.get(i)); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } - public Builder clone() { - return (Builder) super.clone(); - } + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.graylog.integrations.ipfix.IpfixJournal.RawIpfix)) { + return super.equals(obj); + } + org.graylog.integrations.ipfix.IpfixJournal.RawIpfix other = (org.graylog.integrations.ipfix.IpfixJournal.RawIpfix) obj; + + if (!internalGetTemplates().equals( + other.internalGetTemplates())) return false; + if (!internalGetOptionTemplates().equals( + other.internalGetOptionTemplates())) return false; + if (!getDataSetsList() + .equals(other.getDataSetsList())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - Object value) { - return (Builder) super.setField(field, value); - } + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (!internalGetTemplates().getMap().isEmpty()) { + hash = (37 * hash) + TEMPLATES_FIELD_NUMBER; + hash = (53 * hash) + internalGetTemplates().hashCode(); + } + if (!internalGetOptionTemplates().getMap().isEmpty()) { + hash = (37 * hash) + OPTIONTEMPLATES_FIELD_NUMBER; + hash = (53 * hash) + internalGetOptionTemplates().hashCode(); + } + if (getDataSetsCount() > 0) { + hash = (37 * hash) + DATASETS_FIELD_NUMBER; + hash = (53 * hash) + getDataSetsList().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - Object value) { - return (Builder) super.addRepeatedField(field, value); - } + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(org.graylog.integrations.ipfix.IpfixJournal.RawIpfix prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.graylog.integrations.ipfix.IpfixJournal.DataSet) { - return mergeFrom((org.graylog.integrations.ipfix.IpfixJournal.DataSet) other); + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.graylog.integrations.ipfix.RawIpfix} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.graylog.integrations.ipfix.RawIpfix) + org.graylog.integrations.ipfix.IpfixJournal.RawIpfixOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 1: + return internalGetTemplates(); + case 2: + return internalGetOptionTemplates(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFieldReflection( + int number) { + switch (number) { + case 1: + return internalGetMutableTemplates(); + case 2: + return internalGetMutableOptionTemplates(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_RawIpfix_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.class, org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.Builder.class); + } + + // Construct using org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + internalGetMutableTemplates().clear(); + internalGetMutableOptionTemplates().clear(); + if (dataSetsBuilder_ == null) { + dataSets_ = java.util.Collections.emptyList(); + } else { + dataSets_ = null; + dataSetsBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000004); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor; + } + + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.RawIpfix getDefaultInstanceForType() { + return org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.getDefaultInstance(); + } + + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.RawIpfix build() { + org.graylog.integrations.ipfix.IpfixJournal.RawIpfix result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.RawIpfix buildPartial() { + org.graylog.integrations.ipfix.IpfixJournal.RawIpfix result = new org.graylog.integrations.ipfix.IpfixJournal.RawIpfix(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields(org.graylog.integrations.ipfix.IpfixJournal.RawIpfix result) { + if (dataSetsBuilder_ == null) { + if (((bitField0_ & 0x00000004) != 0)) { + dataSets_ = java.util.Collections.unmodifiableList(dataSets_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.dataSets_ = dataSets_; + } else { + result.dataSets_ = dataSetsBuilder_.build(); + } + } + + private void buildPartial0(org.graylog.integrations.ipfix.IpfixJournal.RawIpfix result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.templates_ = internalGetTemplates(); + result.templates_.makeImmutable(); + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.optionTemplates_ = internalGetOptionTemplates(); + result.optionTemplates_.makeImmutable(); + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.graylog.integrations.ipfix.IpfixJournal.RawIpfix) { + return mergeFrom((org.graylog.integrations.ipfix.IpfixJournal.RawIpfix)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.graylog.integrations.ipfix.IpfixJournal.RawIpfix other) { + if (other == org.graylog.integrations.ipfix.IpfixJournal.RawIpfix.getDefaultInstance()) return this; + internalGetMutableTemplates().mergeFrom( + other.internalGetTemplates()); + bitField0_ |= 0x00000001; + internalGetMutableOptionTemplates().mergeFrom( + other.internalGetOptionTemplates()); + bitField0_ |= 0x00000002; + if (dataSetsBuilder_ == null) { + if (!other.dataSets_.isEmpty()) { + if (dataSets_.isEmpty()) { + dataSets_ = other.dataSets_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureDataSetsIsMutable(); + dataSets_.addAll(other.dataSets_); + } + onChanged(); + } + } else { + if (!other.dataSets_.isEmpty()) { + if (dataSetsBuilder_.isEmpty()) { + dataSetsBuilder_.dispose(); + dataSetsBuilder_ = null; + dataSets_ = other.dataSets_; + bitField0_ = (bitField0_ & ~0x00000004); + dataSetsBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + getDataSetsFieldBuilder() : null; + } else { + dataSetsBuilder_.addAllMessages(other.dataSets_); + } + } + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + for (int i = 0; i < getDataSetsCount(); i++) { + if (!getDataSets(i).isInitialized()) { + return false; + } + } + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + com.google.protobuf.MapEntry + templates__ = input.readMessage( + TemplatesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); + internalGetMutableTemplates().getMutableMap().put( + templates__.getKey(), templates__.getValue()); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: { + com.google.protobuf.MapEntry + optionTemplates__ = input.readMessage( + OptionTemplatesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); + internalGetMutableOptionTemplates().getMutableMap().put( + optionTemplates__.getKey(), optionTemplates__.getValue()); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: { + org.graylog.integrations.ipfix.IpfixJournal.DataSet m = + input.readMessage( + org.graylog.integrations.ipfix.IpfixJournal.DataSet.PARSER, + extensionRegistry); + if (dataSetsBuilder_ == null) { + ensureDataSetsIsMutable(); + dataSets_.add(m); } else { - super.mergeFrom(other); - return this; + dataSetsBuilder_.addMessage(m); } - } - - public Builder mergeFrom(org.graylog.integrations.ipfix.IpfixJournal.DataSet other) { - if (other == org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance()) return this; - if (other.hasTimestampEpochSeconds()) { - setTimestampEpochSeconds(other.getTimestampEpochSeconds()); - } - if (other.hasTemplateId()) { - setTemplateId(other.getTemplateId()); - } - if (other.hasDataRecords()) { - setDataRecords(other.getDataRecords()); + break; + } // case 26 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private com.google.protobuf.MapField< + java.lang.Integer, com.google.protobuf.ByteString> templates_; + private com.google.protobuf.MapField + internalGetTemplates() { + if (templates_ == null) { + return com.google.protobuf.MapField.emptyMapField( + TemplatesDefaultEntryHolder.defaultEntry); + } + return templates_; + } + private com.google.protobuf.MapField + internalGetMutableTemplates() { + if (templates_ == null) { + templates_ = com.google.protobuf.MapField.newMapField( + TemplatesDefaultEntryHolder.defaultEntry); + } + if (!templates_.isMutable()) { + templates_ = templates_.copy(); + } + bitField0_ |= 0x00000001; + onChanged(); + return templates_; + } + public int getTemplatesCount() { + return internalGetTemplates().getMap().size(); + } + /** + *
    +       * all applicable templates that are referenced by the data sets
    +       * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public boolean containsTemplates( + int key) { + + return internalGetTemplates().getMap().containsKey(key); + } + /** + * Use {@link #getTemplatesMap()} instead. + */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getTemplates() { + return getTemplatesMap(); + } + /** + *
    +       * all applicable templates that are referenced by the data sets
    +       * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public java.util.Map getTemplatesMap() { + return internalGetTemplates().getMap(); + } + /** + *
    +       * all applicable templates that are referenced by the data sets
    +       * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getTemplatesOrDefault( + int key, + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + + java.util.Map map = + internalGetTemplates().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + *
    +       * all applicable templates that are referenced by the data sets
    +       * 
    + * + * map<uint32, bytes> templates = 1; + */ + @java.lang.Override + public com.google.protobuf.ByteString getTemplatesOrThrow( + int key) { + + java.util.Map map = + internalGetTemplates().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + public Builder clearTemplates() { + bitField0_ = (bitField0_ & ~0x00000001); + internalGetMutableTemplates().getMutableMap() + .clear(); + return this; + } + /** + *
    +       * all applicable templates that are referenced by the data sets
    +       * 
    + * + * map<uint32, bytes> templates = 1; + */ + public Builder removeTemplates( + int key) { + + internalGetMutableTemplates().getMutableMap() + .remove(key); + return this; + } + /** + * Use alternate mutation accessors instead. + */ + @java.lang.Deprecated + public java.util.Map + getMutableTemplates() { + bitField0_ |= 0x00000001; + return internalGetMutableTemplates().getMutableMap(); + } + /** + *
    +       * all applicable templates that are referenced by the data sets
    +       * 
    + * + * map<uint32, bytes> templates = 1; + */ + public Builder putTemplates( + int key, + com.google.protobuf.ByteString value) { + + if (value == null) { throw new NullPointerException("map value"); } + internalGetMutableTemplates().getMutableMap() + .put(key, value); + bitField0_ |= 0x00000001; + return this; + } + /** + *
    +       * all applicable templates that are referenced by the data sets
    +       * 
    + * + * map<uint32, bytes> templates = 1; + */ + public Builder putAllTemplates( + java.util.Map values) { + internalGetMutableTemplates().getMutableMap() + .putAll(values); + bitField0_ |= 0x00000001; + return this; + } + + private com.google.protobuf.MapField< + java.lang.Integer, com.google.protobuf.ByteString> optionTemplates_; + private com.google.protobuf.MapField + internalGetOptionTemplates() { + if (optionTemplates_ == null) { + return com.google.protobuf.MapField.emptyMapField( + OptionTemplatesDefaultEntryHolder.defaultEntry); + } + return optionTemplates_; + } + private com.google.protobuf.MapField + internalGetMutableOptionTemplates() { + if (optionTemplates_ == null) { + optionTemplates_ = com.google.protobuf.MapField.newMapField( + OptionTemplatesDefaultEntryHolder.defaultEntry); + } + if (!optionTemplates_.isMutable()) { + optionTemplates_ = optionTemplates_.copy(); + } + bitField0_ |= 0x00000002; + onChanged(); + return optionTemplates_; + } + public int getOptionTemplatesCount() { + return internalGetOptionTemplates().getMap().size(); + } + /** + *
    +       * all applicable options templates that are references by the data sets
    +       * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public boolean containsOptionTemplates( + int key) { + + return internalGetOptionTemplates().getMap().containsKey(key); + } + /** + * Use {@link #getOptionTemplatesMap()} instead. + */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptionTemplates() { + return getOptionTemplatesMap(); + } + /** + *
    +       * all applicable options templates that are references by the data sets
    +       * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public java.util.Map getOptionTemplatesMap() { + return internalGetOptionTemplates().getMap(); + } + /** + *
    +       * all applicable options templates that are references by the data sets
    +       * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getOptionTemplatesOrDefault( + int key, + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + + java.util.Map map = + internalGetOptionTemplates().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + *
    +       * all applicable options templates that are references by the data sets
    +       * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + @java.lang.Override + public com.google.protobuf.ByteString getOptionTemplatesOrThrow( + int key) { + + java.util.Map map = + internalGetOptionTemplates().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + public Builder clearOptionTemplates() { + bitField0_ = (bitField0_ & ~0x00000002); + internalGetMutableOptionTemplates().getMutableMap() + .clear(); + return this; + } + /** + *
    +       * all applicable options templates that are references by the data sets
    +       * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + public Builder removeOptionTemplates( + int key) { + + internalGetMutableOptionTemplates().getMutableMap() + .remove(key); + return this; + } + /** + * Use alternate mutation accessors instead. + */ + @java.lang.Deprecated + public java.util.Map + getMutableOptionTemplates() { + bitField0_ |= 0x00000002; + return internalGetMutableOptionTemplates().getMutableMap(); + } + /** + *
    +       * all applicable options templates that are references by the data sets
    +       * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + public Builder putOptionTemplates( + int key, + com.google.protobuf.ByteString value) { + + if (value == null) { throw new NullPointerException("map value"); } + internalGetMutableOptionTemplates().getMutableMap() + .put(key, value); + bitField0_ |= 0x00000002; + return this; + } + /** + *
    +       * all applicable options templates that are references by the data sets
    +       * 
    + * + * map<uint32, bytes> optionTemplates = 2; + */ + public Builder putAllOptionTemplates( + java.util.Map values) { + internalGetMutableOptionTemplates().getMutableMap() + .putAll(values); + bitField0_ |= 0x00000002; + return this; + } + + private java.util.List dataSets_ = + java.util.Collections.emptyList(); + private void ensureDataSetsIsMutable() { + if (!((bitField0_ & 0x00000004) != 0)) { + dataSets_ = new java.util.ArrayList(dataSets_); + bitField0_ |= 0x00000004; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + org.graylog.integrations.ipfix.IpfixJournal.DataSet, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder, org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder> dataSetsBuilder_; + + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public java.util.List getDataSetsList() { + if (dataSetsBuilder_ == null) { + return java.util.Collections.unmodifiableList(dataSets_); + } else { + return dataSetsBuilder_.getMessageList(); + } + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public int getDataSetsCount() { + if (dataSetsBuilder_ == null) { + return dataSets_.size(); + } else { + return dataSetsBuilder_.getCount(); + } + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDataSets(int index) { + if (dataSetsBuilder_ == null) { + return dataSets_.get(index); + } else { + return dataSetsBuilder_.getMessage(index); + } + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder setDataSets( + int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet value) { + if (dataSetsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureDataSetsIsMutable(); + dataSets_.set(index, value); + onChanged(); + } else { + dataSetsBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder setDataSets( + int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder builderForValue) { + if (dataSetsBuilder_ == null) { + ensureDataSetsIsMutable(); + dataSets_.set(index, builderForValue.build()); + onChanged(); + } else { + dataSetsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder addDataSets(org.graylog.integrations.ipfix.IpfixJournal.DataSet value) { + if (dataSetsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureDataSetsIsMutable(); + dataSets_.add(value); + onChanged(); + } else { + dataSetsBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder addDataSets( + int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet value) { + if (dataSetsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureDataSetsIsMutable(); + dataSets_.add(index, value); + onChanged(); + } else { + dataSetsBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder addDataSets( + org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder builderForValue) { + if (dataSetsBuilder_ == null) { + ensureDataSetsIsMutable(); + dataSets_.add(builderForValue.build()); + onChanged(); + } else { + dataSetsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder addDataSets( + int index, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder builderForValue) { + if (dataSetsBuilder_ == null) { + ensureDataSetsIsMutable(); + dataSets_.add(index, builderForValue.build()); + onChanged(); + } else { + dataSetsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder addAllDataSets( + java.lang.Iterable values) { + if (dataSetsBuilder_ == null) { + ensureDataSetsIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, dataSets_); + onChanged(); + } else { + dataSetsBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder clearDataSets() { + if (dataSetsBuilder_ == null) { + dataSets_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + } else { + dataSetsBuilder_.clear(); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public Builder removeDataSets(int index) { + if (dataSetsBuilder_ == null) { + ensureDataSetsIsMutable(); + dataSets_.remove(index); + onChanged(); + } else { + dataSetsBuilder_.remove(index); + } + return this; + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder getDataSetsBuilder( + int index) { + return getDataSetsFieldBuilder().getBuilder(index); + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder getDataSetsOrBuilder( + int index) { + if (dataSetsBuilder_ == null) { + return dataSets_.get(index); } else { + return dataSetsBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public java.util.List + getDataSetsOrBuilderList() { + if (dataSetsBuilder_ != null) { + return dataSetsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(dataSets_); + } + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder addDataSetsBuilder() { + return getDataSetsFieldBuilder().addBuilder( + org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance()); + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder addDataSetsBuilder( + int index) { + return getDataSetsFieldBuilder().addBuilder( + index, org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance()); + } + /** + * repeated .org.graylog.integrations.ipfix.DataSet dataSets = 3; + */ + public java.util.List + getDataSetsBuilderList() { + return getDataSetsFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilderV3< + org.graylog.integrations.ipfix.IpfixJournal.DataSet, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder, org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder> + getDataSetsFieldBuilder() { + if (dataSetsBuilder_ == null) { + dataSetsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< + org.graylog.integrations.ipfix.IpfixJournal.DataSet, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder, org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder>( + dataSets_, + ((bitField0_ & 0x00000004) != 0), + getParentForChildren(), + isClean()); + dataSets_ = null; + } + return dataSetsBuilder_; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:org.graylog.integrations.ipfix.RawIpfix) + } - public final boolean isInitialized() { - if (!hasTimestampEpochSeconds()) { - return false; - } - if (!hasTemplateId()) { - return false; - } - if (!hasDataRecords()) { - return false; - } - return true; - } + // @@protoc_insertion_point(class_scope:org.graylog.integrations.ipfix.RawIpfix) + private static final org.graylog.integrations.ipfix.IpfixJournal.RawIpfix DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new org.graylog.integrations.ipfix.IpfixJournal.RawIpfix(); + } - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - org.graylog.integrations.ipfix.IpfixJournal.DataSet parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.graylog.integrations.ipfix.IpfixJournal.DataSet) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } + public static org.graylog.integrations.ipfix.IpfixJournal.RawIpfix getDefaultInstance() { + return DEFAULT_INSTANCE; + } - private int bitField0_; + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public RawIpfix parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } - private long timestampEpochSeconds_; + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } - /** - * required uint64 timestampEpochSeconds = 1; - */ - public boolean hasTimestampEpochSeconds() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.RawIpfix getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } - /** - * required uint64 timestampEpochSeconds = 1; - */ - public long getTimestampEpochSeconds() { - return timestampEpochSeconds_; - } + } - /** - * required uint64 timestampEpochSeconds = 1; - */ - public Builder setTimestampEpochSeconds(long value) { - bitField0_ |= 0x00000001; - timestampEpochSeconds_ = value; - onChanged(); - return this; - } + public interface DataSetOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.graylog.integrations.ipfix.DataSet) + com.google.protobuf.MessageOrBuilder { - /** - * required uint64 timestampEpochSeconds = 1; - */ - public Builder clearTimestampEpochSeconds() { - bitField0_ = (bitField0_ & ~0x00000001); - timestampEpochSeconds_ = 0L; - onChanged(); - return this; - } + /** + * required uint64 timestampEpochSeconds = 1; + * @return Whether the timestampEpochSeconds field is set. + */ + boolean hasTimestampEpochSeconds(); + /** + * required uint64 timestampEpochSeconds = 1; + * @return The timestampEpochSeconds. + */ + long getTimestampEpochSeconds(); - private int templateId_; + /** + * required uint32 templateId = 2; + * @return Whether the templateId field is set. + */ + boolean hasTemplateId(); + /** + * required uint32 templateId = 2; + * @return The templateId. + */ + int getTemplateId(); - /** - * required uint32 templateId = 2; - */ - public boolean hasTemplateId() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } + /** + * required bytes dataRecords = 3; + * @return Whether the dataRecords field is set. + */ + boolean hasDataRecords(); + /** + * required bytes dataRecords = 3; + * @return The dataRecords. + */ + com.google.protobuf.ByteString getDataRecords(); + } + /** + * Protobuf type {@code org.graylog.integrations.ipfix.DataSet} + */ + public static final class DataSet extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.graylog.integrations.ipfix.DataSet) + DataSetOrBuilder { + private static final long serialVersionUID = 0L; + // Use DataSet.newBuilder() to construct. + private DataSet(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private DataSet() { + dataRecords_ = com.google.protobuf.ByteString.EMPTY; + } - /** - * required uint32 templateId = 2; - */ - public int getTemplateId() { - return templateId_; - } + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new DataSet(); + } - /** - * required uint32 templateId = 2; - */ - public Builder setTemplateId(int value) { - bitField0_ |= 0x00000002; - templateId_ = value; - onChanged(); - return this; - } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_DataSet_descriptor; + } - /** - * required uint32 templateId = 2; - */ - public Builder clearTemplateId() { - bitField0_ = (bitField0_ & ~0x00000002); - templateId_ = 0; - onChanged(); - return this; - } + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_DataSet_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.graylog.integrations.ipfix.IpfixJournal.DataSet.class, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder.class); + } - private com.google.protobuf.ByteString dataRecords_ = com.google.protobuf.ByteString.EMPTY; + private int bitField0_; + public static final int TIMESTAMPEPOCHSECONDS_FIELD_NUMBER = 1; + private long timestampEpochSeconds_ = 0L; + /** + * required uint64 timestampEpochSeconds = 1; + * @return Whether the timestampEpochSeconds field is set. + */ + @java.lang.Override + public boolean hasTimestampEpochSeconds() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * required uint64 timestampEpochSeconds = 1; + * @return The timestampEpochSeconds. + */ + @java.lang.Override + public long getTimestampEpochSeconds() { + return timestampEpochSeconds_; + } - /** - * required bytes dataRecords = 3; - */ - public boolean hasDataRecords() { - return ((bitField0_ & 0x00000004) == 0x00000004); - } + public static final int TEMPLATEID_FIELD_NUMBER = 2; + private int templateId_ = 0; + /** + * required uint32 templateId = 2; + * @return Whether the templateId field is set. + */ + @java.lang.Override + public boolean hasTemplateId() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * required uint32 templateId = 2; + * @return The templateId. + */ + @java.lang.Override + public int getTemplateId() { + return templateId_; + } - /** - * required bytes dataRecords = 3; - */ - public com.google.protobuf.ByteString getDataRecords() { - return dataRecords_; - } + public static final int DATARECORDS_FIELD_NUMBER = 3; + private com.google.protobuf.ByteString dataRecords_ = com.google.protobuf.ByteString.EMPTY; + /** + * required bytes dataRecords = 3; + * @return Whether the dataRecords field is set. + */ + @java.lang.Override + public boolean hasDataRecords() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * required bytes dataRecords = 3; + * @return The dataRecords. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDataRecords() { + return dataRecords_; + } - /** - * required bytes dataRecords = 3; - */ - public Builder setDataRecords(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; - dataRecords_ = value; - onChanged(); - return this; - } + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + if (!hasTimestampEpochSeconds()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasTemplateId()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasDataRecords()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } - /** - * required bytes dataRecords = 3; - */ - public Builder clearDataRecords() { - bitField0_ = (bitField0_ & ~0x00000004); - dataRecords_ = getDefaultInstance().getDataRecords(); - onChanged(); - return this; - } + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeUInt64(1, timestampEpochSeconds_); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeUInt32(2, templateId_); + } + if (((bitField0_ & 0x00000004) != 0)) { + output.writeBytes(3, dataRecords_); + } + getUnknownFields().writeTo(output); + } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream + .computeUInt64Size(1, timestampEpochSeconds_); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream + .computeUInt32Size(2, templateId_); + } + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, dataRecords_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.graylog.integrations.ipfix.IpfixJournal.DataSet)) { + return super.equals(obj); + } + org.graylog.integrations.ipfix.IpfixJournal.DataSet other = (org.graylog.integrations.ipfix.IpfixJournal.DataSet) obj; + + if (hasTimestampEpochSeconds() != other.hasTimestampEpochSeconds()) return false; + if (hasTimestampEpochSeconds()) { + if (getTimestampEpochSeconds() + != other.getTimestampEpochSeconds()) return false; + } + if (hasTemplateId() != other.hasTemplateId()) return false; + if (hasTemplateId()) { + if (getTemplateId() + != other.getTemplateId()) return false; + } + if (hasDataRecords() != other.hasDataRecords()) return false; + if (hasDataRecords()) { + if (!getDataRecords() + .equals(other.getDataRecords())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasTimestampEpochSeconds()) { + hash = (37 * hash) + TIMESTAMPEPOCHSECONDS_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getTimestampEpochSeconds()); + } + if (hasTemplateId()) { + hash = (37 * hash) + TEMPLATEID_FIELD_NUMBER; + hash = (53 * hash) + getTemplateId(); + } + if (hasDataRecords()) { + hash = (37 * hash) + DATARECORDS_FIELD_NUMBER; + hash = (53 * hash) + getDataRecords().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } - // @@protoc_insertion_point(builder_scope:org.graylog.plugins.ipfix.DataSet) - } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } - // @@protoc_insertion_point(class_scope:org.graylog.plugins.ipfix.DataSet) - private static final org.graylog.integrations.ipfix.IpfixJournal.DataSet DEFAULT_INSTANCE; + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } - static { - DEFAULT_INSTANCE = new org.graylog.integrations.ipfix.IpfixJournal.DataSet(); - } + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(org.graylog.integrations.ipfix.IpfixJournal.DataSet prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } - public static org.graylog.integrations.ipfix.IpfixJournal.DataSet getDefaultInstance() { - return DEFAULT_INSTANCE; - } + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.graylog.integrations.ipfix.DataSet} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.graylog.integrations.ipfix.DataSet) + org.graylog.integrations.ipfix.IpfixJournal.DataSetOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_DataSet_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_DataSet_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.graylog.integrations.ipfix.IpfixJournal.DataSet.class, org.graylog.integrations.ipfix.IpfixJournal.DataSet.Builder.class); + } + + // Construct using org.graylog.integrations.ipfix.IpfixJournal.DataSet.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + timestampEpochSeconds_ = 0L; + templateId_ = 0; + dataRecords_ = com.google.protobuf.ByteString.EMPTY; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.graylog.integrations.ipfix.IpfixJournal.internal_static_org_graylog_integrations_ipfix_DataSet_descriptor; + } + + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDefaultInstanceForType() { + return org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance(); + } + + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.DataSet build() { + org.graylog.integrations.ipfix.IpfixJournal.DataSet result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.DataSet buildPartial() { + org.graylog.integrations.ipfix.IpfixJournal.DataSet result = new org.graylog.integrations.ipfix.IpfixJournal.DataSet(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(org.graylog.integrations.ipfix.IpfixJournal.DataSet result) { + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.timestampEpochSeconds_ = timestampEpochSeconds_; + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.templateId_ = templateId_; + to_bitField0_ |= 0x00000002; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.dataRecords_ = dataRecords_; + to_bitField0_ |= 0x00000004; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.graylog.integrations.ipfix.IpfixJournal.DataSet) { + return mergeFrom((org.graylog.integrations.ipfix.IpfixJournal.DataSet)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.graylog.integrations.ipfix.IpfixJournal.DataSet other) { + if (other == org.graylog.integrations.ipfix.IpfixJournal.DataSet.getDefaultInstance()) return this; + if (other.hasTimestampEpochSeconds()) { + setTimestampEpochSeconds(other.getTimestampEpochSeconds()); + } + if (other.hasTemplateId()) { + setTemplateId(other.getTemplateId()); + } + if (other.hasDataRecords()) { + setDataRecords(other.getDataRecords()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + if (!hasTimestampEpochSeconds()) { + return false; + } + if (!hasTemplateId()) { + return false; + } + if (!hasDataRecords()) { + return false; + } + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + timestampEpochSeconds_ = input.readUInt64(); + bitField0_ |= 0x00000001; + break; + } // case 8 + case 16: { + templateId_ = input.readUInt32(); + bitField0_ |= 0x00000002; + break; + } // case 16 + case 26: { + dataRecords_ = input.readBytes(); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private long timestampEpochSeconds_ ; + /** + * required uint64 timestampEpochSeconds = 1; + * @return Whether the timestampEpochSeconds field is set. + */ + @java.lang.Override + public boolean hasTimestampEpochSeconds() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * required uint64 timestampEpochSeconds = 1; + * @return The timestampEpochSeconds. + */ + @java.lang.Override + public long getTimestampEpochSeconds() { + return timestampEpochSeconds_; + } + /** + * required uint64 timestampEpochSeconds = 1; + * @param value The timestampEpochSeconds to set. + * @return This builder for chaining. + */ + public Builder setTimestampEpochSeconds(long value) { + + timestampEpochSeconds_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * required uint64 timestampEpochSeconds = 1; + * @return This builder for chaining. + */ + public Builder clearTimestampEpochSeconds() { + bitField0_ = (bitField0_ & ~0x00000001); + timestampEpochSeconds_ = 0L; + onChanged(); + return this; + } + + private int templateId_ ; + /** + * required uint32 templateId = 2; + * @return Whether the templateId field is set. + */ + @java.lang.Override + public boolean hasTemplateId() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * required uint32 templateId = 2; + * @return The templateId. + */ + @java.lang.Override + public int getTemplateId() { + return templateId_; + } + /** + * required uint32 templateId = 2; + * @param value The templateId to set. + * @return This builder for chaining. + */ + public Builder setTemplateId(int value) { + + templateId_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * required uint32 templateId = 2; + * @return This builder for chaining. + */ + public Builder clearTemplateId() { + bitField0_ = (bitField0_ & ~0x00000002); + templateId_ = 0; + onChanged(); + return this; + } + + private com.google.protobuf.ByteString dataRecords_ = com.google.protobuf.ByteString.EMPTY; + /** + * required bytes dataRecords = 3; + * @return Whether the dataRecords field is set. + */ + @java.lang.Override + public boolean hasDataRecords() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * required bytes dataRecords = 3; + * @return The dataRecords. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDataRecords() { + return dataRecords_; + } + /** + * required bytes dataRecords = 3; + * @param value The dataRecords to set. + * @return This builder for chaining. + */ + public Builder setDataRecords(com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + dataRecords_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * required bytes dataRecords = 3; + * @return This builder for chaining. + */ + public Builder clearDataRecords() { + bitField0_ = (bitField0_ & ~0x00000004); + dataRecords_ = getDefaultInstance().getDataRecords(); + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:org.graylog.integrations.ipfix.DataSet) + } - @Deprecated - public static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public DataSet parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new DataSet(input, extensionRegistry); - } - }; + // @@protoc_insertion_point(class_scope:org.graylog.integrations.ipfix.DataSet) + private static final org.graylog.integrations.ipfix.IpfixJournal.DataSet DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new org.graylog.integrations.ipfix.IpfixJournal.DataSet(); + } - public static com.google.protobuf.Parser parser() { - return PARSER; - } + public static org.graylog.integrations.ipfix.IpfixJournal.DataSet getDefaultInstance() { + return DEFAULT_INSTANCE; + } - @Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public DataSet parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } - public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + @java.lang.Override + public org.graylog.integrations.ipfix.IpfixJournal.DataSet getDefaultInstanceForType() { + return DEFAULT_INSTANCE; } - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor; - private static final + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor; + private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_org_graylog_plugins_ipfix_RawIpfix_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_org_graylog_plugins_ipfix_RawIpfix_TemplatesEntry_descriptor; - private static final + internal_static_org_graylog_integrations_ipfix_RawIpfix_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_graylog_integrations_ipfix_RawIpfix_TemplatesEntry_descriptor; + private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_org_graylog_plugins_ipfix_RawIpfix_TemplatesEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_org_graylog_plugins_ipfix_RawIpfix_OptionTemplatesEntry_descriptor; - private static final + internal_static_org_graylog_integrations_ipfix_RawIpfix_TemplatesEntry_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_graylog_integrations_ipfix_RawIpfix_OptionTemplatesEntry_descriptor; + private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_org_graylog_plugins_ipfix_RawIpfix_OptionTemplatesEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_org_graylog_plugins_ipfix_DataSet_descriptor; - private static final + internal_static_org_graylog_integrations_ipfix_RawIpfix_OptionTemplatesEntry_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_graylog_integrations_ipfix_DataSet_descriptor; + private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_org_graylog_plugins_ipfix_DataSet_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - - static { - String[] descriptorData = { - "\n&src/main/resources/ipfix_journal.proto" + - "\022\031org.graylog.plugins.ipfix\"\304\002\n\010RawIpfix" + - "\022E\n\ttemplates\030\001 \003(\01322.org.graylog.plugin" + - "s.ipfix.RawIpfix.TemplatesEntry\022Q\n\017optio" + - "nTemplates\030\002 \003(\01328.org.graylog.plugins.i" + - "pfix.RawIpfix.OptionTemplatesEntry\0224\n\010da" + - "taSets\030\003 \003(\0132\".org.graylog.plugins.ipfix" + - ".DataSet\0320\n\016TemplatesEntry\022\013\n\003key\030\001 \001(\r\022" + - "\r\n\005value\030\002 \001(\014:\0028\001\0326\n\024OptionTemplatesEnt" + - "ry\022\013\n\003key\030\001 \001(\r\022\r\n\005value\030\002 \001(\014:\0028\001\"Q\n\007Da", - "taSet\022\035\n\025timestampEpochSeconds\030\001 \002(\004\022\022\n\n" + - "templateId\030\002 \002(\r\022\023\n\013dataRecords\030\003 \002(\014B)\n" + - "\031org.graylog.plugins.ipfixB\014IpfixJournal" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[]{ - }, assigner); - internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_org_graylog_plugins_ipfix_RawIpfix_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor, - new String[]{"Templates", "OptionTemplates", "DataSets",}); - internal_static_org_graylog_plugins_ipfix_RawIpfix_TemplatesEntry_descriptor = - internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor.getNestedTypes().get(0); - internal_static_org_graylog_plugins_ipfix_RawIpfix_TemplatesEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_org_graylog_plugins_ipfix_RawIpfix_TemplatesEntry_descriptor, - new String[]{"Key", "Value",}); - internal_static_org_graylog_plugins_ipfix_RawIpfix_OptionTemplatesEntry_descriptor = - internal_static_org_graylog_plugins_ipfix_RawIpfix_descriptor.getNestedTypes().get(1); - internal_static_org_graylog_plugins_ipfix_RawIpfix_OptionTemplatesEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_org_graylog_plugins_ipfix_RawIpfix_OptionTemplatesEntry_descriptor, - new String[]{"Key", "Value",}); - internal_static_org_graylog_plugins_ipfix_DataSet_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_org_graylog_plugins_ipfix_DataSet_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_org_graylog_plugins_ipfix_DataSet_descriptor, - new String[]{"TimestampEpochSeconds", "TemplateId", "DataRecords",}); - } - - // @@protoc_insertion_point(outer_class_scope) + internal_static_org_graylog_integrations_ipfix_DataSet_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n&src/main/resources/ipfix_journal.proto" + + "\022\036org.graylog.integrations.ipfix\"\323\002\n\010Raw" + + "Ipfix\022J\n\ttemplates\030\001 \003(\01327.org.graylog.i" + + "ntegrations.ipfix.RawIpfix.TemplatesEntr" + + "y\022V\n\017optionTemplates\030\002 \003(\0132=.org.graylog" + + ".integrations.ipfix.RawIpfix.OptionTempl" + + "atesEntry\0229\n\010dataSets\030\003 \003(\0132\'.org.graylo" + + "g.integrations.ipfix.DataSet\0320\n\016Template" + + "sEntry\022\013\n\003key\030\001 \001(\r\022\r\n\005value\030\002 \001(\014:\0028\001\0326" + + "\n\024OptionTemplatesEntry\022\013\n\003key\030\001 \001(\r\022\r\n\005v" + + "alue\030\002 \001(\014:\0028\001\"Q\n\007DataSet\022\035\n\025timestampEp" + + "ochSeconds\030\001 \002(\004\022\022\n\ntemplateId\030\002 \002(\r\022\023\n\013" + + "dataRecords\030\003 \002(\014B.\n\036org.graylog.integra" + + "tions.ipfixB\014IpfixJournal" + }; + descriptor = com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }); + internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_org_graylog_integrations_ipfix_RawIpfix_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor, + new java.lang.String[] { "Templates", "OptionTemplates", "DataSets", }); + internal_static_org_graylog_integrations_ipfix_RawIpfix_TemplatesEntry_descriptor = + internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor.getNestedTypes().get(0); + internal_static_org_graylog_integrations_ipfix_RawIpfix_TemplatesEntry_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog_integrations_ipfix_RawIpfix_TemplatesEntry_descriptor, + new java.lang.String[] { "Key", "Value", }); + internal_static_org_graylog_integrations_ipfix_RawIpfix_OptionTemplatesEntry_descriptor = + internal_static_org_graylog_integrations_ipfix_RawIpfix_descriptor.getNestedTypes().get(1); + internal_static_org_graylog_integrations_ipfix_RawIpfix_OptionTemplatesEntry_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog_integrations_ipfix_RawIpfix_OptionTemplatesEntry_descriptor, + new java.lang.String[] { "Key", "Value", }); + internal_static_org_graylog_integrations_ipfix_DataSet_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_org_graylog_integrations_ipfix_DataSet_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog_integrations_ipfix_DataSet_descriptor, + new java.lang.String[] { "TimestampEpochSeconds", "TemplateId", "DataRecords", }); + } + + // @@protoc_insertion_point(outer_class_scope) } diff --git a/graylog2-server/src/main/java/org/graylog/integrations/ipfix/codecs/IpfixCodec.java b/graylog2-server/src/main/java/org/graylog/integrations/ipfix/codecs/IpfixCodec.java index 58dedc5c242d..1dd8a27e9ad9 100644 --- a/graylog2-server/src/main/java/org/graylog/integrations/ipfix/codecs/IpfixCodec.java +++ b/graylog2-server/src/main/java/org/graylog/integrations/ipfix/codecs/IpfixCodec.java @@ -213,7 +213,7 @@ public Collection decodeMessages(@Nonnull RawMessage rawMessage) { }) .collect(Collectors.toList()); } catch (Exception e) { - throw InputProcessingException.create("Unable to parse ipfix journal message", rawMessage); + throw InputProcessingException.create("Unable to parse ipfix journal message", e, rawMessage); } } diff --git a/graylog2-server/src/main/java/org/graylog/plugins/netflow/v9/NetFlowV9Journal.java b/graylog2-server/src/main/java/org/graylog/plugins/netflow/v9/NetFlowV9Journal.java index a10ed3de2660..ffe0b4cd9179 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/netflow/v9/NetFlowV9Journal.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/netflow/v9/NetFlowV9Journal.java @@ -14,11 +14,12 @@ * along with this program. If not, see * . */ -package org.graylog.plugins.netflow.v9; +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: src/main/resources/netflow_v9.proto -import javax.annotation.Generated; +// Protobuf Java Version: 3.25.6 +package org.graylog.plugins.netflow.v9; -@Generated("Generated by Protobuf") public final class NetFlowV9Journal { private NetFlowV9Journal() {} public static void registerAllExtensions( @@ -73,10 +74,11 @@ boolean containsTemplates( * * map<uint32, bytes> templates = 1; */ - - com.google.protobuf.ByteString getTemplatesOrDefault( + /* nullable */ +com.google.protobuf.ByteString getTemplatesOrDefault( int key, - com.google.protobuf.ByteString defaultValue); + /* nullable */ +com.google.protobuf.ByteString defaultValue); /** *
          * all applicable templates that are referenced by the packets
    @@ -84,7 +86,6 @@ com.google.protobuf.ByteString getTemplatesOrDefault(
          *
          * map<uint32, bytes> templates = 1;
          */
    -
         com.google.protobuf.ByteString getTemplatesOrThrow(
             int key);
     
    @@ -127,10 +128,11 @@ boolean containsOptionTemplate(
          *
          * map<uint32, bytes> optionTemplate = 2;
          */
    -
    -    com.google.protobuf.ByteString getOptionTemplateOrDefault(
    +    /* nullable */
    +com.google.protobuf.ByteString getOptionTemplateOrDefault(
             int key,
    -        com.google.protobuf.ByteString defaultValue);
    +        /* nullable */
    +com.google.protobuf.ByteString defaultValue);
         /**
          * 
          * there is only one option template, but we need to know its template id, so a map is the easiest way to find it
    @@ -138,7 +140,6 @@ com.google.protobuf.ByteString getOptionTemplateOrDefault(
          *
          * map<uint32, bytes> optionTemplate = 2;
          */
    -
         com.google.protobuf.ByteString getOptionTemplateOrThrow(
             int key);
     
    @@ -150,6 +151,7 @@ com.google.protobuf.ByteString getOptionTemplateOrThrow(
          * 
    * * repeated bytes packets = 3; + * @return A list containing the packets. */ java.util.List getPacketsList(); /** @@ -160,6 +162,7 @@ com.google.protobuf.ByteString getOptionTemplateOrThrow( *
    * * repeated bytes packets = 3; + * @return The count of packets. */ int getPacketsCount(); /** @@ -170,106 +173,42 @@ com.google.protobuf.ByteString getOptionTemplateOrThrow( * * * repeated bytes packets = 3; + * @param index The index of the element to return. + * @return The packets at the given index. */ com.google.protobuf.ByteString getPackets(int index); } /** * Protobuf type {@code org.graylog.plugins.netflow.v9.RawNetflowV9} */ - public static final class RawNetflowV9 extends + public static final class RawNetflowV9 extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:org.graylog.plugins.netflow.v9.RawNetflowV9) RawNetflowV9OrBuilder { + private static final long serialVersionUID = 0L; // Use RawNetflowV9.newBuilder() to construct. private RawNetflowV9(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); } private RawNetflowV9() { - packets_ = java.util.Collections.emptyList(); + packets_ = emptyList(com.google.protobuf.ByteString.class); } @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private RawNetflowV9( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - templates_ = com.google.protobuf.MapField.newMapField( - TemplatesDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - templates = input.readMessage( - TemplatesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - templates_.getMutableMap().put(templates.getKey(), templates.getValue()); - break; - } - case 18: { - if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - optionTemplate_ = com.google.protobuf.MapField.newMapField( - OptionTemplateDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000002; - } - com.google.protobuf.MapEntry - optionTemplate = input.readMessage( - OptionTemplateDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - optionTemplate_.getMutableMap().put(optionTemplate.getKey(), optionTemplate.getValue()); - break; - } - case 26: { - if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - packets_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000004; - } - packets_.add(input.readBytes()); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - packets_ = java.util.Collections.unmodifiableList(packets_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new RawNetflowV9(); } + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog.plugins.netflow.v9.NetFlowV9Journal.internal_static_org_graylog_plugins_netflow_v9_RawNetflowV9_descriptor; } @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( + @java.lang.Override + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( int number) { switch (number) { case 1: @@ -281,6 +220,7 @@ protected com.google.protobuf.MapField internalGetMapField( "Invalid map field number: " + number); } } + @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog.plugins.netflow.v9.NetFlowV9Journal.internal_static_org_graylog_plugins_netflow_v9_RawNetflowV9_fieldAccessorTable @@ -300,6 +240,7 @@ private static final class TemplatesDefaultEntryHolder { com.google.protobuf.WireFormat.FieldType.BYTES, com.google.protobuf.ByteString.EMPTY); } + @SuppressWarnings("serial") private com.google.protobuf.MapField< java.lang.Integer, com.google.protobuf.ByteString> templates_; private com.google.protobuf.MapField @@ -310,7 +251,6 @@ private static final class TemplatesDefaultEntryHolder { } return templates_; } - public int getTemplatesCount() { return internalGetTemplates().getMap().size(); } @@ -321,15 +261,16 @@ public int getTemplatesCount() { * * map<uint32, bytes> templates = 1; */ - + @java.lang.Override public boolean containsTemplates( int key) { - + return internalGetTemplates().getMap().containsKey(key); } /** * Use {@link #getTemplatesMap()} instead. */ + @java.lang.Override @java.lang.Deprecated public java.util.Map getTemplates() { return getTemplatesMap(); @@ -341,7 +282,7 @@ public java.util.Map getTempl * * map<uint32, bytes> templates = 1; */ - + @java.lang.Override public java.util.Map getTemplatesMap() { return internalGetTemplates().getMap(); } @@ -352,11 +293,13 @@ public java.util.Map getTempl * * map<uint32, bytes> templates = 1; */ - - public com.google.protobuf.ByteString getTemplatesOrDefault( + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getTemplatesOrDefault( int key, - com.google.protobuf.ByteString defaultValue) { - + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + java.util.Map map = internalGetTemplates().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; @@ -368,10 +311,10 @@ public com.google.protobuf.ByteString getTemplatesOrDefault( * * map<uint32, bytes> templates = 1; */ - + @java.lang.Override public com.google.protobuf.ByteString getTemplatesOrThrow( int key) { - + java.util.Map map = internalGetTemplates().getMap(); if (!map.containsKey(key)) { @@ -392,6 +335,7 @@ private static final class OptionTemplateDefaultEntryHolder { com.google.protobuf.WireFormat.FieldType.BYTES, com.google.protobuf.ByteString.EMPTY); } + @SuppressWarnings("serial") private com.google.protobuf.MapField< java.lang.Integer, com.google.protobuf.ByteString> optionTemplate_; private com.google.protobuf.MapField @@ -402,7 +346,6 @@ private static final class OptionTemplateDefaultEntryHolder { } return optionTemplate_; } - public int getOptionTemplateCount() { return internalGetOptionTemplate().getMap().size(); } @@ -413,15 +356,16 @@ public int getOptionTemplateCount() { * * map<uint32, bytes> optionTemplate = 2; */ - + @java.lang.Override public boolean containsOptionTemplate( int key) { - + return internalGetOptionTemplate().getMap().containsKey(key); } /** * Use {@link #getOptionTemplateMap()} instead. */ + @java.lang.Override @java.lang.Deprecated public java.util.Map getOptionTemplate() { return getOptionTemplateMap(); @@ -433,7 +377,7 @@ public java.util.Map getOptio * * map<uint32, bytes> optionTemplate = 2; */ - + @java.lang.Override public java.util.Map getOptionTemplateMap() { return internalGetOptionTemplate().getMap(); } @@ -444,11 +388,13 @@ public java.util.Map getOptio * * map<uint32, bytes> optionTemplate = 2; */ - - public com.google.protobuf.ByteString getOptionTemplateOrDefault( + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getOptionTemplateOrDefault( int key, - com.google.protobuf.ByteString defaultValue) { - + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + java.util.Map map = internalGetOptionTemplate().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; @@ -460,10 +406,10 @@ public com.google.protobuf.ByteString getOptionTemplateOrDefault( * * map<uint32, bytes> optionTemplate = 2; */ - + @java.lang.Override public com.google.protobuf.ByteString getOptionTemplateOrThrow( int key) { - + java.util.Map map = internalGetOptionTemplate().getMap(); if (!map.containsKey(key)) { @@ -473,7 +419,9 @@ public com.google.protobuf.ByteString getOptionTemplateOrThrow( } public static final int PACKETS_FIELD_NUMBER = 3; - private java.util.List packets_; + @SuppressWarnings("serial") + private com.google.protobuf.Internal.ProtobufList packets_ = + emptyList(com.google.protobuf.ByteString.class); /** *
          * the raw packets as received. it might contain templates as well, but even if it does the above fields will have that information, too
    @@ -482,7 +430,9 @@ public com.google.protobuf.ByteString getOptionTemplateOrThrow(
          * 
    * * repeated bytes packets = 3; + * @return A list containing the packets. */ + @java.lang.Override public java.util.List getPacketsList() { return packets_; @@ -495,6 +445,7 @@ public com.google.protobuf.ByteString getOptionTemplateOrThrow( * * * repeated bytes packets = 3; + * @return The count of packets. */ public int getPacketsCount() { return packets_.size(); @@ -507,12 +458,15 @@ public int getPacketsCount() { * * * repeated bytes packets = 3; + * @param index The index of the element to return. + * @return The packets at the given index. */ public com.google.protobuf.ByteString getPackets(int index) { return packets_.get(index); } private byte memoizedIsInitialized = -1; + @java.lang.Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; @@ -522,32 +476,28 @@ public final boolean isInitialized() { return true; } + @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - for (java.util.Map.Entry entry - : internalGetTemplates().getMap().entrySet()) { - com.google.protobuf.MapEntry - templates = TemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - output.writeMessage(1, templates); - } - for (java.util.Map.Entry entry - : internalGetOptionTemplate().getMap().entrySet()) { - com.google.protobuf.MapEntry - optionTemplate = OptionTemplateDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - output.writeMessage(2, optionTemplate); - } + com.google.protobuf.GeneratedMessageV3 + .serializeIntegerMapTo( + output, + internalGetTemplates(), + TemplatesDefaultEntryHolder.defaultEntry, + 1); + com.google.protobuf.GeneratedMessageV3 + .serializeIntegerMapTo( + output, + internalGetOptionTemplate(), + OptionTemplateDefaultEntryHolder.defaultEntry, + 2); for (int i = 0; i < packets_.size(); i++) { output.writeBytes(3, packets_.get(i)); } - unknownFields.writeTo(output); + getUnknownFields().writeTo(output); } + @java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; @@ -556,22 +506,22 @@ public int getSerializedSize() { for (java.util.Map.Entry entry : internalGetTemplates().getMap().entrySet()) { com.google.protobuf.MapEntry - templates = TemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() + templates__ = TemplatesDefaultEntryHolder.defaultEntry.newBuilderForType() .setKey(entry.getKey()) .setValue(entry.getValue()) .build(); size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, templates); + .computeMessageSize(1, templates__); } for (java.util.Map.Entry entry : internalGetOptionTemplate().getMap().entrySet()) { com.google.protobuf.MapEntry - optionTemplate = OptionTemplateDefaultEntryHolder.defaultEntry.newBuilderForType() + optionTemplate__ = OptionTemplateDefaultEntryHolder.defaultEntry.newBuilderForType() .setKey(entry.getKey()) .setValue(entry.getValue()) .build(); size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, optionTemplate); + .computeMessageSize(2, optionTemplate__); } { int dataSize = 0; @@ -582,12 +532,11 @@ public int getSerializedSize() { size += dataSize; size += 1 * getPacketsList().size(); } - size += unknownFields.getSerializedSize(); + size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; } - private static final long serialVersionUID = 0L; @java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { @@ -598,15 +547,14 @@ public boolean equals(final java.lang.Object obj) { } org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 other = (org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9) obj; - boolean result = true; - result = result && internalGetTemplates().equals( - other.internalGetTemplates()); - result = result && internalGetOptionTemplate().equals( - other.internalGetOptionTemplate()); - result = result && getPacketsList() - .equals(other.getPacketsList()); - result = result && unknownFields.equals(other.unknownFields); - return result; + if (!internalGetTemplates().equals( + other.internalGetTemplates())) return false; + if (!internalGetOptionTemplate().equals( + other.internalGetOptionTemplate())) return false; + if (!getPacketsList() + .equals(other.getPacketsList())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; } @java.lang.Override @@ -615,7 +563,7 @@ public int hashCode() { return memoizedHashCode; } int hash = 41; - hash = (19 * hash) + getDescriptorForType().hashCode(); + hash = (19 * hash) + getDescriptor().hashCode(); if (!internalGetTemplates().getMap().isEmpty()) { hash = (37 * hash) + TEMPLATES_FIELD_NUMBER; hash = (53 * hash) + internalGetTemplates().hashCode(); @@ -628,11 +576,22 @@ public int hashCode() { hash = (37 * hash) + PACKETS_FIELD_NUMBER; hash = (53 * hash) + getPacketsList().hashCode(); } - hash = (29 * hash) + unknownFields.hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; } + public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { @@ -666,11 +625,13 @@ public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parse return com.google.protobuf.GeneratedMessageV3 .parseWithIOException(PARSER, input, extensionRegistry); } + public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessageV3 .parseDelimitedWithIOException(PARSER, input); } + public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) @@ -692,6 +653,7 @@ public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parse .parseWithIOException(PARSER, input, extensionRegistry); } + @java.lang.Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); @@ -699,6 +661,7 @@ public static Builder newBuilder() { public static Builder newBuilder(org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } + @java.lang.Override public Builder toBuilder() { return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); @@ -723,7 +686,7 @@ public static final class Builder extends } @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( int number) { switch (number) { case 1: @@ -736,7 +699,7 @@ protected com.google.protobuf.MapField internalGetMapField( } } @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFieldReflection( int number) { switch (number) { case 1: @@ -748,6 +711,7 @@ protected com.google.protobuf.MapField internalGetMutableMapField( "Invalid map field number: " + number); } } + @java.lang.Override protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog.plugins.netflow.v9.NetFlowV9Journal.internal_static_org_graylog_plugins_netflow_v9_RawNetflowV9_fieldAccessorTable @@ -757,37 +721,36 @@ protected com.google.protobuf.MapField internalGetMutableMapField( // Construct using org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9.newBuilder() private Builder() { - maybeForceBuilderInitialization(); + } private Builder( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } + } + @java.lang.Override public Builder clear() { super.clear(); + bitField0_ = 0; internalGetMutableTemplates().clear(); internalGetMutableOptionTemplate().clear(); - packets_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000004); + packets_ = emptyList(com.google.protobuf.ByteString.class); return this; } + @java.lang.Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return org.graylog.plugins.netflow.v9.NetFlowV9Journal.internal_static_org_graylog_plugins_netflow_v9_RawNetflowV9_descriptor; } + @java.lang.Override public org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 getDefaultInstanceForType() { return org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9.getDefaultInstance(); } + @java.lang.Override public org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 build() { org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 result = buildPartial(); if (!result.isInitialized()) { @@ -796,48 +759,63 @@ public org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 build() { return result; } + @java.lang.Override public org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 buildPartial() { org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 result = new org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9(this); - int from_bitField0_ = bitField0_; - result.templates_ = internalGetTemplates(); - result.templates_.makeImmutable(); - result.optionTemplate_ = internalGetOptionTemplate(); - result.optionTemplate_.makeImmutable(); - if (((bitField0_ & 0x00000004) == 0x00000004)) { - packets_ = java.util.Collections.unmodifiableList(packets_); - bitField0_ = (bitField0_ & ~0x00000004); - } - result.packets_ = packets_; + if (bitField0_ != 0) { buildPartial0(result); } onBuilt(); return result; } + private void buildPartial0(org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.templates_ = internalGetTemplates(); + result.templates_.makeImmutable(); + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.optionTemplate_ = internalGetOptionTemplate(); + result.optionTemplate_.makeImmutable(); + } + if (((from_bitField0_ & 0x00000004) != 0)) { + packets_.makeImmutable(); + result.packets_ = packets_; + } + } + + @java.lang.Override public Builder clone() { - return (Builder) super.clone(); + return super.clone(); } + @java.lang.Override public Builder setField( com.google.protobuf.Descriptors.FieldDescriptor field, - Object value) { - return (Builder) super.setField(field, value); + java.lang.Object value) { + return super.setField(field, value); } + @java.lang.Override public Builder clearField( com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); + return super.clearField(field); } + @java.lang.Override public Builder clearOneof( com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); + return super.clearOneof(oneof); } + @java.lang.Override public Builder setRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, - int index, Object value) { - return (Builder) super.setRepeatedField(field, index, value); + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); } + @java.lang.Override public Builder addRepeatedField( com.google.protobuf.Descriptors.FieldDescriptor field, - Object value) { - return (Builder) super.addRepeatedField(field, value); + java.lang.Object value) { + return super.addRepeatedField(field, value); } + @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9) { return mergeFrom((org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9)other); @@ -851,42 +829,84 @@ public Builder mergeFrom(org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetf if (other == org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9.getDefaultInstance()) return this; internalGetMutableTemplates().mergeFrom( other.internalGetTemplates()); + bitField0_ |= 0x00000001; internalGetMutableOptionTemplate().mergeFrom( other.internalGetOptionTemplate()); + bitField0_ |= 0x00000002; if (!other.packets_.isEmpty()) { if (packets_.isEmpty()) { packets_ = other.packets_; - bitField0_ = (bitField0_ & ~0x00000004); + packets_.makeImmutable(); + bitField0_ |= 0x00000004; } else { ensurePacketsIsMutable(); packets_.addAll(other.packets_); } onChanged(); } - this.mergeUnknownFields(other.unknownFields); + this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; } + @java.lang.Override public final boolean isInitialized() { return true; } + @java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 parsedMessage = null; + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + com.google.protobuf.MapEntry + templates__ = input.readMessage( + TemplatesDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); + internalGetMutableTemplates().getMutableMap().put( + templates__.getKey(), templates__.getValue()); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: { + com.google.protobuf.MapEntry + optionTemplate__ = input.readMessage( + OptionTemplateDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); + internalGetMutableOptionTemplate().getMutableMap().put( + optionTemplate__.getKey(), optionTemplate__.getValue()); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: { + com.google.protobuf.ByteString v = input.readBytes(); + ensurePacketsIsMutable(); + packets_.add(v); + break; + } // case 26 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } + onChanged(); + } // finally return this; } private int bitField0_; @@ -894,7 +914,7 @@ public Builder mergeFrom( private com.google.protobuf.MapField< java.lang.Integer, com.google.protobuf.ByteString> templates_; private com.google.protobuf.MapField - internalGetTemplates() { + internalGetTemplates() { if (templates_ == null) { return com.google.protobuf.MapField.emptyMapField( TemplatesDefaultEntryHolder.defaultEntry); @@ -902,8 +922,7 @@ public Builder mergeFrom( return templates_; } private com.google.protobuf.MapField - internalGetMutableTemplates() { - onChanged(); + internalGetMutableTemplates() { if (templates_ == null) { templates_ = com.google.protobuf.MapField.newMapField( TemplatesDefaultEntryHolder.defaultEntry); @@ -911,9 +930,10 @@ public Builder mergeFrom( if (!templates_.isMutable()) { templates_ = templates_.copy(); } + bitField0_ |= 0x00000001; + onChanged(); return templates_; } - public int getTemplatesCount() { return internalGetTemplates().getMap().size(); } @@ -924,15 +944,16 @@ public int getTemplatesCount() { * * map<uint32, bytes> templates = 1; */ - + @java.lang.Override public boolean containsTemplates( int key) { - + return internalGetTemplates().getMap().containsKey(key); } /** * Use {@link #getTemplatesMap()} instead. */ + @java.lang.Override @java.lang.Deprecated public java.util.Map getTemplates() { return getTemplatesMap(); @@ -944,7 +965,7 @@ public java.util.Map getTempl * * map<uint32, bytes> templates = 1; */ - + @java.lang.Override public java.util.Map getTemplatesMap() { return internalGetTemplates().getMap(); } @@ -955,11 +976,13 @@ public java.util.Map getTempl * * map<uint32, bytes> templates = 1; */ - - public com.google.protobuf.ByteString getTemplatesOrDefault( + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getTemplatesOrDefault( int key, - com.google.protobuf.ByteString defaultValue) { - + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + java.util.Map map = internalGetTemplates().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; @@ -971,10 +994,10 @@ public com.google.protobuf.ByteString getTemplatesOrDefault( * * map<uint32, bytes> templates = 1; */ - + @java.lang.Override public com.google.protobuf.ByteString getTemplatesOrThrow( int key) { - + java.util.Map map = internalGetTemplates().getMap(); if (!map.containsKey(key)) { @@ -982,9 +1005,10 @@ public com.google.protobuf.ByteString getTemplatesOrThrow( } return map.get(key); } - public Builder clearTemplates() { - getMutableTemplates().clear(); + bitField0_ = (bitField0_ & ~0x00000001); + internalGetMutableTemplates().getMutableMap() + .clear(); return this; } /** @@ -994,11 +1018,11 @@ public Builder clearTemplates() { * * map<uint32, bytes> templates = 1; */ - public Builder removeTemplates( int key) { - - getMutableTemplates().remove(key); + + internalGetMutableTemplates().getMutableMap() + .remove(key); return this; } /** @@ -1006,7 +1030,8 @@ public Builder removeTemplates( */ @java.lang.Deprecated public java.util.Map - getMutableTemplates() { + getMutableTemplates() { + bitField0_ |= 0x00000001; return internalGetMutableTemplates().getMutableMap(); } /** @@ -1019,9 +1044,11 @@ public Builder removeTemplates( public Builder putTemplates( int key, com.google.protobuf.ByteString value) { - - if (value == null) { throw new java.lang.NullPointerException(); } - getMutableTemplates().put(key, value); + + if (value == null) { throw new NullPointerException("map value"); } + internalGetMutableTemplates().getMutableMap() + .put(key, value); + bitField0_ |= 0x00000001; return this; } /** @@ -1031,17 +1058,18 @@ public Builder putTemplates( * * map<uint32, bytes> templates = 1; */ - public Builder putAllTemplates( java.util.Map values) { - getMutableTemplates().putAll(values); + internalGetMutableTemplates().getMutableMap() + .putAll(values); + bitField0_ |= 0x00000001; return this; } private com.google.protobuf.MapField< java.lang.Integer, com.google.protobuf.ByteString> optionTemplate_; private com.google.protobuf.MapField - internalGetOptionTemplate() { + internalGetOptionTemplate() { if (optionTemplate_ == null) { return com.google.protobuf.MapField.emptyMapField( OptionTemplateDefaultEntryHolder.defaultEntry); @@ -1049,8 +1077,7 @@ public Builder putAllTemplates( return optionTemplate_; } private com.google.protobuf.MapField - internalGetMutableOptionTemplate() { - onChanged();; + internalGetMutableOptionTemplate() { if (optionTemplate_ == null) { optionTemplate_ = com.google.protobuf.MapField.newMapField( OptionTemplateDefaultEntryHolder.defaultEntry); @@ -1058,9 +1085,10 @@ public Builder putAllTemplates( if (!optionTemplate_.isMutable()) { optionTemplate_ = optionTemplate_.copy(); } + bitField0_ |= 0x00000002; + onChanged(); return optionTemplate_; } - public int getOptionTemplateCount() { return internalGetOptionTemplate().getMap().size(); } @@ -1071,15 +1099,16 @@ public int getOptionTemplateCount() { * * map<uint32, bytes> optionTemplate = 2; */ - + @java.lang.Override public boolean containsOptionTemplate( int key) { - + return internalGetOptionTemplate().getMap().containsKey(key); } /** * Use {@link #getOptionTemplateMap()} instead. */ + @java.lang.Override @java.lang.Deprecated public java.util.Map getOptionTemplate() { return getOptionTemplateMap(); @@ -1091,7 +1120,7 @@ public java.util.Map getOptio * * map<uint32, bytes> optionTemplate = 2; */ - + @java.lang.Override public java.util.Map getOptionTemplateMap() { return internalGetOptionTemplate().getMap(); } @@ -1102,11 +1131,13 @@ public java.util.Map getOptio * * map<uint32, bytes> optionTemplate = 2; */ - - public com.google.protobuf.ByteString getOptionTemplateOrDefault( + @java.lang.Override + public /* nullable */ +com.google.protobuf.ByteString getOptionTemplateOrDefault( int key, - com.google.protobuf.ByteString defaultValue) { - + /* nullable */ +com.google.protobuf.ByteString defaultValue) { + java.util.Map map = internalGetOptionTemplate().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; @@ -1118,10 +1149,10 @@ public com.google.protobuf.ByteString getOptionTemplateOrDefault( * * map<uint32, bytes> optionTemplate = 2; */ - + @java.lang.Override public com.google.protobuf.ByteString getOptionTemplateOrThrow( int key) { - + java.util.Map map = internalGetOptionTemplate().getMap(); if (!map.containsKey(key)) { @@ -1129,9 +1160,10 @@ public com.google.protobuf.ByteString getOptionTemplateOrThrow( } return map.get(key); } - public Builder clearOptionTemplate() { - getMutableOptionTemplate().clear(); + bitField0_ = (bitField0_ & ~0x00000002); + internalGetMutableOptionTemplate().getMutableMap() + .clear(); return this; } /** @@ -1141,11 +1173,11 @@ public Builder clearOptionTemplate() { * * map<uint32, bytes> optionTemplate = 2; */ - public Builder removeOptionTemplate( int key) { - - getMutableOptionTemplate().remove(key); + + internalGetMutableOptionTemplate().getMutableMap() + .remove(key); return this; } /** @@ -1153,7 +1185,8 @@ public Builder removeOptionTemplate( */ @java.lang.Deprecated public java.util.Map - getMutableOptionTemplate() { + getMutableOptionTemplate() { + bitField0_ |= 0x00000002; return internalGetMutableOptionTemplate().getMutableMap(); } /** @@ -1166,9 +1199,11 @@ public Builder removeOptionTemplate( public Builder putOptionTemplate( int key, com.google.protobuf.ByteString value) { - - if (value == null) { throw new java.lang.NullPointerException(); } - getMutableOptionTemplate().put(key, value); + + if (value == null) { throw new NullPointerException("map value"); } + internalGetMutableOptionTemplate().getMutableMap() + .put(key, value); + bitField0_ |= 0x00000002; return this; } /** @@ -1178,19 +1213,20 @@ public Builder putOptionTemplate( * * map<uint32, bytes> optionTemplate = 2; */ - public Builder putAllOptionTemplate( java.util.Map values) { - getMutableOptionTemplate().putAll(values); + internalGetMutableOptionTemplate().getMutableMap() + .putAll(values); + bitField0_ |= 0x00000002; return this; } - private java.util.List packets_ = java.util.Collections.emptyList(); + private com.google.protobuf.Internal.ProtobufList packets_ = emptyList(com.google.protobuf.ByteString.class); private void ensurePacketsIsMutable() { - if (!((bitField0_ & 0x00000004) == 0x00000004)) { - packets_ = new java.util.ArrayList(packets_); - bitField0_ |= 0x00000004; - } + if (!packets_.isModifiable()) { + packets_ = makeMutableCopy(packets_); + } + bitField0_ |= 0x00000004; } /** *
    @@ -1200,10 +1236,12 @@ private void ensurePacketsIsMutable() {
            * 
    * * repeated bytes packets = 3; + * @return A list containing the packets. */ public java.util.List getPacketsList() { - return java.util.Collections.unmodifiableList(packets_); + packets_.makeImmutable(); + return packets_; } /** *
    @@ -1213,6 +1251,7 @@ private void ensurePacketsIsMutable() {
            * 
    * * repeated bytes packets = 3; + * @return The count of packets. */ public int getPacketsCount() { return packets_.size(); @@ -1225,6 +1264,8 @@ public int getPacketsCount() { * * * repeated bytes packets = 3; + * @param index The index of the element to return. + * @return The packets at the given index. */ public com.google.protobuf.ByteString getPackets(int index) { return packets_.get(index); @@ -1237,14 +1278,16 @@ public com.google.protobuf.ByteString getPackets(int index) { * * * repeated bytes packets = 3; + * @param index The index to set the value at. + * @param value The packets to set. + * @return This builder for chaining. */ public Builder setPackets( int index, com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - ensurePacketsIsMutable(); + if (value == null) { throw new NullPointerException(); } + ensurePacketsIsMutable(); packets_.set(index, value); + bitField0_ |= 0x00000004; onChanged(); return this; } @@ -1256,13 +1299,14 @@ public Builder setPackets( * * * repeated bytes packets = 3; + * @param value The packets to add. + * @return This builder for chaining. */ public Builder addPackets(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - ensurePacketsIsMutable(); + if (value == null) { throw new NullPointerException(); } + ensurePacketsIsMutable(); packets_.add(value); + bitField0_ |= 0x00000004; onChanged(); return this; } @@ -1274,12 +1318,15 @@ public Builder addPackets(com.google.protobuf.ByteString value) { * * * repeated bytes packets = 3; + * @param values The packets to add. + * @return This builder for chaining. */ public Builder addAllPackets( java.lang.Iterable values) { ensurePacketsIsMutable(); com.google.protobuf.AbstractMessageLite.Builder.addAll( values, packets_); + bitField0_ |= 0x00000004; onChanged(); return this; } @@ -1291,18 +1338,21 @@ public Builder addAllPackets( * * * repeated bytes packets = 3; + * @return This builder for chaining. */ public Builder clearPackets() { - packets_ = java.util.Collections.emptyList(); + packets_ = emptyList(com.google.protobuf.ByteString.class); bitField0_ = (bitField0_ & ~0x00000004); onChanged(); return this; } + @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); } + @java.lang.Override public final Builder mergeUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return super.mergeUnknownFields(unknownFields); @@ -1324,11 +1374,23 @@ public static org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 getDe @java.lang.Deprecated public static final com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override public RawNetflowV9 parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { - return new RawNetflowV9(input, extensionRegistry); + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); } }; @@ -1341,6 +1403,7 @@ public com.google.protobuf.Parser getParserForType() { return PARSER; } + @java.lang.Override public org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 getDefaultInstanceForType() { return DEFAULT_INSTANCE; } @@ -1380,21 +1443,13 @@ public org.graylog.plugins.netflow.v9.NetFlowV9Journal.RawNetflowV9 getDefaultIn "ionTemplateEntry\022\017\n\007packets\030\003 \003(\014\0320\n\016Tem" + "platesEntry\022\013\n\003key\030\001 \001(\r\022\r\n\005value\030\002 \001(\014:" + "\0028\001\0325\n\023OptionTemplateEntry\022\013\n\003key\030\001 \001(\r\022" + - "\r\n\005value\030\002 \001(\014:\0028\001B2\n\036org.graylog.plugin", + "\r\n\005value\030\002 \001(\014:\0028\001B2\n\036org.graylog.plugin" + "s.netflow.v9B\020NetFlowV9Journal" }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor + descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); + }); internal_static_org_graylog_plugins_netflow_v9_RawNetflowV9_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_org_graylog_plugins_netflow_v9_RawNetflowV9_fieldAccessorTable = new diff --git a/graylog2-server/src/main/java/org/graylog2/plugin/journal/JournalMessages.java b/graylog2-server/src/main/java/org/graylog2/plugin/journal/JournalMessages.java index 364530b432c8..a334b410d228 100644 --- a/graylog2-server/src/main/java/org/graylog2/plugin/journal/JournalMessages.java +++ b/graylog2-server/src/main/java/org/graylog2/plugin/journal/JournalMessages.java @@ -16,162 +16,172 @@ */ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: resources/org/graylog2/plugin/journal/raw_message.proto -// to regenerate: -// install protobuf compiler (this was generated with 2.5.0) -// cd graylog2-server/src/main && protoc --java_out=java resources/org/graylog2/plugin/journal/raw_message.proto +// Protobuf Java Version: 3.25.6 package org.graylog2.plugin.journal; public final class JournalMessages { private JournalMessages() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + public static void registerAllExtensions( com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); } - public interface JournalMessageOrBuilder - extends com.google.protobuf.MessageOrBuilder { + public interface JournalMessageOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.graylog2.plugin.journal.JournalMessage) + com.google.protobuf.MessageOrBuilder { - // optional uint32 version = 1; /** - * optional uint32 version = 1; - * *
          * the version of the message format (used for simplifying code when deserializing messages)
          * 
    + * + * optional uint32 version = 1; + * @return Whether the version field is set. */ boolean hasVersion(); /** - * optional uint32 version = 1; - * *
          * the version of the message format (used for simplifying code when deserializing messages)
          * 
    + * + * optional uint32 version = 1; + * @return The version. */ int getVersion(); - // optional fixed64 uuid_time = 2; /** - * optional fixed64 uuid_time = 2; - * *
          * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
          * 
    + * + * optional fixed64 uuid_time = 2; + * @return Whether the uuidTime field is set. */ boolean hasUuidTime(); /** - * optional fixed64 uuid_time = 2; - * *
          * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
          * 
    + * + * optional fixed64 uuid_time = 2; + * @return The uuidTime. */ long getUuidTime(); - // optional fixed64 uuid_clockseq = 3; /** * optional fixed64 uuid_clockseq = 3; + * @return Whether the uuidClockseq field is set. */ boolean hasUuidClockseq(); /** * optional fixed64 uuid_clockseq = 3; + * @return The uuidClockseq. */ long getUuidClockseq(); - // optional fixed64 timestamp = 4; /** - * optional fixed64 timestamp = 4; - * *
          * milliseconds since Java epoch (1970/01/01 00:00:00.000)
          * 
    + * + * optional fixed64 timestamp = 4; + * @return Whether the timestamp field is set. */ boolean hasTimestamp(); /** - * optional fixed64 timestamp = 4; - * *
          * milliseconds since Java epoch (1970/01/01 00:00:00.000)
          * 
    + * + * optional fixed64 timestamp = 4; + * @return The timestamp. */ long getTimestamp(); - // optional .org.graylog2.plugin.journal.CodecInfo codec = 5; /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
          * which format the payload is supposed to have
          * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; + * @return Whether the codec field is set. */ boolean hasCodec(); /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
          * which format the payload is supposed to have
          * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; + * @return The codec. */ org.graylog2.plugin.journal.JournalMessages.CodecInfo getCodec(); /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
          * which format the payload is supposed to have
          * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder getCodecOrBuilder(); - // repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ - java.util.List + java.util.List getSourceNodesList(); /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ org.graylog2.plugin.journal.JournalMessages.SourceNode getSourceNodes(int index); /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ int getSourceNodesCount(); /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ - java.util.List + java.util.List getSourceNodesOrBuilderList(); /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder getSourceNodesOrBuilder( int index); - // optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; + * @return Whether the remote field is set. */ boolean hasRemote(); /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; + * @return The remote. */ org.graylog2.plugin.journal.JournalMessages.RemoteAddress getRemote(); /** @@ -179,23 +189,25 @@ org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder getSourceNodesOr */ org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder getRemoteOrBuilder(); - // optional bytes payload = 8; /** * optional bytes payload = 8; + * @return Whether the payload field is set. */ boolean hasPayload(); /** * optional bytes payload = 8; + * @return The payload. */ com.google.protobuf.ByteString getPayload(); - // optional uint32 sequence_nr = 9; /** * optional uint32 sequence_nr = 9; + * @return Whether the sequenceNr field is set. */ boolean hasSequenceNr(); /** * optional uint32 sequence_nr = 9; + * @return The sequenceNr. */ int getSequenceNr(); } @@ -203,499 +215,512 @@ org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder getSourceNodesOr * Protobuf type {@code org.graylog2.plugin.journal.JournalMessage} */ public static final class JournalMessage extends - com.google.protobuf.GeneratedMessage - implements JournalMessageOrBuilder { + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.graylog2.plugin.journal.JournalMessage) + JournalMessageOrBuilder { + private static final long serialVersionUID = 0L; // Use JournalMessage.newBuilder() to construct. - private JournalMessage(com.google.protobuf.GeneratedMessage.Builder builder) { + private JournalMessage(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private JournalMessage(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final JournalMessage defaultInstance; - public static JournalMessage getDefaultInstance() { - return defaultInstance; } - - public JournalMessage getDefaultInstanceForType() { - return defaultInstance; + private JournalMessage() { + sourceNodes_ = java.util.Collections.emptyList(); + payload_ = com.google.protobuf.ByteString.EMPTY; } - private final com.google.protobuf.UnknownFieldSet unknownFields; @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private JournalMessage( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - bitField0_ |= 0x00000001; - version_ = input.readUInt32(); - break; - } - case 17: { - bitField0_ |= 0x00000002; - uuidTime_ = input.readFixed64(); - break; - } - case 25: { - bitField0_ |= 0x00000004; - uuidClockseq_ = input.readFixed64(); - break; - } - case 33: { - bitField0_ |= 0x00000008; - timestamp_ = input.readFixed64(); - break; - } - case 42: { - org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder subBuilder = null; - if (((bitField0_ & 0x00000010) == 0x00000010)) { - subBuilder = codec_.toBuilder(); - } - codec_ = input.readMessage(org.graylog2.plugin.journal.JournalMessages.CodecInfo.PARSER, extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(codec_); - codec_ = subBuilder.buildPartial(); - } - bitField0_ |= 0x00000010; - break; - } - case 50: { - if (!((mutable_bitField0_ & 0x00000020) == 0x00000020)) { - sourceNodes_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000020; - } - sourceNodes_.add(input.readMessage(org.graylog2.plugin.journal.JournalMessages.SourceNode.PARSER, extensionRegistry)); - break; - } - case 58: { - org.graylog2.plugin.journal.JournalMessages.RemoteAddress.Builder subBuilder = null; - if (((bitField0_ & 0x00000020) == 0x00000020)) { - subBuilder = remote_.toBuilder(); - } - remote_ = input.readMessage(org.graylog2.plugin.journal.JournalMessages.RemoteAddress.PARSER, extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(remote_); - remote_ = subBuilder.buildPartial(); - } - bitField0_ |= 0x00000020; - break; - } - case 66: { - bitField0_ |= 0x00000040; - payload_ = input.readBytes(); - break; - } - case 72: { - bitField0_ |= 0x00000080; - sequenceNr_ = input.readUInt32(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000020) == 0x00000020)) { - sourceNodes_ = java.util.Collections.unmodifiableList(sourceNodes_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new JournalMessage(); } + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_JournalMessage_fieldAccessorTable .ensureFieldAccessorsInitialized( org.graylog2.plugin.journal.JournalMessages.JournalMessage.class, org.graylog2.plugin.journal.JournalMessages.JournalMessage.Builder.class); } - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public JournalMessage parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new JournalMessage(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - private int bitField0_; - // optional uint32 version = 1; public static final int VERSION_FIELD_NUMBER = 1; - private int version_; + private int version_ = 0; /** - * optional uint32 version = 1; - * *
          * the version of the message format (used for simplifying code when deserializing messages)
          * 
    + * + * optional uint32 version = 1; + * @return Whether the version field is set. */ + @java.lang.Override public boolean hasVersion() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** - * optional uint32 version = 1; - * *
          * the version of the message format (used for simplifying code when deserializing messages)
          * 
    + * + * optional uint32 version = 1; + * @return The version. */ + @java.lang.Override public int getVersion() { return version_; } - // optional fixed64 uuid_time = 2; public static final int UUID_TIME_FIELD_NUMBER = 2; - private long uuidTime_; + private long uuidTime_ = 0L; /** - * optional fixed64 uuid_time = 2; - * *
          * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
          * 
    + * + * optional fixed64 uuid_time = 2; + * @return Whether the uuidTime field is set. */ + @java.lang.Override public boolean hasUuidTime() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** - * optional fixed64 uuid_time = 2; - * *
          * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
          * 
    + * + * optional fixed64 uuid_time = 2; + * @return The uuidTime. */ + @java.lang.Override public long getUuidTime() { return uuidTime_; } - // optional fixed64 uuid_clockseq = 3; public static final int UUID_CLOCKSEQ_FIELD_NUMBER = 3; - private long uuidClockseq_; + private long uuidClockseq_ = 0L; /** * optional fixed64 uuid_clockseq = 3; + * @return Whether the uuidClockseq field is set. */ + @java.lang.Override public boolean hasUuidClockseq() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000004) != 0); } /** * optional fixed64 uuid_clockseq = 3; + * @return The uuidClockseq. */ + @java.lang.Override public long getUuidClockseq() { return uuidClockseq_; } - // optional fixed64 timestamp = 4; public static final int TIMESTAMP_FIELD_NUMBER = 4; - private long timestamp_; + private long timestamp_ = 0L; /** - * optional fixed64 timestamp = 4; - * *
          * milliseconds since Java epoch (1970/01/01 00:00:00.000)
          * 
    + * + * optional fixed64 timestamp = 4; + * @return Whether the timestamp field is set. */ + @java.lang.Override public boolean hasTimestamp() { - return ((bitField0_ & 0x00000008) == 0x00000008); + return ((bitField0_ & 0x00000008) != 0); } /** - * optional fixed64 timestamp = 4; - * *
          * milliseconds since Java epoch (1970/01/01 00:00:00.000)
          * 
    + * + * optional fixed64 timestamp = 4; + * @return The timestamp. */ + @java.lang.Override public long getTimestamp() { return timestamp_; } - // optional .org.graylog2.plugin.journal.CodecInfo codec = 5; public static final int CODEC_FIELD_NUMBER = 5; private org.graylog2.plugin.journal.JournalMessages.CodecInfo codec_; /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
          * which format the payload is supposed to have
          * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; + * @return Whether the codec field is set. */ + @java.lang.Override public boolean hasCodec() { - return ((bitField0_ & 0x00000010) == 0x00000010); + return ((bitField0_ & 0x00000010) != 0); } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
          * which format the payload is supposed to have
          * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; + * @return The codec. */ + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.CodecInfo getCodec() { - return codec_; + return codec_ == null ? org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance() : codec_; } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
          * which format the payload is supposed to have
          * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder getCodecOrBuilder() { - return codec_; + return codec_ == null ? org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance() : codec_; } - // repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; public static final int SOURCE_NODES_FIELD_NUMBER = 6; + @SuppressWarnings("serial") private java.util.List sourceNodes_; /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ + @java.lang.Override public java.util.List getSourceNodesList() { return sourceNodes_; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ - public java.util.List + @java.lang.Override + public java.util.List getSourceNodesOrBuilderList() { return sourceNodes_; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ + @java.lang.Override public int getSourceNodesCount() { return sourceNodes_.size(); } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.SourceNode getSourceNodes(int index) { return sourceNodes_.get(index); } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
          * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
          * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder getSourceNodesOrBuilder( int index) { return sourceNodes_.get(index); } - // optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; public static final int REMOTE_FIELD_NUMBER = 7; private org.graylog2.plugin.journal.JournalMessages.RemoteAddress remote_; /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; + * @return Whether the remote field is set. */ + @java.lang.Override public boolean hasRemote() { - return ((bitField0_ & 0x00000020) == 0x00000020); + return ((bitField0_ & 0x00000020) != 0); } /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; + * @return The remote. */ + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.RemoteAddress getRemote() { - return remote_; + return remote_ == null ? org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance() : remote_; } /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; */ + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder getRemoteOrBuilder() { - return remote_; + return remote_ == null ? org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance() : remote_; } - // optional bytes payload = 8; public static final int PAYLOAD_FIELD_NUMBER = 8; - private com.google.protobuf.ByteString payload_; + private com.google.protobuf.ByteString payload_ = com.google.protobuf.ByteString.EMPTY; /** * optional bytes payload = 8; + * @return Whether the payload field is set. */ + @java.lang.Override public boolean hasPayload() { - return ((bitField0_ & 0x00000040) == 0x00000040); + return ((bitField0_ & 0x00000040) != 0); } /** * optional bytes payload = 8; + * @return The payload. */ + @java.lang.Override public com.google.protobuf.ByteString getPayload() { return payload_; } - // optional uint32 sequence_nr = 9; public static final int SEQUENCE_NR_FIELD_NUMBER = 9; - private int sequenceNr_; + private int sequenceNr_ = 0; /** * optional uint32 sequence_nr = 9; + * @return Whether the sequenceNr field is set. */ + @java.lang.Override public boolean hasSequenceNr() { - return ((bitField0_ & 0x00000080) == 0x00000080); + return ((bitField0_ & 0x00000080) != 0); } /** * optional uint32 sequence_nr = 9; + * @return The sequenceNr. */ + @java.lang.Override public int getSequenceNr() { return sequenceNr_; } - private void initFields() { - version_ = 0; - uuidTime_ = 0L; - uuidClockseq_ = 0L; - timestamp_ = 0L; - codec_ = org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance(); - sourceNodes_ = java.util.Collections.emptyList(); - remote_ = org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance(); - payload_ = com.google.protobuf.ByteString.EMPTY; - sequenceNr_ = 0; - } private byte memoizedIsInitialized = -1; + @java.lang.Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; memoizedIsInitialized = 1; return true; } + @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { + if (((bitField0_ & 0x00000001) != 0)) { output.writeUInt32(1, version_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { + if (((bitField0_ & 0x00000002) != 0)) { output.writeFixed64(2, uuidTime_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { + if (((bitField0_ & 0x00000004) != 0)) { output.writeFixed64(3, uuidClockseq_); } - if (((bitField0_ & 0x00000008) == 0x00000008)) { + if (((bitField0_ & 0x00000008) != 0)) { output.writeFixed64(4, timestamp_); } - if (((bitField0_ & 0x00000010) == 0x00000010)) { - output.writeMessage(5, codec_); + if (((bitField0_ & 0x00000010) != 0)) { + output.writeMessage(5, getCodec()); } for (int i = 0; i < sourceNodes_.size(); i++) { output.writeMessage(6, sourceNodes_.get(i)); } - if (((bitField0_ & 0x00000020) == 0x00000020)) { - output.writeMessage(7, remote_); + if (((bitField0_ & 0x00000020) != 0)) { + output.writeMessage(7, getRemote()); } - if (((bitField0_ & 0x00000040) == 0x00000040)) { + if (((bitField0_ & 0x00000040) != 0)) { output.writeBytes(8, payload_); } - if (((bitField0_ & 0x00000080) == 0x00000080)) { + if (((bitField0_ & 0x00000080) != 0)) { output.writeUInt32(9, sequenceNr_); } getUnknownFields().writeTo(output); } - private int memoizedSerializedSize = -1; + @java.lang.Override public int getSerializedSize() { - int size = memoizedSerializedSize; + int size = memoizedSize; if (size != -1) return size; size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { + if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(1, version_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { + if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream .computeFixed64Size(2, uuidTime_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { + if (((bitField0_ & 0x00000004) != 0)) { size += com.google.protobuf.CodedOutputStream .computeFixed64Size(3, uuidClockseq_); } - if (((bitField0_ & 0x00000008) == 0x00000008)) { + if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream .computeFixed64Size(4, timestamp_); } - if (((bitField0_ & 0x00000010) == 0x00000010)) { + if (((bitField0_ & 0x00000010) != 0)) { size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, codec_); + .computeMessageSize(5, getCodec()); } for (int i = 0; i < sourceNodes_.size(); i++) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(6, sourceNodes_.get(i)); } - if (((bitField0_ & 0x00000020) == 0x00000020)) { + if (((bitField0_ & 0x00000020) != 0)) { size += com.google.protobuf.CodedOutputStream - .computeMessageSize(7, remote_); + .computeMessageSize(7, getRemote()); } - if (((bitField0_ & 0x00000040) == 0x00000040)) { + if (((bitField0_ & 0x00000040) != 0)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(8, payload_); } - if (((bitField0_ & 0x00000080) == 0x00000080)) { + if (((bitField0_ & 0x00000080) != 0)) { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(9, sequenceNr_); } size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; + memoizedSize = size; return size; } - private static final long serialVersionUID = 0L; @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.graylog2.plugin.journal.JournalMessages.JournalMessage)) { + return super.equals(obj); + } + org.graylog2.plugin.journal.JournalMessages.JournalMessage other = (org.graylog2.plugin.journal.JournalMessages.JournalMessage) obj; + + if (hasVersion() != other.hasVersion()) return false; + if (hasVersion()) { + if (getVersion() + != other.getVersion()) return false; + } + if (hasUuidTime() != other.hasUuidTime()) return false; + if (hasUuidTime()) { + if (getUuidTime() + != other.getUuidTime()) return false; + } + if (hasUuidClockseq() != other.hasUuidClockseq()) return false; + if (hasUuidClockseq()) { + if (getUuidClockseq() + != other.getUuidClockseq()) return false; + } + if (hasTimestamp() != other.hasTimestamp()) return false; + if (hasTimestamp()) { + if (getTimestamp() + != other.getTimestamp()) return false; + } + if (hasCodec() != other.hasCodec()) return false; + if (hasCodec()) { + if (!getCodec() + .equals(other.getCodec())) return false; + } + if (!getSourceNodesList() + .equals(other.getSourceNodesList())) return false; + if (hasRemote() != other.hasRemote()) return false; + if (hasRemote()) { + if (!getRemote() + .equals(other.getRemote())) return false; + } + if (hasPayload() != other.hasPayload()) return false; + if (hasPayload()) { + if (!getPayload() + .equals(other.getPayload())) return false; + } + if (hasSequenceNr() != other.hasSequenceNr()) return false; + if (hasSequenceNr()) { + if (getSequenceNr() + != other.getSequenceNr()) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasVersion()) { + hash = (37 * hash) + VERSION_FIELD_NUMBER; + hash = (53 * hash) + getVersion(); + } + if (hasUuidTime()) { + hash = (37 * hash) + UUID_TIME_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getUuidTime()); + } + if (hasUuidClockseq()) { + hash = (37 * hash) + UUID_CLOCKSEQ_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getUuidClockseq()); + } + if (hasTimestamp()) { + hash = (37 * hash) + TIMESTAMP_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getTimestamp()); + } + if (hasCodec()) { + hash = (37 * hash) + CODEC_FIELD_NUMBER; + hash = (53 * hash) + getCodec().hashCode(); + } + if (getSourceNodesCount() > 0) { + hash = (37 * hash) + SOURCE_NODES_FIELD_NUMBER; + hash = (53 * hash) + getSourceNodesList().hashCode(); + } + if (hasRemote()) { + hash = (37 * hash) + REMOTE_FIELD_NUMBER; + hash = (53 * hash) + getRemote().hashCode(); + } + if (hasPayload()) { + hash = (37 * hash) + PAYLOAD_FIELD_NUMBER; + hash = (53 * hash) + getPayload().hashCode(); + } + if (hasSequenceNr()) { + hash = (37 * hash) + SEQUENCE_NR_FIELD_NUMBER; + hash = (53 * hash) + getSequenceNr(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; } + public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { @@ -719,46 +744,61 @@ public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFr } public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } + public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); } + public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.JournalMessage parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } - public static Builder newBuilder() { return Builder.create(); } + @java.lang.Override public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } public static Builder newBuilder(org.graylog2.plugin.journal.JournalMessages.JournalMessage prototype) { - return newBuilder().mergeFrom(prototype); + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); } - public Builder toBuilder() { return newBuilder(this); } @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -766,14 +806,16 @@ protected Builder newBuilderForType( * Protobuf type {@code org.graylog2.plugin.journal.JournalMessage} */ public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements org.graylog2.plugin.journal.JournalMessages.JournalMessageOrBuilder { + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.graylog2.plugin.journal.JournalMessage) + org.graylog2.plugin.journal.JournalMessages.JournalMessageOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_JournalMessage_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -786,69 +828,60 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { getCodecFieldBuilder(); getSourceNodesFieldBuilder(); getRemoteFieldBuilder(); } } - private static Builder create() { - return new Builder(); - } - + @java.lang.Override public Builder clear() { super.clear(); + bitField0_ = 0; version_ = 0; - bitField0_ = (bitField0_ & ~0x00000001); uuidTime_ = 0L; - bitField0_ = (bitField0_ & ~0x00000002); uuidClockseq_ = 0L; - bitField0_ = (bitField0_ & ~0x00000004); timestamp_ = 0L; - bitField0_ = (bitField0_ & ~0x00000008); - if (codecBuilder_ == null) { - codec_ = org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance(); - } else { - codecBuilder_.clear(); + codec_ = null; + if (codecBuilder_ != null) { + codecBuilder_.dispose(); + codecBuilder_ = null; } - bitField0_ = (bitField0_ & ~0x00000010); if (sourceNodesBuilder_ == null) { sourceNodes_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000020); } else { + sourceNodes_ = null; sourceNodesBuilder_.clear(); } - if (remoteBuilder_ == null) { - remote_ = org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance(); - } else { - remoteBuilder_.clear(); + bitField0_ = (bitField0_ & ~0x00000020); + remote_ = null; + if (remoteBuilder_ != null) { + remoteBuilder_.dispose(); + remoteBuilder_ = null; } - bitField0_ = (bitField0_ & ~0x00000040); payload_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000080); sequenceNr_ = 0; - bitField0_ = (bitField0_ & ~0x00000100); return this; } - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - + @java.lang.Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor; } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.JournalMessage getDefaultInstanceForType() { return org.graylog2.plugin.journal.JournalMessages.JournalMessage.getDefaultInstance(); } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.JournalMessage build() { org.graylog2.plugin.journal.JournalMessages.JournalMessage result = buildPartial(); if (!result.isInitialized()) { @@ -857,64 +890,102 @@ public org.graylog2.plugin.journal.JournalMessages.JournalMessage build() { return result; } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.JournalMessage buildPartial() { org.graylog2.plugin.journal.JournalMessages.JournalMessage result = new org.graylog2.plugin.journal.JournalMessages.JournalMessage(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields(org.graylog2.plugin.journal.JournalMessages.JournalMessage result) { + if (sourceNodesBuilder_ == null) { + if (((bitField0_ & 0x00000020) != 0)) { + sourceNodes_ = java.util.Collections.unmodifiableList(sourceNodes_); + bitField0_ = (bitField0_ & ~0x00000020); + } + result.sourceNodes_ = sourceNodes_; + } else { + result.sourceNodes_ = sourceNodesBuilder_.build(); + } + } + + private void buildPartial0(org.graylog2.plugin.journal.JournalMessages.JournalMessage result) { int from_bitField0_ = bitField0_; int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + if (((from_bitField0_ & 0x00000001) != 0)) { + result.version_ = version_; to_bitField0_ |= 0x00000001; } - result.version_ = version_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + if (((from_bitField0_ & 0x00000002) != 0)) { + result.uuidTime_ = uuidTime_; to_bitField0_ |= 0x00000002; } - result.uuidTime_ = uuidTime_; - if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + if (((from_bitField0_ & 0x00000004) != 0)) { + result.uuidClockseq_ = uuidClockseq_; to_bitField0_ |= 0x00000004; } - result.uuidClockseq_ = uuidClockseq_; - if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + if (((from_bitField0_ & 0x00000008) != 0)) { + result.timestamp_ = timestamp_; to_bitField0_ |= 0x00000008; } - result.timestamp_ = timestamp_; - if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + if (((from_bitField0_ & 0x00000010) != 0)) { + result.codec_ = codecBuilder_ == null + ? codec_ + : codecBuilder_.build(); to_bitField0_ |= 0x00000010; } - if (codecBuilder_ == null) { - result.codec_ = codec_; - } else { - result.codec_ = codecBuilder_.build(); - } - if (sourceNodesBuilder_ == null) { - if (((bitField0_ & 0x00000020) == 0x00000020)) { - sourceNodes_ = java.util.Collections.unmodifiableList(sourceNodes_); - bitField0_ = (bitField0_ & ~0x00000020); - } - result.sourceNodes_ = sourceNodes_; - } else { - result.sourceNodes_ = sourceNodesBuilder_.build(); - } - if (((from_bitField0_ & 0x00000040) == 0x00000040)) { + if (((from_bitField0_ & 0x00000040) != 0)) { + result.remote_ = remoteBuilder_ == null + ? remote_ + : remoteBuilder_.build(); to_bitField0_ |= 0x00000020; } - if (remoteBuilder_ == null) { - result.remote_ = remote_; - } else { - result.remote_ = remoteBuilder_.build(); - } - if (((from_bitField0_ & 0x00000080) == 0x00000080)) { + if (((from_bitField0_ & 0x00000080) != 0)) { + result.payload_ = payload_; to_bitField0_ |= 0x00000040; } - result.payload_ = payload_; - if (((from_bitField0_ & 0x00000100) == 0x00000100)) { + if (((from_bitField0_ & 0x00000100) != 0)) { + result.sequenceNr_ = sequenceNr_; to_bitField0_ |= 0x00000080; } - result.sequenceNr_ = sequenceNr_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; + result.bitField0_ |= to_bitField0_; } + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof org.graylog2.plugin.journal.JournalMessages.JournalMessage) { return mergeFrom((org.graylog2.plugin.journal.JournalMessages.JournalMessage)other); @@ -959,8 +1030,8 @@ public Builder mergeFrom(org.graylog2.plugin.journal.JournalMessages.JournalMess sourceNodesBuilder_ = null; sourceNodes_ = other.sourceNodes_; bitField0_ = (bitField0_ & ~0x00000020); - sourceNodesBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + sourceNodesBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? getSourceNodesFieldBuilder() : null; } else { sourceNodesBuilder_.addAllMessages(other.sourceNodes_); @@ -977,73 +1048,153 @@ public Builder mergeFrom(org.graylog2.plugin.journal.JournalMessages.JournalMess setSequenceNr(other.getSequenceNr()); } this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); return this; } + @java.lang.Override public final boolean isInitialized() { return true; } + @java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - org.graylog2.plugin.journal.JournalMessages.JournalMessage parsedMessage = null; + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + version_ = input.readUInt32(); + bitField0_ |= 0x00000001; + break; + } // case 8 + case 17: { + uuidTime_ = input.readFixed64(); + bitField0_ |= 0x00000002; + break; + } // case 17 + case 25: { + uuidClockseq_ = input.readFixed64(); + bitField0_ |= 0x00000004; + break; + } // case 25 + case 33: { + timestamp_ = input.readFixed64(); + bitField0_ |= 0x00000008; + break; + } // case 33 + case 42: { + input.readMessage( + getCodecFieldBuilder().getBuilder(), + extensionRegistry); + bitField0_ |= 0x00000010; + break; + } // case 42 + case 50: { + org.graylog2.plugin.journal.JournalMessages.SourceNode m = + input.readMessage( + org.graylog2.plugin.journal.JournalMessages.SourceNode.PARSER, + extensionRegistry); + if (sourceNodesBuilder_ == null) { + ensureSourceNodesIsMutable(); + sourceNodes_.add(m); + } else { + sourceNodesBuilder_.addMessage(m); + } + break; + } // case 50 + case 58: { + input.readMessage( + getRemoteFieldBuilder().getBuilder(), + extensionRegistry); + bitField0_ |= 0x00000040; + break; + } // case 58 + case 66: { + payload_ = input.readBytes(); + bitField0_ |= 0x00000080; + break; + } // case 66 + case 72: { + sequenceNr_ = input.readUInt32(); + bitField0_ |= 0x00000100; + break; + } // case 72 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.graylog2.plugin.journal.JournalMessages.JournalMessage) e.getUnfinishedMessage(); - throw e; + throw e.unwrapIOException(); } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } + onChanged(); + } // finally return this; } private int bitField0_; - // optional uint32 version = 1; private int version_ ; /** - * optional uint32 version = 1; - * *
            * the version of the message format (used for simplifying code when deserializing messages)
            * 
    + * + * optional uint32 version = 1; + * @return Whether the version field is set. */ + @java.lang.Override public boolean hasVersion() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** - * optional uint32 version = 1; - * *
            * the version of the message format (used for simplifying code when deserializing messages)
            * 
    + * + * optional uint32 version = 1; + * @return The version. */ + @java.lang.Override public int getVersion() { return version_; } /** - * optional uint32 version = 1; - * *
            * the version of the message format (used for simplifying code when deserializing messages)
            * 
    + * + * optional uint32 version = 1; + * @param value The version to set. + * @return This builder for chaining. */ public Builder setVersion(int value) { - bitField0_ |= 0x00000001; + version_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } /** - * optional uint32 version = 1; - * *
            * the version of the message format (used for simplifying code when deserializing messages)
            * 
    + * + * optional uint32 version = 1; + * @return This builder for chaining. */ public Builder clearVersion() { bitField0_ = (bitField0_ & ~0x00000001); @@ -1052,47 +1203,54 @@ public Builder clearVersion() { return this; } - // optional fixed64 uuid_time = 2; private long uuidTime_ ; /** - * optional fixed64 uuid_time = 2; - * *
            * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
            * 
    + * + * optional fixed64 uuid_time = 2; + * @return Whether the uuidTime field is set. */ + @java.lang.Override public boolean hasUuidTime() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** - * optional fixed64 uuid_time = 2; - * *
            * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
            * 
    + * + * optional fixed64 uuid_time = 2; + * @return The uuidTime. */ + @java.lang.Override public long getUuidTime() { return uuidTime_; } /** - * optional fixed64 uuid_time = 2; - * *
            * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
            * 
    + * + * optional fixed64 uuid_time = 2; + * @param value The uuidTime to set. + * @return This builder for chaining. */ public Builder setUuidTime(long value) { - bitField0_ |= 0x00000002; + uuidTime_ = value; + bitField0_ |= 0x00000002; onChanged(); return this; } /** - * optional fixed64 uuid_time = 2; - * *
            * uuid, time is upper 64 bits, clockseq is lower 64 bits of the 128 bit uuid value
            * 
    + * + * optional fixed64 uuid_time = 2; + * @return This builder for chaining. */ public Builder clearUuidTime() { bitField0_ = (bitField0_ & ~0x00000002); @@ -1101,31 +1259,38 @@ public Builder clearUuidTime() { return this; } - // optional fixed64 uuid_clockseq = 3; private long uuidClockseq_ ; /** * optional fixed64 uuid_clockseq = 3; + * @return Whether the uuidClockseq field is set. */ + @java.lang.Override public boolean hasUuidClockseq() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000004) != 0); } /** * optional fixed64 uuid_clockseq = 3; + * @return The uuidClockseq. */ + @java.lang.Override public long getUuidClockseq() { return uuidClockseq_; } /** * optional fixed64 uuid_clockseq = 3; + * @param value The uuidClockseq to set. + * @return This builder for chaining. */ public Builder setUuidClockseq(long value) { - bitField0_ |= 0x00000004; + uuidClockseq_ = value; + bitField0_ |= 0x00000004; onChanged(); return this; } /** * optional fixed64 uuid_clockseq = 3; + * @return This builder for chaining. */ public Builder clearUuidClockseq() { bitField0_ = (bitField0_ & ~0x00000004); @@ -1134,47 +1299,54 @@ public Builder clearUuidClockseq() { return this; } - // optional fixed64 timestamp = 4; private long timestamp_ ; /** - * optional fixed64 timestamp = 4; - * *
            * milliseconds since Java epoch (1970/01/01 00:00:00.000)
            * 
    + * + * optional fixed64 timestamp = 4; + * @return Whether the timestamp field is set. */ + @java.lang.Override public boolean hasTimestamp() { - return ((bitField0_ & 0x00000008) == 0x00000008); + return ((bitField0_ & 0x00000008) != 0); } /** - * optional fixed64 timestamp = 4; - * *
            * milliseconds since Java epoch (1970/01/01 00:00:00.000)
            * 
    + * + * optional fixed64 timestamp = 4; + * @return The timestamp. */ + @java.lang.Override public long getTimestamp() { return timestamp_; } /** - * optional fixed64 timestamp = 4; - * *
            * milliseconds since Java epoch (1970/01/01 00:00:00.000)
            * 
    + * + * optional fixed64 timestamp = 4; + * @param value The timestamp to set. + * @return This builder for chaining. */ public Builder setTimestamp(long value) { - bitField0_ |= 0x00000008; + timestamp_ = value; + bitField0_ |= 0x00000008; onChanged(); return this; } /** - * optional fixed64 timestamp = 4; - * *
            * milliseconds since Java epoch (1970/01/01 00:00:00.000)
            * 
    + * + * optional fixed64 timestamp = 4; + * @return This builder for chaining. */ public Builder clearTimestamp() { bitField0_ = (bitField0_ & ~0x00000008); @@ -1183,40 +1355,41 @@ public Builder clearTimestamp() { return this; } - // optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - private org.graylog2.plugin.journal.JournalMessages.CodecInfo codec_ = org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance(); - private com.google.protobuf.SingleFieldBuilder< + private org.graylog2.plugin.journal.JournalMessages.CodecInfo codec_; + private com.google.protobuf.SingleFieldBuilderV3< org.graylog2.plugin.journal.JournalMessages.CodecInfo, org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder, org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder> codecBuilder_; /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; + * @return Whether the codec field is set. */ public boolean hasCodec() { - return ((bitField0_ & 0x00000010) == 0x00000010); + return ((bitField0_ & 0x00000010) != 0); } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; + * @return The codec. */ public org.graylog2.plugin.journal.JournalMessages.CodecInfo getCodec() { if (codecBuilder_ == null) { - return codec_; + return codec_ == null ? org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance() : codec_; } else { return codecBuilder_.getMessage(); } } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ public Builder setCodec(org.graylog2.plugin.journal.JournalMessages.CodecInfo value) { if (codecBuilder_ == null) { @@ -1224,77 +1397,79 @@ public Builder setCodec(org.graylog2.plugin.journal.JournalMessages.CodecInfo va throw new NullPointerException(); } codec_ = value; - onChanged(); } else { codecBuilder_.setMessage(value); } bitField0_ |= 0x00000010; + onChanged(); return this; } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ public Builder setCodec( org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder builderForValue) { if (codecBuilder_ == null) { codec_ = builderForValue.build(); - onChanged(); } else { codecBuilder_.setMessage(builderForValue.build()); } bitField0_ |= 0x00000010; + onChanged(); return this; } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ public Builder mergeCodec(org.graylog2.plugin.journal.JournalMessages.CodecInfo value) { if (codecBuilder_ == null) { - if (((bitField0_ & 0x00000010) == 0x00000010) && - codec_ != org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance()) { - codec_ = - org.graylog2.plugin.journal.JournalMessages.CodecInfo.newBuilder(codec_).mergeFrom(value).buildPartial(); + if (((bitField0_ & 0x00000010) != 0) && + codec_ != null && + codec_ != org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance()) { + getCodecBuilder().mergeFrom(value); } else { codec_ = value; } - onChanged(); } else { codecBuilder_.mergeFrom(value); } - bitField0_ |= 0x00000010; + if (codec_ != null) { + bitField0_ |= 0x00000010; + onChanged(); + } return this; } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ public Builder clearCodec() { - if (codecBuilder_ == null) { - codec_ = org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance(); - onChanged(); - } else { - codecBuilder_.clear(); - } bitField0_ = (bitField0_ & ~0x00000010); + codec_ = null; + if (codecBuilder_ != null) { + codecBuilder_.dispose(); + codecBuilder_ = null; + } + onChanged(); return this; } - /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * + /** *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ public org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder getCodecBuilder() { bitField0_ |= 0x00000010; @@ -1302,33 +1477,34 @@ public org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder getCodecBui return getCodecFieldBuilder().getBuilder(); } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ public org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder getCodecOrBuilder() { if (codecBuilder_ != null) { return codecBuilder_.getMessageOrBuilder(); } else { - return codec_; + return codec_ == null ? + org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance() : codec_; } } /** - * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; - * *
            * which format the payload is supposed to have
            * 
    + * + * optional .org.graylog2.plugin.journal.CodecInfo codec = 5; */ - private com.google.protobuf.SingleFieldBuilder< - org.graylog2.plugin.journal.JournalMessages.CodecInfo, org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder, org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder> + private com.google.protobuf.SingleFieldBuilderV3< + org.graylog2.plugin.journal.JournalMessages.CodecInfo, org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder, org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder> getCodecFieldBuilder() { if (codecBuilder_ == null) { - codecBuilder_ = new com.google.protobuf.SingleFieldBuilder< + codecBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< org.graylog2.plugin.journal.JournalMessages.CodecInfo, org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder, org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder>( - codec_, + getCodec(), getParentForChildren(), isClean()); codec_ = null; @@ -1336,25 +1512,24 @@ public org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder getCodecOr return codecBuilder_; } - // repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; private java.util.List sourceNodes_ = java.util.Collections.emptyList(); private void ensureSourceNodesIsMutable() { - if (!((bitField0_ & 0x00000020) == 0x00000020)) { + if (!((bitField0_ & 0x00000020) != 0)) { sourceNodes_ = new java.util.ArrayList(sourceNodes_); bitField0_ |= 0x00000020; } } - private com.google.protobuf.RepeatedFieldBuilder< + private com.google.protobuf.RepeatedFieldBuilderV3< org.graylog2.plugin.journal.JournalMessages.SourceNode, org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder, org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder> sourceNodesBuilder_; /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public java.util.List getSourceNodesList() { if (sourceNodesBuilder_ == null) { @@ -1364,11 +1539,11 @@ public java.util.List ge } } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public int getSourceNodesCount() { if (sourceNodesBuilder_ == null) { @@ -1378,11 +1553,11 @@ public int getSourceNodesCount() { } } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public org.graylog2.plugin.journal.JournalMessages.SourceNode getSourceNodes(int index) { if (sourceNodesBuilder_ == null) { @@ -1392,11 +1567,11 @@ public org.graylog2.plugin.journal.JournalMessages.SourceNode getSourceNodes(int } } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder setSourceNodes( int index, org.graylog2.plugin.journal.JournalMessages.SourceNode value) { @@ -1413,11 +1588,11 @@ public Builder setSourceNodes( return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder setSourceNodes( int index, org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder builderForValue) { @@ -1431,11 +1606,11 @@ public Builder setSourceNodes( return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder addSourceNodes(org.graylog2.plugin.journal.JournalMessages.SourceNode value) { if (sourceNodesBuilder_ == null) { @@ -1451,11 +1626,11 @@ public Builder addSourceNodes(org.graylog2.plugin.journal.JournalMessages.Source return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder addSourceNodes( int index, org.graylog2.plugin.journal.JournalMessages.SourceNode value) { @@ -1472,11 +1647,11 @@ public Builder addSourceNodes( return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder addSourceNodes( org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder builderForValue) { @@ -1490,11 +1665,11 @@ public Builder addSourceNodes( return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder addSourceNodes( int index, org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder builderForValue) { @@ -1508,17 +1683,18 @@ public Builder addSourceNodes( return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder addAllSourceNodes( java.lang.Iterable values) { if (sourceNodesBuilder_ == null) { ensureSourceNodesIsMutable(); - super.addAll(values, sourceNodes_); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, sourceNodes_); onChanged(); } else { sourceNodesBuilder_.addAllMessages(values); @@ -1526,11 +1702,11 @@ public Builder addAllSourceNodes( return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder clearSourceNodes() { if (sourceNodesBuilder_ == null) { @@ -1543,11 +1719,11 @@ public Builder clearSourceNodes() { return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public Builder removeSourceNodes(int index) { if (sourceNodesBuilder_ == null) { @@ -1560,22 +1736,22 @@ public Builder removeSourceNodes(int index) { return this; } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder getSourceNodesBuilder( int index) { return getSourceNodesFieldBuilder().getBuilder(index); } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder getSourceNodesOrBuilder( int index) { @@ -1585,13 +1761,13 @@ public org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder getSource } } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ - public java.util.List + public java.util.List getSourceNodesOrBuilderList() { if (sourceNodesBuilder_ != null) { return sourceNodesBuilder_.getMessageOrBuilderList(); @@ -1600,22 +1776,22 @@ public org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder getSource } } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder addSourceNodesBuilder() { return getSourceNodesFieldBuilder().addBuilder( org.graylog2.plugin.journal.JournalMessages.SourceNode.getDefaultInstance()); } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ public org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder addSourceNodesBuilder( int index) { @@ -1623,24 +1799,24 @@ public org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder addSourceN index, org.graylog2.plugin.journal.JournalMessages.SourceNode.getDefaultInstance()); } /** - * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; - * *
            * the list of graylog2 nodes which have handled the message (radios, servers) in receive order
            * 
    + * + * repeated .org.graylog2.plugin.journal.SourceNode source_nodes = 6; */ - public java.util.List + public java.util.List getSourceNodesBuilderList() { return getSourceNodesFieldBuilder().getBuilderList(); } - private com.google.protobuf.RepeatedFieldBuilder< - org.graylog2.plugin.journal.JournalMessages.SourceNode, org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder, org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder> + private com.google.protobuf.RepeatedFieldBuilderV3< + org.graylog2.plugin.journal.JournalMessages.SourceNode, org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder, org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder> getSourceNodesFieldBuilder() { if (sourceNodesBuilder_ == null) { - sourceNodesBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + sourceNodesBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< org.graylog2.plugin.journal.JournalMessages.SourceNode, org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder, org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder>( sourceNodes_, - ((bitField0_ & 0x00000020) == 0x00000020), + ((bitField0_ & 0x00000020) != 0), getParentForChildren(), isClean()); sourceNodes_ = null; @@ -1648,22 +1824,23 @@ public org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder addSourceN return sourceNodesBuilder_; } - // optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; - private org.graylog2.plugin.journal.JournalMessages.RemoteAddress remote_ = org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance(); - private com.google.protobuf.SingleFieldBuilder< + private org.graylog2.plugin.journal.JournalMessages.RemoteAddress remote_; + private com.google.protobuf.SingleFieldBuilderV3< org.graylog2.plugin.journal.JournalMessages.RemoteAddress, org.graylog2.plugin.journal.JournalMessages.RemoteAddress.Builder, org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder> remoteBuilder_; /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; + * @return Whether the remote field is set. */ public boolean hasRemote() { - return ((bitField0_ & 0x00000040) == 0x00000040); + return ((bitField0_ & 0x00000040) != 0); } /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; + * @return The remote. */ public org.graylog2.plugin.journal.JournalMessages.RemoteAddress getRemote() { if (remoteBuilder_ == null) { - return remote_; + return remote_ == null ? org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance() : remote_; } else { return remoteBuilder_.getMessage(); } @@ -1677,11 +1854,11 @@ public Builder setRemote(org.graylog2.plugin.journal.JournalMessages.RemoteAddre throw new NullPointerException(); } remote_ = value; - onChanged(); } else { remoteBuilder_.setMessage(value); } bitField0_ |= 0x00000040; + onChanged(); return this; } /** @@ -1691,11 +1868,11 @@ public Builder setRemote( org.graylog2.plugin.journal.JournalMessages.RemoteAddress.Builder builderForValue) { if (remoteBuilder_ == null) { remote_ = builderForValue.build(); - onChanged(); } else { remoteBuilder_.setMessage(builderForValue.build()); } bitField0_ |= 0x00000040; + onChanged(); return this; } /** @@ -1703,31 +1880,33 @@ public Builder setRemote( */ public Builder mergeRemote(org.graylog2.plugin.journal.JournalMessages.RemoteAddress value) { if (remoteBuilder_ == null) { - if (((bitField0_ & 0x00000040) == 0x00000040) && - remote_ != org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance()) { - remote_ = - org.graylog2.plugin.journal.JournalMessages.RemoteAddress.newBuilder(remote_).mergeFrom(value).buildPartial(); + if (((bitField0_ & 0x00000040) != 0) && + remote_ != null && + remote_ != org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance()) { + getRemoteBuilder().mergeFrom(value); } else { remote_ = value; } - onChanged(); } else { remoteBuilder_.mergeFrom(value); } - bitField0_ |= 0x00000040; + if (remote_ != null) { + bitField0_ |= 0x00000040; + onChanged(); + } return this; } /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; */ public Builder clearRemote() { - if (remoteBuilder_ == null) { - remote_ = org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance(); - onChanged(); - } else { - remoteBuilder_.clear(); - } bitField0_ = (bitField0_ & ~0x00000040); + remote_ = null; + if (remoteBuilder_ != null) { + remoteBuilder_.dispose(); + remoteBuilder_ = null; + } + onChanged(); return this; } /** @@ -1745,19 +1924,20 @@ public org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder getRem if (remoteBuilder_ != null) { return remoteBuilder_.getMessageOrBuilder(); } else { - return remote_; + return remote_ == null ? + org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance() : remote_; } } /** * optional .org.graylog2.plugin.journal.RemoteAddress remote = 7; */ - private com.google.protobuf.SingleFieldBuilder< - org.graylog2.plugin.journal.JournalMessages.RemoteAddress, org.graylog2.plugin.journal.JournalMessages.RemoteAddress.Builder, org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder> + private com.google.protobuf.SingleFieldBuilderV3< + org.graylog2.plugin.journal.JournalMessages.RemoteAddress, org.graylog2.plugin.journal.JournalMessages.RemoteAddress.Builder, org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder> getRemoteFieldBuilder() { if (remoteBuilder_ == null) { - remoteBuilder_ = new com.google.protobuf.SingleFieldBuilder< + remoteBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< org.graylog2.plugin.journal.JournalMessages.RemoteAddress, org.graylog2.plugin.journal.JournalMessages.RemoteAddress.Builder, org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder>( - remote_, + getRemote(), getParentForChildren(), isClean()); remote_ = null; @@ -1765,34 +1945,38 @@ public org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder getRem return remoteBuilder_; } - // optional bytes payload = 8; private com.google.protobuf.ByteString payload_ = com.google.protobuf.ByteString.EMPTY; /** * optional bytes payload = 8; + * @return Whether the payload field is set. */ + @java.lang.Override public boolean hasPayload() { - return ((bitField0_ & 0x00000080) == 0x00000080); + return ((bitField0_ & 0x00000080) != 0); } /** * optional bytes payload = 8; + * @return The payload. */ + @java.lang.Override public com.google.protobuf.ByteString getPayload() { return payload_; } /** * optional bytes payload = 8; + * @param value The payload to set. + * @return This builder for chaining. */ public Builder setPayload(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000080; + if (value == null) { throw new NullPointerException(); } payload_ = value; + bitField0_ |= 0x00000080; onChanged(); return this; } /** * optional bytes payload = 8; + * @return This builder for chaining. */ public Builder clearPayload() { bitField0_ = (bitField0_ & ~0x00000080); @@ -1801,31 +1985,38 @@ public Builder clearPayload() { return this; } - // optional uint32 sequence_nr = 9; private int sequenceNr_ ; /** * optional uint32 sequence_nr = 9; + * @return Whether the sequenceNr field is set. */ + @java.lang.Override public boolean hasSequenceNr() { - return ((bitField0_ & 0x00000100) == 0x00000100); + return ((bitField0_ & 0x00000100) != 0); } /** * optional uint32 sequence_nr = 9; + * @return The sequenceNr. */ + @java.lang.Override public int getSequenceNr() { return sequenceNr_; } /** * optional uint32 sequence_nr = 9; + * @param value The sequenceNr to set. + * @return This builder for chaining. */ public Builder setSequenceNr(int value) { - bitField0_ |= 0x00000100; + sequenceNr_ = value; + bitField0_ |= 0x00000100; onChanged(); return this; } /** * optional uint32 sequence_nr = 9; + * @return This builder for chaining. */ public Builder clearSequenceNr() { bitField0_ = (bitField0_ & ~0x00000100); @@ -1833,80 +2024,137 @@ public Builder clearSequenceNr() { onChanged(); return this; } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + // @@protoc_insertion_point(builder_scope:org.graylog2.plugin.journal.JournalMessage) } + // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.JournalMessage) + private static final org.graylog2.plugin.journal.JournalMessages.JournalMessage DEFAULT_INSTANCE; static { - defaultInstance = new JournalMessage(true); - defaultInstance.initFields(); + DEFAULT_INSTANCE = new org.graylog2.plugin.journal.JournalMessages.JournalMessage(); + } + + public static org.graylog2.plugin.journal.JournalMessages.JournalMessage getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public JournalMessage parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.graylog2.plugin.journal.JournalMessages.JournalMessage getDefaultInstanceForType() { + return DEFAULT_INSTANCE; } - // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.JournalMessage) } - public interface RemoteAddressOrBuilder - extends com.google.protobuf.MessageOrBuilder { + public interface RemoteAddressOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.graylog2.plugin.journal.RemoteAddress) + com.google.protobuf.MessageOrBuilder { - // optional bytes address = 1; /** - * optional bytes address = 1; - * *
          * the original remote (IP) address of the message sender, unresolved,
          * 
    + * + * optional bytes address = 1; + * @return Whether the address field is set. */ boolean hasAddress(); /** - * optional bytes address = 1; - * *
          * the original remote (IP) address of the message sender, unresolved,
          * 
    + * + * optional bytes address = 1; + * @return The address. */ com.google.protobuf.ByteString getAddress(); - // optional uint32 port = 2; /** - * optional uint32 port = 2; - * *
          * the port of the sender, if available/applicable
          * 
    + * + * optional uint32 port = 2; + * @return Whether the port field is set. */ boolean hasPort(); /** - * optional uint32 port = 2; - * *
          * the port of the sender, if available/applicable
          * 
    + * + * optional uint32 port = 2; + * @return The port. */ int getPort(); - // optional string resolved = 3; /** - * optional string resolved = 3; - * *
          * a processing node can optionally resolve the address early
          * 
    + * + * optional string resolved = 3; + * @return Whether the resolved field is set. */ boolean hasResolved(); /** - * optional string resolved = 3; - * *
          * a processing node can optionally resolve the address early
          * 
    + * + * optional string resolved = 3; + * @return The resolved. */ java.lang.String getResolved(); /** - * optional string resolved = 3; - * *
          * a processing node can optionally resolve the address early
          * 
    + * + * optional string resolved = 3; + * @return The bytes for resolved. */ com.google.protobuf.ByteString getResolvedBytes(); @@ -1915,182 +2163,124 @@ public interface RemoteAddressOrBuilder * Protobuf type {@code org.graylog2.plugin.journal.RemoteAddress} */ public static final class RemoteAddress extends - com.google.protobuf.GeneratedMessage - implements RemoteAddressOrBuilder { + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.graylog2.plugin.journal.RemoteAddress) + RemoteAddressOrBuilder { + private static final long serialVersionUID = 0L; // Use RemoteAddress.newBuilder() to construct. - private RemoteAddress(com.google.protobuf.GeneratedMessage.Builder builder) { + private RemoteAddress(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); - this.unknownFields = builder.getUnknownFields(); } - private RemoteAddress(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final RemoteAddress defaultInstance; - public static RemoteAddress getDefaultInstance() { - return defaultInstance; - } - - public RemoteAddress getDefaultInstanceForType() { - return defaultInstance; + private RemoteAddress() { + address_ = com.google.protobuf.ByteString.EMPTY; + resolved_ = ""; } - private final com.google.protobuf.UnknownFieldSet unknownFields; @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private RemoteAddress( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - bitField0_ |= 0x00000001; - address_ = input.readBytes(); - break; - } - case 16: { - bitField0_ |= 0x00000002; - port_ = input.readUInt32(); - break; - } - case 26: { - bitField0_ |= 0x00000004; - resolved_ = input.readBytes(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new RemoteAddress(); } + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_RemoteAddress_fieldAccessorTable .ensureFieldAccessorsInitialized( org.graylog2.plugin.journal.JournalMessages.RemoteAddress.class, org.graylog2.plugin.journal.JournalMessages.RemoteAddress.Builder.class); } - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public RemoteAddress parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new RemoteAddress(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - private int bitField0_; - // optional bytes address = 1; public static final int ADDRESS_FIELD_NUMBER = 1; - private com.google.protobuf.ByteString address_; + private com.google.protobuf.ByteString address_ = com.google.protobuf.ByteString.EMPTY; /** - * optional bytes address = 1; - * *
          * the original remote (IP) address of the message sender, unresolved,
          * 
    + * + * optional bytes address = 1; + * @return Whether the address field is set. */ + @java.lang.Override public boolean hasAddress() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** - * optional bytes address = 1; - * *
          * the original remote (IP) address of the message sender, unresolved,
          * 
    + * + * optional bytes address = 1; + * @return The address. */ + @java.lang.Override public com.google.protobuf.ByteString getAddress() { return address_; } - // optional uint32 port = 2; public static final int PORT_FIELD_NUMBER = 2; - private int port_; + private int port_ = 0; /** - * optional uint32 port = 2; - * *
          * the port of the sender, if available/applicable
          * 
    + * + * optional uint32 port = 2; + * @return Whether the port field is set. */ + @java.lang.Override public boolean hasPort() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** - * optional uint32 port = 2; - * *
          * the port of the sender, if available/applicable
          * 
    + * + * optional uint32 port = 2; + * @return The port. */ + @java.lang.Override public int getPort() { return port_; } - // optional string resolved = 3; public static final int RESOLVED_FIELD_NUMBER = 3; - private java.lang.Object resolved_; + @SuppressWarnings("serial") + private volatile java.lang.Object resolved_ = ""; /** - * optional string resolved = 3; - * *
          * a processing node can optionally resolve the address early
          * 
    + * + * optional string resolved = 3; + * @return Whether the resolved field is set. */ + @java.lang.Override public boolean hasResolved() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000004) != 0); } /** - * optional string resolved = 3; - * *
          * a processing node can optionally resolve the address early
          * 
    + * + * optional string resolved = 3; + * @return The resolved. */ + @java.lang.Override public java.lang.String getResolved() { java.lang.Object ref = resolved_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { - com.google.protobuf.ByteString bs = + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { @@ -2100,17 +2290,19 @@ public java.lang.String getResolved() { } } /** - * optional string resolved = 3; - * *
          * a processing node can optionally resolve the address early
          * 
    + * + * optional string resolved = 3; + * @return The bytes for resolved. */ + @java.lang.Override public com.google.protobuf.ByteString getResolvedBytes() { java.lang.Object ref = resolved_; if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); resolved_ = b; @@ -2120,65 +2312,118 @@ public java.lang.String getResolved() { } } - private void initFields() { - address_ = com.google.protobuf.ByteString.EMPTY; - port_ = 0; - resolved_ = ""; - } private byte memoizedIsInitialized = -1; + @java.lang.Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; memoizedIsInitialized = 1; return true; } + @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { + if (((bitField0_ & 0x00000001) != 0)) { output.writeBytes(1, address_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { + if (((bitField0_ & 0x00000002) != 0)) { output.writeUInt32(2, port_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - output.writeBytes(3, getResolvedBytes()); + if (((bitField0_ & 0x00000004) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, resolved_); } getUnknownFields().writeTo(output); } - private int memoizedSerializedSize = -1; + @java.lang.Override public int getSerializedSize() { - int size = memoizedSerializedSize; + int size = memoizedSize; if (size != -1) return size; size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { + if (((bitField0_ & 0x00000001) != 0)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(1, address_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { + if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(2, port_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(3, getResolvedBytes()); + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, resolved_); } size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; + memoizedSize = size; return size; } - private static final long serialVersionUID = 0L; @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.graylog2.plugin.journal.JournalMessages.RemoteAddress)) { + return super.equals(obj); + } + org.graylog2.plugin.journal.JournalMessages.RemoteAddress other = (org.graylog2.plugin.journal.JournalMessages.RemoteAddress) obj; + + if (hasAddress() != other.hasAddress()) return false; + if (hasAddress()) { + if (!getAddress() + .equals(other.getAddress())) return false; + } + if (hasPort() != other.hasPort()) return false; + if (hasPort()) { + if (getPort() + != other.getPort()) return false; + } + if (hasResolved() != other.hasResolved()) return false; + if (hasResolved()) { + if (!getResolved() + .equals(other.getResolved())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasAddress()) { + hash = (37 * hash) + ADDRESS_FIELD_NUMBER; + hash = (53 * hash) + getAddress().hashCode(); + } + if (hasPort()) { + hash = (37 * hash) + PORT_FIELD_NUMBER; + hash = (53 * hash) + getPort(); + } + if (hasResolved()) { + hash = (37 * hash) + RESOLVED_FIELD_NUMBER; + hash = (53 * hash) + getResolved().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); } - public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { @@ -2202,46 +2447,61 @@ public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFro } public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } + public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); } + public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } - public static Builder newBuilder() { return Builder.create(); } + @java.lang.Override public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } public static Builder newBuilder(org.graylog2.plugin.journal.JournalMessages.RemoteAddress prototype) { - return newBuilder().mergeFrom(prototype); + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); } - public Builder toBuilder() { return newBuilder(this); } @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -2249,14 +2509,16 @@ protected Builder newBuilderForType( * Protobuf type {@code org.graylog2.plugin.journal.RemoteAddress} */ public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder { + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.graylog2.plugin.journal.RemoteAddress) + org.graylog2.plugin.journal.JournalMessages.RemoteAddressOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_RemoteAddress_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -2265,46 +2527,36 @@ public static final class Builder extends // Construct using org.graylog2.plugin.journal.JournalMessages.RemoteAddress.newBuilder() private Builder() { - maybeForceBuilderInitialization(); + } private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } + } + @java.lang.Override public Builder clear() { super.clear(); + bitField0_ = 0; address_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); port_ = 0; - bitField0_ = (bitField0_ & ~0x00000002); resolved_ = ""; - bitField0_ = (bitField0_ & ~0x00000004); return this; } - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - + @java.lang.Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor; } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.RemoteAddress getDefaultInstanceForType() { return org.graylog2.plugin.journal.JournalMessages.RemoteAddress.getDefaultInstance(); } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.RemoteAddress build() { org.graylog2.plugin.journal.JournalMessages.RemoteAddress result = buildPartial(); if (!result.isInitialized()) { @@ -2313,27 +2565,65 @@ public org.graylog2.plugin.journal.JournalMessages.RemoteAddress build() { return result; } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.RemoteAddress buildPartial() { org.graylog2.plugin.journal.JournalMessages.RemoteAddress result = new org.graylog2.plugin.journal.JournalMessages.RemoteAddress(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(org.graylog2.plugin.journal.JournalMessages.RemoteAddress result) { int from_bitField0_ = bitField0_; int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + if (((from_bitField0_ & 0x00000001) != 0)) { + result.address_ = address_; to_bitField0_ |= 0x00000001; } - result.address_ = address_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + if (((from_bitField0_ & 0x00000002) != 0)) { + result.port_ = port_; to_bitField0_ |= 0x00000002; } - result.port_ = port_; - if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + if (((from_bitField0_ & 0x00000004) != 0)) { + result.resolved_ = resolved_; to_bitField0_ |= 0x00000004; } - result.resolved_ = resolved_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; + result.bitField0_ |= to_bitField0_; } + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof org.graylog2.plugin.journal.JournalMessages.RemoteAddress) { return mergeFrom((org.graylog2.plugin.journal.JournalMessages.RemoteAddress)other); @@ -2352,81 +2642,116 @@ public Builder mergeFrom(org.graylog2.plugin.journal.JournalMessages.RemoteAddre setPort(other.getPort()); } if (other.hasResolved()) { - bitField0_ |= 0x00000004; resolved_ = other.resolved_; + bitField0_ |= 0x00000004; onChanged(); } this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); return this; } + @java.lang.Override public final boolean isInitialized() { return true; } + @java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - org.graylog2.plugin.journal.JournalMessages.RemoteAddress parsedMessage = null; + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + address_ = input.readBytes(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 16: { + port_ = input.readUInt32(); + bitField0_ |= 0x00000002; + break; + } // case 16 + case 26: { + resolved_ = input.readBytes(); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.graylog2.plugin.journal.JournalMessages.RemoteAddress) e.getUnfinishedMessage(); - throw e; + throw e.unwrapIOException(); } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } + onChanged(); + } // finally return this; } private int bitField0_; - // optional bytes address = 1; private com.google.protobuf.ByteString address_ = com.google.protobuf.ByteString.EMPTY; /** - * optional bytes address = 1; - * *
            * the original remote (IP) address of the message sender, unresolved,
            * 
    + * + * optional bytes address = 1; + * @return Whether the address field is set. */ + @java.lang.Override public boolean hasAddress() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** - * optional bytes address = 1; - * *
            * the original remote (IP) address of the message sender, unresolved,
            * 
    + * + * optional bytes address = 1; + * @return The address. */ + @java.lang.Override public com.google.protobuf.ByteString getAddress() { return address_; } /** - * optional bytes address = 1; - * *
            * the original remote (IP) address of the message sender, unresolved,
            * 
    + * + * optional bytes address = 1; + * @param value The address to set. + * @return This builder for chaining. */ public Builder setAddress(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; + if (value == null) { throw new NullPointerException(); } address_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } /** - * optional bytes address = 1; - * *
            * the original remote (IP) address of the message sender, unresolved,
            * 
    + * + * optional bytes address = 1; + * @return This builder for chaining. */ public Builder clearAddress() { bitField0_ = (bitField0_ & ~0x00000001); @@ -2435,47 +2760,54 @@ public Builder clearAddress() { return this; } - // optional uint32 port = 2; private int port_ ; /** - * optional uint32 port = 2; - * *
            * the port of the sender, if available/applicable
            * 
    + * + * optional uint32 port = 2; + * @return Whether the port field is set. */ + @java.lang.Override public boolean hasPort() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** - * optional uint32 port = 2; - * *
            * the port of the sender, if available/applicable
            * 
    + * + * optional uint32 port = 2; + * @return The port. */ + @java.lang.Override public int getPort() { return port_; } /** - * optional uint32 port = 2; - * *
            * the port of the sender, if available/applicable
            * 
    + * + * optional uint32 port = 2; + * @param value The port to set. + * @return This builder for chaining. */ public Builder setPort(int value) { - bitField0_ |= 0x00000002; + port_ = value; + bitField0_ |= 0x00000002; onChanged(); return this; } /** - * optional uint32 port = 2; - * *
            * the port of the sender, if available/applicable
            * 
    + * + * optional uint32 port = 2; + * @return This builder for chaining. */ public Builder clearPort() { bitField0_ = (bitField0_ & ~0x00000002); @@ -2484,48 +2816,53 @@ public Builder clearPort() { return this; } - // optional string resolved = 3; private java.lang.Object resolved_ = ""; /** - * optional string resolved = 3; - * *
            * a processing node can optionally resolve the address early
            * 
    + * + * optional string resolved = 3; + * @return Whether the resolved field is set. */ public boolean hasResolved() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000004) != 0); } /** - * optional string resolved = 3; - * *
            * a processing node can optionally resolve the address early
            * 
    + * + * optional string resolved = 3; + * @return The resolved. */ public java.lang.String getResolved() { java.lang.Object ref = resolved_; if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - resolved_ = s; + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + resolved_ = s; + } return s; } else { return (java.lang.String) ref; } } /** - * optional string resolved = 3; - * *
            * a processing node can optionally resolve the address early
            * 
    + * + * optional string resolved = 3; + * @return The bytes for resolved. */ public com.google.protobuf.ByteString getResolvedBytes() { java.lang.Object ref = resolved_; if (ref instanceof String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); resolved_ = b; @@ -2535,108 +2872,166 @@ public java.lang.String getResolved() { } } /** - * optional string resolved = 3; - * *
            * a processing node can optionally resolve the address early
            * 
    + * + * optional string resolved = 3; + * @param value The resolved to set. + * @return This builder for chaining. */ public Builder setResolved( java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; + if (value == null) { throw new NullPointerException(); } resolved_ = value; + bitField0_ |= 0x00000004; onChanged(); return this; } /** - * optional string resolved = 3; - * *
            * a processing node can optionally resolve the address early
            * 
    + * + * optional string resolved = 3; + * @return This builder for chaining. */ public Builder clearResolved() { - bitField0_ = (bitField0_ & ~0x00000004); resolved_ = getDefaultInstance().getResolved(); + bitField0_ = (bitField0_ & ~0x00000004); onChanged(); return this; } /** - * optional string resolved = 3; - * *
            * a processing node can optionally resolve the address early
            * 
    + * + * optional string resolved = 3; + * @param value The bytes for resolved to set. + * @return This builder for chaining. */ public Builder setResolvedBytes( com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; + if (value == null) { throw new NullPointerException(); } resolved_ = value; + bitField0_ |= 0x00000004; onChanged(); return this; } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + // @@protoc_insertion_point(builder_scope:org.graylog2.plugin.journal.RemoteAddress) } + // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.RemoteAddress) + private static final org.graylog2.plugin.journal.JournalMessages.RemoteAddress DEFAULT_INSTANCE; static { - defaultInstance = new RemoteAddress(true); - defaultInstance.initFields(); + DEFAULT_INSTANCE = new org.graylog2.plugin.journal.JournalMessages.RemoteAddress(); + } + + public static org.graylog2.plugin.journal.JournalMessages.RemoteAddress getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public RemoteAddress parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.graylog2.plugin.journal.JournalMessages.RemoteAddress getDefaultInstanceForType() { + return DEFAULT_INSTANCE; } - // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.RemoteAddress) } - public interface CodecInfoOrBuilder - extends com.google.protobuf.MessageOrBuilder { + public interface CodecInfoOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.graylog2.plugin.journal.CodecInfo) + com.google.protobuf.MessageOrBuilder { - // optional string name = 1; /** * optional string name = 1; + * @return Whether the name field is set. */ boolean hasName(); /** * optional string name = 1; + * @return The name. */ java.lang.String getName(); /** * optional string name = 1; + * @return The bytes for name. */ com.google.protobuf.ByteString getNameBytes(); - // optional string config = 2; /** - * optional string config = 2; - * *
          * JSON description of configuration settings necessary to create the codec with
          * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
          * 
    + * + * optional string config = 2; + * @return Whether the config field is set. */ boolean hasConfig(); /** - * optional string config = 2; - * *
          * JSON description of configuration settings necessary to create the codec with
          * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
          * 
    + * + * optional string config = 2; + * @return The config. */ java.lang.String getConfig(); /** - * optional string config = 2; - * *
          * JSON description of configuration settings necessary to create the codec with
          * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
          * 
    + * + * optional string config = 2; + * @return The bytes for config. */ com.google.protobuf.ByteString getConfigBytes(); @@ -2645,121 +3040,62 @@ public interface CodecInfoOrBuilder * Protobuf type {@code org.graylog2.plugin.journal.CodecInfo} */ public static final class CodecInfo extends - com.google.protobuf.GeneratedMessage - implements CodecInfoOrBuilder { + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.graylog2.plugin.journal.CodecInfo) + CodecInfoOrBuilder { + private static final long serialVersionUID = 0L; // Use CodecInfo.newBuilder() to construct. - private CodecInfo(com.google.protobuf.GeneratedMessage.Builder builder) { + private CodecInfo(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private CodecInfo(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final CodecInfo defaultInstance; - public static CodecInfo getDefaultInstance() { - return defaultInstance; } - - public CodecInfo getDefaultInstanceForType() { - return defaultInstance; + private CodecInfo() { + name_ = ""; + config_ = ""; } - private final com.google.protobuf.UnknownFieldSet unknownFields; @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private CodecInfo( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - bitField0_ |= 0x00000001; - name_ = input.readBytes(); - break; - } - case 18: { - bitField0_ |= 0x00000002; - config_ = input.readBytes(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new CodecInfo(); } + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_CodecInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( org.graylog2.plugin.journal.JournalMessages.CodecInfo.class, org.graylog2.plugin.journal.JournalMessages.CodecInfo.Builder.class); } - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public CodecInfo parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new CodecInfo(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - private int bitField0_; - // optional string name = 1; public static final int NAME_FIELD_NUMBER = 1; - private java.lang.Object name_; + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; /** * optional string name = 1; + * @return Whether the name field is set. */ + @java.lang.Override public boolean hasName() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional string name = 1; + * @return The name. */ + @java.lang.Override public java.lang.String getName() { java.lang.Object ref = name_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { - com.google.protobuf.ByteString bs = + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { @@ -2770,12 +3106,14 @@ public java.lang.String getName() { } /** * optional string name = 1; + * @return The bytes for name. */ + @java.lang.Override public com.google.protobuf.ByteString getNameBytes() { java.lang.Object ref = name_; if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); name_ = b; @@ -2785,34 +3123,38 @@ public java.lang.String getName() { } } - // optional string config = 2; public static final int CONFIG_FIELD_NUMBER = 2; - private java.lang.Object config_; + @SuppressWarnings("serial") + private volatile java.lang.Object config_ = ""; /** - * optional string config = 2; - * *
          * JSON description of configuration settings necessary to create the codec with
          * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
          * 
    + * + * optional string config = 2; + * @return Whether the config field is set. */ + @java.lang.Override public boolean hasConfig() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** - * optional string config = 2; - * *
          * JSON description of configuration settings necessary to create the codec with
          * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
          * 
    + * + * optional string config = 2; + * @return The config. */ + @java.lang.Override public java.lang.String getConfig() { java.lang.Object ref = config_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { - com.google.protobuf.ByteString bs = + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { @@ -2822,18 +3164,20 @@ public java.lang.String getConfig() { } } /** - * optional string config = 2; - * *
          * JSON description of configuration settings necessary to create the codec with
          * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
          * 
    + * + * optional string config = 2; + * @return The bytes for config. */ + @java.lang.Override public com.google.protobuf.ByteString getConfigBytes() { java.lang.Object ref = config_; if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); config_ = b; @@ -2843,57 +3187,101 @@ public java.lang.String getConfig() { } } - private void initFields() { - name_ = ""; - config_ = ""; - } private byte memoizedIsInitialized = -1; + @java.lang.Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; memoizedIsInitialized = 1; return true; } + @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, getNameBytes()); + if (((bitField0_ & 0x00000001) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeBytes(2, getConfigBytes()); + if (((bitField0_ & 0x00000002) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, config_); } getUnknownFields().writeTo(output); } - private int memoizedSerializedSize = -1; + @java.lang.Override public int getSerializedSize() { - int size = memoizedSerializedSize; + int size = memoizedSize; if (size != -1) return size; size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, getNameBytes()); + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(2, getConfigBytes()); + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, config_); } size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; + memoizedSize = size; return size; } - private static final long serialVersionUID = 0L; @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.graylog2.plugin.journal.JournalMessages.CodecInfo)) { + return super.equals(obj); + } + org.graylog2.plugin.journal.JournalMessages.CodecInfo other = (org.graylog2.plugin.journal.JournalMessages.CodecInfo) obj; + + if (hasName() != other.hasName()) return false; + if (hasName()) { + if (!getName() + .equals(other.getName())) return false; + } + if (hasConfig() != other.hasConfig()) return false; + if (hasConfig()) { + if (!getConfig() + .equals(other.getConfig())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasName()) { + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + } + if (hasConfig()) { + hash = (37 * hash) + CONFIG_FIELD_NUMBER; + hash = (53 * hash) + getConfig().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; } + public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { @@ -2917,46 +3305,61 @@ public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom( } public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } + public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); } + public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.CodecInfo parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } - public static Builder newBuilder() { return Builder.create(); } + @java.lang.Override public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } public static Builder newBuilder(org.graylog2.plugin.journal.JournalMessages.CodecInfo prototype) { - return newBuilder().mergeFrom(prototype); + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); } - public Builder toBuilder() { return newBuilder(this); } @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -2964,14 +3367,16 @@ protected Builder newBuilderForType( * Protobuf type {@code org.graylog2.plugin.journal.CodecInfo} */ public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder { + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.graylog2.plugin.journal.CodecInfo) + org.graylog2.plugin.journal.JournalMessages.CodecInfoOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_CodecInfo_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -2980,44 +3385,35 @@ public static final class Builder extends // Construct using org.graylog2.plugin.journal.JournalMessages.CodecInfo.newBuilder() private Builder() { - maybeForceBuilderInitialization(); + } private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } + } + @java.lang.Override public Builder clear() { super.clear(); + bitField0_ = 0; name_ = ""; - bitField0_ = (bitField0_ & ~0x00000001); config_ = ""; - bitField0_ = (bitField0_ & ~0x00000002); return this; } - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - + @java.lang.Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor; } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.CodecInfo getDefaultInstanceForType() { return org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance(); } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.CodecInfo build() { org.graylog2.plugin.journal.JournalMessages.CodecInfo result = buildPartial(); if (!result.isInitialized()) { @@ -3026,23 +3422,61 @@ public org.graylog2.plugin.journal.JournalMessages.CodecInfo build() { return result; } - public org.graylog2.plugin.journal.JournalMessages.CodecInfo buildPartial() { - org.graylog2.plugin.journal.JournalMessages.CodecInfo result = new org.graylog2.plugin.journal.JournalMessages.CodecInfo(this); + @java.lang.Override + public org.graylog2.plugin.journal.JournalMessages.CodecInfo buildPartial() { + org.graylog2.plugin.journal.JournalMessages.CodecInfo result = new org.graylog2.plugin.journal.JournalMessages.CodecInfo(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(org.graylog2.plugin.journal.JournalMessages.CodecInfo result) { int from_bitField0_ = bitField0_; int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; to_bitField0_ |= 0x00000001; } - result.name_ = name_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + if (((from_bitField0_ & 0x00000002) != 0)) { + result.config_ = config_; to_bitField0_ |= 0x00000002; } - result.config_ = config_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; + result.bitField0_ |= to_bitField0_; } + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof org.graylog2.plugin.journal.JournalMessages.CodecInfo) { return mergeFrom((org.graylog2.plugin.journal.JournalMessages.CodecInfo)other); @@ -3055,59 +3489,89 @@ public Builder mergeFrom(com.google.protobuf.Message other) { public Builder mergeFrom(org.graylog2.plugin.journal.JournalMessages.CodecInfo other) { if (other == org.graylog2.plugin.journal.JournalMessages.CodecInfo.getDefaultInstance()) return this; if (other.hasName()) { - bitField0_ |= 0x00000001; name_ = other.name_; + bitField0_ |= 0x00000001; onChanged(); } if (other.hasConfig()) { - bitField0_ |= 0x00000002; config_ = other.config_; + bitField0_ |= 0x00000002; onChanged(); } this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); return this; } + @java.lang.Override public final boolean isInitialized() { return true; } + @java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - org.graylog2.plugin.journal.JournalMessages.CodecInfo parsedMessage = null; + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + name_ = input.readBytes(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: { + config_ = input.readBytes(); + bitField0_ |= 0x00000002; + break; + } // case 18 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.graylog2.plugin.journal.JournalMessages.CodecInfo) e.getUnfinishedMessage(); - throw e; + throw e.unwrapIOException(); } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } + onChanged(); + } // finally return this; } private int bitField0_; - // optional string name = 1; private java.lang.Object name_ = ""; /** * optional string name = 1; + * @return Whether the name field is set. */ public boolean hasName() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional string name = 1; + * @return The name. */ public java.lang.String getName() { java.lang.Object ref = name_; if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - name_ = s; + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } return s; } else { return (java.lang.String) ref; @@ -3115,12 +3579,13 @@ public java.lang.String getName() { } /** * optional string name = 1; + * @return The bytes for name. */ public com.google.protobuf.ByteString getNameBytes() { java.lang.Object ref = name_; if (ref instanceof String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); name_ = b; @@ -3131,85 +3596,91 @@ public java.lang.String getName() { } /** * optional string name = 1; + * @param value The name to set. + * @return This builder for chaining. */ public Builder setName( java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; + if (value == null) { throw new NullPointerException(); } name_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } /** * optional string name = 1; + * @return This builder for chaining. */ public Builder clearName() { - bitField0_ = (bitField0_ & ~0x00000001); name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); onChanged(); return this; } /** * optional string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. */ public Builder setNameBytes( com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; + if (value == null) { throw new NullPointerException(); } name_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } - // optional string config = 2; private java.lang.Object config_ = ""; /** - * optional string config = 2; - * *
            * JSON description of configuration settings necessary to create the codec with
            * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
            * 
    + * + * optional string config = 2; + * @return Whether the config field is set. */ public boolean hasConfig() { - return ((bitField0_ & 0x00000002) == 0x00000002); + return ((bitField0_ & 0x00000002) != 0); } /** - * optional string config = 2; - * *
            * JSON description of configuration settings necessary to create the codec with
            * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
            * 
    + * + * optional string config = 2; + * @return The config. */ public java.lang.String getConfig() { java.lang.Object ref = config_; if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - config_ = s; + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + config_ = s; + } return s; } else { return (java.lang.String) ref; } } /** - * optional string config = 2; - * *
            * JSON description of configuration settings necessary to create the codec with
            * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
            * 
    + * + * optional string config = 2; + * @return The bytes for config. */ public com.google.protobuf.ByteString getConfigBytes() { java.lang.Object ref = config_; if (ref instanceof String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); config_ = b; @@ -3219,106 +3690,165 @@ public java.lang.String getConfig() { } } /** - * optional string config = 2; - * *
            * JSON description of configuration settings necessary to create the codec with
            * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
            * 
    + * + * optional string config = 2; + * @param value The config to set. + * @return This builder for chaining. */ public Builder setConfig( java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000002; + if (value == null) { throw new NullPointerException(); } config_ = value; + bitField0_ |= 0x00000002; onChanged(); return this; } /** - * optional string config = 2; - * *
            * JSON description of configuration settings necessary to create the codec with
            * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
            * 
    + * + * optional string config = 2; + * @return This builder for chaining. */ public Builder clearConfig() { - bitField0_ = (bitField0_ & ~0x00000002); config_ = getDefaultInstance().getConfig(); + bitField0_ = (bitField0_ & ~0x00000002); onChanged(); return this; } /** - * optional string config = 2; - * *
            * JSON description of configuration settings necessary to create the codec with
            * for optimal performance make sure the serialization is stable, i.e. same config == same serialization bytes
            * 
    + * + * optional string config = 2; + * @param value The bytes for config to set. + * @return This builder for chaining. */ public Builder setConfigBytes( com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000002; + if (value == null) { throw new NullPointerException(); } config_ = value; + bitField0_ |= 0x00000002; onChanged(); return this; } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + // @@protoc_insertion_point(builder_scope:org.graylog2.plugin.journal.CodecInfo) } + // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.CodecInfo) + private static final org.graylog2.plugin.journal.JournalMessages.CodecInfo DEFAULT_INSTANCE; static { - defaultInstance = new CodecInfo(true); - defaultInstance.initFields(); + DEFAULT_INSTANCE = new org.graylog2.plugin.journal.JournalMessages.CodecInfo(); + } + + public static org.graylog2.plugin.journal.JournalMessages.CodecInfo getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public CodecInfo parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.graylog2.plugin.journal.JournalMessages.CodecInfo getDefaultInstanceForType() { + return DEFAULT_INSTANCE; } - // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.CodecInfo) } - public interface SourceNodeOrBuilder - extends com.google.protobuf.MessageOrBuilder { + public interface SourceNodeOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.graylog2.plugin.journal.SourceNode) + com.google.protobuf.MessageOrBuilder { - // optional string id = 1; /** * optional string id = 1; + * @return Whether the id field is set. */ boolean hasId(); /** * optional string id = 1; + * @return The id. */ java.lang.String getId(); /** * optional string id = 1; + * @return The bytes for id. */ com.google.protobuf.ByteString getIdBytes(); - // optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @return Whether the type field is set. */ boolean hasType(); /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @return The type. */ org.graylog2.plugin.journal.JournalMessages.SourceNode.Type getType(); - // optional string input_id = 3; /** * optional string input_id = 3; + * @return Whether the inputId field is set. */ boolean hasInputId(); /** * optional string input_id = 3; + * @return The inputId. */ java.lang.String getInputId(); /** * optional string input_id = 3; + * @return The bytes for inputId. */ com.google.protobuf.ByteString getInputIdBytes(); @@ -3327,113 +3857,40 @@ public interface SourceNodeOrBuilder * Protobuf type {@code org.graylog2.plugin.journal.SourceNode} */ public static final class SourceNode extends - com.google.protobuf.GeneratedMessage - implements SourceNodeOrBuilder { + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.graylog2.plugin.journal.SourceNode) + SourceNodeOrBuilder { + private static final long serialVersionUID = 0L; // Use SourceNode.newBuilder() to construct. - private SourceNode(com.google.protobuf.GeneratedMessage.Builder builder) { + private SourceNode(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private SourceNode(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final SourceNode defaultInstance; - public static SourceNode getDefaultInstance() { - return defaultInstance; } - - public SourceNode getDefaultInstanceForType() { - return defaultInstance; + private SourceNode() { + id_ = ""; + type_ = 0; + inputId_ = ""; } - private final com.google.protobuf.UnknownFieldSet unknownFields; @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private SourceNode( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - bitField0_ |= 0x00000001; - id_ = input.readBytes(); - break; - } - case 16: { - int rawValue = input.readEnum(); - org.graylog2.plugin.journal.JournalMessages.SourceNode.Type value = org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.valueOf(rawValue); - if (value == null) { - unknownFields.mergeVarintField(2, rawValue); - } else { - bitField0_ |= 0x00000002; - type_ = value; - } - break; - } - case 26: { - bitField0_ |= 0x00000004; - inputId_ = input.readBytes(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new SourceNode(); } + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_SourceNode_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_SourceNode_fieldAccessorTable .ensureFieldAccessorsInitialized( org.graylog2.plugin.journal.JournalMessages.SourceNode.class, org.graylog2.plugin.journal.JournalMessages.SourceNode.Builder.class); } - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public SourceNode parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new SourceNode(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - /** * Protobuf enum {@code org.graylog2.plugin.journal.SourceNode.Type} */ @@ -3442,11 +3899,11 @@ public enum Type /** * SERVER = 0; */ - SERVER(0, 0), + SERVER(0), /** * RADIO = 1; */ - RADIO(1, 1), + RADIO(1), ; /** @@ -3459,9 +3916,25 @@ public enum Type public static final int RADIO_VALUE = 1; - public final int getNumber() { return value; } + public final int getNumber() { + return value; + } + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated public static Type valueOf(int value) { + return forNumber(value); + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + */ + public static Type forNumber(int value) { switch (value) { case 0: return SERVER; case 1: return RADIO; @@ -3473,17 +3946,17 @@ public static Type valueOf(int value) { internalGetValueMap() { return internalValueMap; } - private static com.google.protobuf.Internal.EnumLiteMap - internalValueMap = + private static final com.google.protobuf.Internal.EnumLiteMap< + Type> internalValueMap = new com.google.protobuf.Internal.EnumLiteMap() { public Type findValueByNumber(int number) { - return Type.valueOf(number); + return Type.forNumber(number); } }; public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { - return getDescriptor().getValues().get(index); + return getDescriptor().getValues().get(ordinal()); } public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { @@ -3505,11 +3978,9 @@ public static Type valueOf( return VALUES[desc.getIndex()]; } - private final int index; private final int value; - private Type(int index, int value) { - this.index = index; + private Type(int value) { this.value = value; } @@ -3517,24 +3988,28 @@ private Type(int index, int value) { } private int bitField0_; - // optional string id = 1; public static final int ID_FIELD_NUMBER = 1; - private java.lang.Object id_; + @SuppressWarnings("serial") + private volatile java.lang.Object id_ = ""; /** * optional string id = 1; + * @return Whether the id field is set. */ + @java.lang.Override public boolean hasId() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional string id = 1; + * @return The id. */ + @java.lang.Override public java.lang.String getId() { java.lang.Object ref = id_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { - com.google.protobuf.ByteString bs = + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { @@ -3545,12 +4020,14 @@ public java.lang.String getId() { } /** * optional string id = 1; + * @return The bytes for id. */ + @java.lang.Override public com.google.protobuf.ByteString getIdBytes() { java.lang.Object ref = id_; if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); id_ = b; @@ -3560,40 +4037,46 @@ public java.lang.String getId() { } } - // optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; public static final int TYPE_FIELD_NUMBER = 2; - private org.graylog2.plugin.journal.JournalMessages.SourceNode.Type type_; + private int type_ = 0; /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @return Whether the type field is set. */ - public boolean hasType() { - return ((bitField0_ & 0x00000002) == 0x00000002); + @java.lang.Override public boolean hasType() { + return ((bitField0_ & 0x00000002) != 0); } /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @return The type. */ - public org.graylog2.plugin.journal.JournalMessages.SourceNode.Type getType() { - return type_; + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.SourceNode.Type getType() { + org.graylog2.plugin.journal.JournalMessages.SourceNode.Type result = org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.forNumber(type_); + return result == null ? org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.SERVER : result; } - // optional string input_id = 3; public static final int INPUT_ID_FIELD_NUMBER = 3; - private java.lang.Object inputId_; + @SuppressWarnings("serial") + private volatile java.lang.Object inputId_ = ""; /** * optional string input_id = 3; + * @return Whether the inputId field is set. */ + @java.lang.Override public boolean hasInputId() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000004) != 0); } /** * optional string input_id = 3; + * @return The inputId. */ + @java.lang.Override public java.lang.String getInputId() { java.lang.Object ref = inputId_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { - com.google.protobuf.ByteString bs = + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { @@ -3604,12 +4087,14 @@ public java.lang.String getInputId() { } /** * optional string input_id = 3; + * @return The bytes for inputId. */ + @java.lang.Override public com.google.protobuf.ByteString getInputIdBytes() { java.lang.Object ref = inputId_; if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); inputId_ = b; @@ -3619,65 +4104,116 @@ public java.lang.String getInputId() { } } - private void initFields() { - id_ = ""; - type_ = org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.SERVER; - inputId_ = ""; - } private byte memoizedIsInitialized = -1; + @java.lang.Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; memoizedIsInitialized = 1; return true; } + @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, getIdBytes()); + if (((bitField0_ & 0x00000001) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, id_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeEnum(2, type_.getNumber()); + if (((bitField0_ & 0x00000002) != 0)) { + output.writeEnum(2, type_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - output.writeBytes(3, getInputIdBytes()); + if (((bitField0_ & 0x00000004) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, inputId_); } getUnknownFields().writeTo(output); } - private int memoizedSerializedSize = -1; + @java.lang.Override public int getSerializedSize() { - int size = memoizedSerializedSize; + int size = memoizedSize; if (size != -1) return size; size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, getIdBytes()); + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, id_); } - if (((bitField0_ & 0x00000002) == 0x00000002)) { + if (((bitField0_ & 0x00000002) != 0)) { size += com.google.protobuf.CodedOutputStream - .computeEnumSize(2, type_.getNumber()); + .computeEnumSize(2, type_); } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(3, getInputIdBytes()); + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, inputId_); } size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; + memoizedSize = size; return size; } - private static final long serialVersionUID = 0L; @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.graylog2.plugin.journal.JournalMessages.SourceNode)) { + return super.equals(obj); + } + org.graylog2.plugin.journal.JournalMessages.SourceNode other = (org.graylog2.plugin.journal.JournalMessages.SourceNode) obj; + + if (hasId() != other.hasId()) return false; + if (hasId()) { + if (!getId() + .equals(other.getId())) return false; + } + if (hasType() != other.hasType()) return false; + if (hasType()) { + if (type_ != other.type_) return false; + } + if (hasInputId() != other.hasInputId()) return false; + if (hasInputId()) { + if (!getInputId() + .equals(other.getInputId())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasId()) { + hash = (37 * hash) + ID_FIELD_NUMBER; + hash = (53 * hash) + getId().hashCode(); + } + if (hasType()) { + hash = (37 * hash) + TYPE_FIELD_NUMBER; + hash = (53 * hash) + type_; + } + if (hasInputId()) { + hash = (37 * hash) + INPUT_ID_FIELD_NUMBER; + hash = (53 * hash) + getInputId().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; } + public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { @@ -3701,46 +4237,61 @@ public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom( } public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } + public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); } + public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return PARSER.parseFrom(input); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); } public static org.graylog2.plugin.journal.JournalMessages.SourceNode parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); } - public static Builder newBuilder() { return Builder.create(); } + @java.lang.Override public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } public static Builder newBuilder(org.graylog2.plugin.journal.JournalMessages.SourceNode prototype) { - return newBuilder().mergeFrom(prototype); + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); } - public Builder toBuilder() { return newBuilder(this); } @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -3748,14 +4299,16 @@ protected Builder newBuilderForType( * Protobuf type {@code org.graylog2.plugin.journal.SourceNode} */ public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder { + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.graylog2.plugin.journal.SourceNode) + org.graylog2.plugin.journal.JournalMessages.SourceNodeOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_SourceNode_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_SourceNode_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -3764,46 +4317,36 @@ public static final class Builder extends // Construct using org.graylog2.plugin.journal.JournalMessages.SourceNode.newBuilder() private Builder() { - maybeForceBuilderInitialization(); + } private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } + } + @java.lang.Override public Builder clear() { super.clear(); + bitField0_ = 0; id_ = ""; - bitField0_ = (bitField0_ & ~0x00000001); - type_ = org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.SERVER; - bitField0_ = (bitField0_ & ~0x00000002); + type_ = 0; inputId_ = ""; - bitField0_ = (bitField0_ & ~0x00000004); return this; } - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - + @java.lang.Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return org.graylog2.plugin.journal.JournalMessages.internal_static_org_graylog2_plugin_journal_SourceNode_descriptor; } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.SourceNode getDefaultInstanceForType() { return org.graylog2.plugin.journal.JournalMessages.SourceNode.getDefaultInstance(); } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.SourceNode build() { org.graylog2.plugin.journal.JournalMessages.SourceNode result = buildPartial(); if (!result.isInitialized()) { @@ -3812,27 +4355,65 @@ public org.graylog2.plugin.journal.JournalMessages.SourceNode build() { return result; } + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.SourceNode buildPartial() { org.graylog2.plugin.journal.JournalMessages.SourceNode result = new org.graylog2.plugin.journal.JournalMessages.SourceNode(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(org.graylog2.plugin.journal.JournalMessages.SourceNode result) { int from_bitField0_ = bitField0_; int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + if (((from_bitField0_ & 0x00000001) != 0)) { + result.id_ = id_; to_bitField0_ |= 0x00000001; } - result.id_ = id_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + if (((from_bitField0_ & 0x00000002) != 0)) { + result.type_ = type_; to_bitField0_ |= 0x00000002; } - result.type_ = type_; - if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + if (((from_bitField0_ & 0x00000004) != 0)) { + result.inputId_ = inputId_; to_bitField0_ |= 0x00000004; } - result.inputId_ = inputId_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; + result.bitField0_ |= to_bitField0_; } + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof org.graylog2.plugin.journal.JournalMessages.SourceNode) { return mergeFrom((org.graylog2.plugin.journal.JournalMessages.SourceNode)other); @@ -3845,62 +4426,104 @@ public Builder mergeFrom(com.google.protobuf.Message other) { public Builder mergeFrom(org.graylog2.plugin.journal.JournalMessages.SourceNode other) { if (other == org.graylog2.plugin.journal.JournalMessages.SourceNode.getDefaultInstance()) return this; if (other.hasId()) { - bitField0_ |= 0x00000001; id_ = other.id_; + bitField0_ |= 0x00000001; onChanged(); } if (other.hasType()) { setType(other.getType()); } if (other.hasInputId()) { - bitField0_ |= 0x00000004; inputId_ = other.inputId_; + bitField0_ |= 0x00000004; onChanged(); } this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); return this; } + @java.lang.Override public final boolean isInitialized() { return true; } + @java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - org.graylog2.plugin.journal.JournalMessages.SourceNode parsedMessage = null; + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + id_ = input.readBytes(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 16: { + int tmpRaw = input.readEnum(); + org.graylog2.plugin.journal.JournalMessages.SourceNode.Type tmpValue = + org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.forNumber(tmpRaw); + if (tmpValue == null) { + mergeUnknownVarintField(2, tmpRaw); + } else { + type_ = tmpRaw; + bitField0_ |= 0x00000002; + } + break; + } // case 16 + case 26: { + inputId_ = input.readBytes(); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.graylog2.plugin.journal.JournalMessages.SourceNode) e.getUnfinishedMessage(); - throw e; + throw e.unwrapIOException(); } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } + onChanged(); + } // finally return this; } private int bitField0_; - // optional string id = 1; private java.lang.Object id_ = ""; /** * optional string id = 1; + * @return Whether the id field is set. */ public boolean hasId() { - return ((bitField0_ & 0x00000001) == 0x00000001); + return ((bitField0_ & 0x00000001) != 0); } /** * optional string id = 1; + * @return The id. */ public java.lang.String getId() { java.lang.Object ref = id_; if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - id_ = s; + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + id_ = s; + } return s; } else { return (java.lang.String) ref; @@ -3908,12 +4531,13 @@ public java.lang.String getId() { } /** * optional string id = 1; + * @return The bytes for id. */ public com.google.protobuf.ByteString getIdBytes() { java.lang.Object ref = id_; if (ref instanceof String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); id_ = b; @@ -3924,93 +4548,104 @@ public java.lang.String getId() { } /** * optional string id = 1; + * @param value The id to set. + * @return This builder for chaining. */ public Builder setId( java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; + if (value == null) { throw new NullPointerException(); } id_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } /** * optional string id = 1; + * @return This builder for chaining. */ public Builder clearId() { - bitField0_ = (bitField0_ & ~0x00000001); id_ = getDefaultInstance().getId(); + bitField0_ = (bitField0_ & ~0x00000001); onChanged(); return this; } /** * optional string id = 1; + * @param value The bytes for id to set. + * @return This builder for chaining. */ public Builder setIdBytes( com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; + if (value == null) { throw new NullPointerException(); } id_ = value; + bitField0_ |= 0x00000001; onChanged(); return this; } - // optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; - private org.graylog2.plugin.journal.JournalMessages.SourceNode.Type type_ = org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.SERVER; + private int type_ = 0; /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @return Whether the type field is set. */ - public boolean hasType() { - return ((bitField0_ & 0x00000002) == 0x00000002); + @java.lang.Override public boolean hasType() { + return ((bitField0_ & 0x00000002) != 0); } /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @return The type. */ + @java.lang.Override public org.graylog2.plugin.journal.JournalMessages.SourceNode.Type getType() { - return type_; + org.graylog2.plugin.journal.JournalMessages.SourceNode.Type result = org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.forNumber(type_); + return result == null ? org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.SERVER : result; } /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @param value The type to set. + * @return This builder for chaining. */ public Builder setType(org.graylog2.plugin.journal.JournalMessages.SourceNode.Type value) { if (value == null) { throw new NullPointerException(); } bitField0_ |= 0x00000002; - type_ = value; + type_ = value.getNumber(); onChanged(); return this; } /** * optional .org.graylog2.plugin.journal.SourceNode.Type type = 2 [default = SERVER]; + * @return This builder for chaining. */ public Builder clearType() { bitField0_ = (bitField0_ & ~0x00000002); - type_ = org.graylog2.plugin.journal.JournalMessages.SourceNode.Type.SERVER; + type_ = 0; onChanged(); return this; } - // optional string input_id = 3; private java.lang.Object inputId_ = ""; /** * optional string input_id = 3; + * @return Whether the inputId field is set. */ public boolean hasInputId() { - return ((bitField0_ & 0x00000004) == 0x00000004); + return ((bitField0_ & 0x00000004) != 0); } /** * optional string input_id = 3; + * @return The inputId. */ public java.lang.String getInputId() { java.lang.Object ref = inputId_; if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - inputId_ = s; + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + inputId_ = s; + } return s; } else { return (java.lang.String) ref; @@ -4018,12 +4653,13 @@ public java.lang.String getInputId() { } /** * optional string input_id = 3; + * @return The bytes for inputId. */ public com.google.protobuf.ByteString getInputIdBytes() { java.lang.Object ref = inputId_; if (ref instanceof String) { - com.google.protobuf.ByteString b = + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); inputId_ = b; @@ -4034,77 +4670,130 @@ public java.lang.String getInputId() { } /** * optional string input_id = 3; + * @param value The inputId to set. + * @return This builder for chaining. */ public Builder setInputId( java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; + if (value == null) { throw new NullPointerException(); } inputId_ = value; + bitField0_ |= 0x00000004; onChanged(); return this; } /** * optional string input_id = 3; + * @return This builder for chaining. */ public Builder clearInputId() { - bitField0_ = (bitField0_ & ~0x00000004); inputId_ = getDefaultInstance().getInputId(); + bitField0_ = (bitField0_ & ~0x00000004); onChanged(); return this; } /** * optional string input_id = 3; + * @param value The bytes for inputId to set. + * @return This builder for chaining. */ public Builder setInputIdBytes( com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; + if (value == null) { throw new NullPointerException(); } inputId_ = value; + bitField0_ |= 0x00000004; onChanged(); return this; } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + // @@protoc_insertion_point(builder_scope:org.graylog2.plugin.journal.SourceNode) } + // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.SourceNode) + private static final org.graylog2.plugin.journal.JournalMessages.SourceNode DEFAULT_INSTANCE; static { - defaultInstance = new SourceNode(true); - defaultInstance.initFields(); + DEFAULT_INSTANCE = new org.graylog2.plugin.journal.JournalMessages.SourceNode(); + } + + public static org.graylog2.plugin.journal.JournalMessages.SourceNode getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public SourceNode parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.graylog2.plugin.journal.JournalMessages.SourceNode getDefaultInstanceForType() { + return DEFAULT_INSTANCE; } - // @@protoc_insertion_point(class_scope:org.graylog2.plugin.journal.SourceNode) } - private static com.google.protobuf.Descriptors.Descriptor + private static final com.google.protobuf.Descriptors.Descriptor internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_org_graylog2_plugin_journal_JournalMessage_fieldAccessorTable; - private static com.google.protobuf.Descriptors.Descriptor + private static final com.google.protobuf.Descriptors.Descriptor internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_org_graylog2_plugin_journal_RemoteAddress_fieldAccessorTable; - private static com.google.protobuf.Descriptors.Descriptor + private static final com.google.protobuf.Descriptors.Descriptor internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_org_graylog2_plugin_journal_CodecInfo_fieldAccessorTable; - private static com.google.protobuf.Descriptors.Descriptor + private static final com.google.protobuf.Descriptors.Descriptor internal_static_org_graylog2_plugin_journal_SourceNode_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_org_graylog2_plugin_journal_SourceNode_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { return descriptor; } - private static com.google.protobuf.Descriptors.FileDescriptor + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; static { java.lang.String[] descriptorData = { @@ -4117,7 +4806,7 @@ public Builder setInputIdBytes( "\n\014source_nodes\030\006 \003(\0132\'.org.graylog2.plug" + "in.journal.SourceNode\022:\n\006remote\030\007 \001(\0132*." + "org.graylog2.plugin.journal.RemoteAddres" + - "s\022\017\n\007payload\030\010 \001(\014\022\023\n\013sequence_nr\030\t \001(\r\"", + "s\022\017\n\007payload\030\010 \001(\014\022\023\n\013sequence_nr\030\t \001(\r\"" + "@\n\rRemoteAddress\022\017\n\007address\030\001 \001(\014\022\014\n\004por" + "t\030\002 \001(\r\022\020\n\010resolved\030\003 \001(\t\")\n\tCodecInfo\022\014" + "\n\004name\030\001 \001(\t\022\016\n\006config\030\002 \001(\t\"\215\001\n\nSourceN" + @@ -4127,42 +4816,34 @@ public Builder setInputIdBytes( "\000\022\t\n\005RADIO\020\001B.\n\033org.graylog2.plugin.jour" + "nalB\017JournalMessages" }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_org_graylog2_plugin_journal_JournalMessage_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor, - new java.lang.String[] { "Version", "UuidTime", "UuidClockseq", "Timestamp", "Codec", "SourceNodes", "Remote", "Payload", "SequenceNr", }); - internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_org_graylog2_plugin_journal_RemoteAddress_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor, - new java.lang.String[] { "Address", "Port", "Resolved", }); - internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor = - getDescriptor().getMessageTypes().get(2); - internal_static_org_graylog2_plugin_journal_CodecInfo_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor, - new java.lang.String[] { "Name", "Config", }); - internal_static_org_graylog2_plugin_journal_SourceNode_descriptor = - getDescriptor().getMessageTypes().get(3); - internal_static_org_graylog2_plugin_journal_SourceNode_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_org_graylog2_plugin_journal_SourceNode_descriptor, - new java.lang.String[] { "Id", "Type", "InputId", }); - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor + descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); + }); + internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_org_graylog2_plugin_journal_JournalMessage_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog2_plugin_journal_JournalMessage_descriptor, + new java.lang.String[] { "Version", "UuidTime", "UuidClockseq", "Timestamp", "Codec", "SourceNodes", "Remote", "Payload", "SequenceNr", }); + internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_org_graylog2_plugin_journal_RemoteAddress_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog2_plugin_journal_RemoteAddress_descriptor, + new java.lang.String[] { "Address", "Port", "Resolved", }); + internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_org_graylog2_plugin_journal_CodecInfo_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog2_plugin_journal_CodecInfo_descriptor, + new java.lang.String[] { "Name", "Config", }); + internal_static_org_graylog2_plugin_journal_SourceNode_descriptor = + getDescriptor().getMessageTypes().get(3); + internal_static_org_graylog2_plugin_journal_SourceNode_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_graylog2_plugin_journal_SourceNode_descriptor, + new java.lang.String[] { "Id", "Type", "InputId", }); } // @@protoc_insertion_point(outer_class_scope) diff --git a/graylog2-server/src/main/resources/ipfix_journal.proto b/graylog2-server/src/main/resources/ipfix_journal.proto index 114fa33a9aef..13caba464727 100644 --- a/graylog2-server/src/main/resources/ipfix_journal.proto +++ b/graylog2-server/src/main/resources/ipfix_journal.proto @@ -3,7 +3,7 @@ syntax = "proto2"; package org.graylog.integrations.ipfix; // to regenerate: -// install protobuf compiler (this was generated with 3.0.0, be careful with newer versions due to API changes in the runtime) +// install protobuf compiler (you can find the version that was used to generate the current java code in the preamble of the generated classes) // protoc --java_out=src/main/java src/main/resources/ipfix_journal.proto option java_package = "org.graylog.integrations.ipfix"; diff --git a/graylog2-server/src/main/resources/netflow_v9.proto b/graylog2-server/src/main/resources/netflow_v9.proto index f649dcd53764..6ee0881ded5c 100644 --- a/graylog2-server/src/main/resources/netflow_v9.proto +++ b/graylog2-server/src/main/resources/netflow_v9.proto @@ -3,7 +3,7 @@ syntax = "proto2"; package org.graylog.plugins.netflow.v9; // to regenerate: -// install protobuf compiler (this was generated with 3.0.0) +// install protobuf compiler (you can find the version that was used to generate the current java code in the preamble of the generated classes) // protoc --java_out=src/main/java src/main/resources/netflow_v9.proto option java_package = "org.graylog.plugins.netflow.v9"; diff --git a/graylog2-server/src/main/resources/org/graylog2/plugin/journal/raw_message.proto b/graylog2-server/src/main/resources/org/graylog2/plugin/journal/raw_message.proto index a2c395947fd2..dd1ef723e7b2 100644 --- a/graylog2-server/src/main/resources/org/graylog2/plugin/journal/raw_message.proto +++ b/graylog2-server/src/main/resources/org/graylog2/plugin/journal/raw_message.proto @@ -3,7 +3,7 @@ syntax = "proto2"; package org.graylog2.plugin.journal; // to regenerate JournalMessages.java: -// install protobuf compiler (at the time of writing 2.5.0) +// install protobuf compiler (you can find the version that was used to generate the current java code in the preamble of the generated classes) // cd graylog2-server/src/main && protoc --java_out=java resources/org/graylog2/plugin/journal/raw_message.proto option java_package = "org.graylog2.plugin.journal"; diff --git a/graylog2-server/src/test/java/org/graylog2/plugin/journal/RawMessageTest.java b/graylog2-server/src/test/java/org/graylog2/plugin/journal/RawMessageTest.java index 8ce550df3611..41f7a28f959f 100644 --- a/graylog2-server/src/test/java/org/graylog2/plugin/journal/RawMessageTest.java +++ b/graylog2-server/src/test/java/org/graylog2/plugin/journal/RawMessageTest.java @@ -20,7 +20,6 @@ import org.graylog2.plugin.system.SimpleNodeId; import org.junit.Test; -import java.io.IOException; import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertArrayEquals; @@ -29,7 +28,7 @@ public class RawMessageTest { @Test - public void minimalEncodeDecode() throws IOException { + public void minimalEncodeDecode() { final RawMessage rawMessage = new RawMessage("testmessage".getBytes(StandardCharsets.UTF_8)); rawMessage.addSourceNode("inputid", new SimpleNodeId("5ca1ab1e-0000-4000-a000-000000000000")); rawMessage.setCodecName("raw"); diff --git a/pom.xml b/pom.xml index 9417537804cb..597d01b0b306 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,7 @@ 1.2.3 3.0.10 0.16.0 - 3.25.5 + 3.25.6 0.10.2 2.11.0 2.2.0-graylog.1 From 9af34d11484cadd0a2374d0d3676cbee873dab11 Mon Sep 17 00:00:00 2001 From: Mohamed OULD HOCINE <106236152+gally47@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:24:09 +0100 Subject: [PATCH 41/56] UI Framework for deprecating pipeline functions (#21467) * added deprecated label to rulebuilder actions list * changelog file * added deprecated label to rule builder * fix eslint issues * added deprecated label to Rules quick reference * fix eslint issue * add tests * removed duplicated test --- changelog/unreleased/pr-21467.toml | 5 +++ .../rule-builder/RuleBlockDisplay.test.tsx | 15 +++++++-- .../rules/rule-builder/RuleBlockDisplay.tsx | 26 +++++++++------- .../rules/rule-builder/RuleBlockForm.test.tsx | 6 ++++ .../rules/rule-builder/RuleBlockForm.tsx | 31 +++++++++++++------ .../rules/rule-builder/RuleBuilderBlock.tsx | 8 ++--- .../components/rules/rule-builder/fixtures.ts | 12 +++++++ .../components/rules/rule-builder/types.ts | 1 + .../rules/rule-helper/RulerHelperTable.tsx | 24 +++++++------- 9 files changed, 88 insertions(+), 40 deletions(-) create mode 100644 changelog/unreleased/pr-21467.toml diff --git a/changelog/unreleased/pr-21467.toml b/changelog/unreleased/pr-21467.toml new file mode 100644 index 000000000000..d0a80594a6e5 --- /dev/null +++ b/changelog/unreleased/pr-21467.toml @@ -0,0 +1,5 @@ +type = "f" +message = "UI Framework for deprecating pipeline functions" + +pulls = ["21467"] +issues = ["19287"] diff --git a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.test.tsx b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.test.tsx index 808769cb9444..c66e4990d94b 100644 --- a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.test.tsx +++ b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.test.tsx @@ -18,8 +18,7 @@ import * as React from 'react'; import { fireEvent, render, screen } from 'wrappedTestingLibrary'; import RuleBlockDisplay from './RuleBlockDisplay'; -import { buildRuleBlock } from './fixtures'; -import { RuleBuilderTypes } from './types'; +import { actionsBlockDict, buildRuleBlock } from './fixtures'; import RuleBuilderProvider from './RuleBuilderProvider'; const block = buildRuleBlock({ @@ -52,7 +51,7 @@ describe('RuleBlockDisplay', () => { it('shows the outputvariable and its return type', async () => { render( - + , ); @@ -116,4 +115,14 @@ describe('RuleBlockDisplay', () => { expect(screen.getByText('wrong 1, not right 2')).toBeInTheDocument(); }); + + it('shows a deprecated label for deprecating pipeline functions', async () => { + render( + + + , + ); + + expect(screen.getByText('Deprecated')).toBeInTheDocument(); + }); }); diff --git a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.tsx b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.tsx index 65bd21c4fd75..7dd11b6c19eb 100644 --- a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.tsx +++ b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockDisplay.tsx @@ -22,7 +22,7 @@ import { IconButton } from 'components/common'; import { MORE_ACTIONS_TITLE, MORE_ACTIONS_HOVER_TITLE } from 'components/common/EntityDataTable/Constants'; import OverlayDropdownButton from 'components/common/OverlayDropdownButton'; -import type { BlockType, RuleBlock } from './types'; +import type { BlockDict, BlockType, RuleBlock } from './types'; import { RuleBuilderTypes } from './types'; import { useRuleBuilder } from './RuleBuilderContext'; @@ -35,7 +35,7 @@ type Props = { onDuplicate: () => void, onInsertAbove: () => void, onInsertBelow: () => void, - returnType?: RuleBuilderTypes, + selectedBlockDict?: BlockDict, type: BlockType, } @@ -89,7 +89,11 @@ const EditIconButton = styled(IconButton)(({ theme }) => css` margin-right: ${theme.spacings.xs}; `); -const RuleBlockDisplay = ({ block, negatable = false, onEdit, onDelete, onNegate, onDuplicate, onInsertAbove, onInsertBelow, returnType, type } : Props) => { +const DeprecatedLabel = styled(Label)` + padding: 2px 8px; +`; + +const RuleBlockDisplay = ({ block = undefined, negatable = false, onEdit, onDelete, onNegate, onDuplicate, onInsertAbove, onInsertBelow, selectedBlockDict = undefined, type } : Props) => { const [showActions, setShowActions] = useState(false); const [isDropdownOpen, setIsDropdownOpen] = useState(false); const [highlightedOutput, setHighlightedOutput] = useRuleBuilder().useHighlightedOutput; @@ -108,7 +112,7 @@ const RuleBlockDisplay = ({ block, negatable = false, onEdit, onDelete, onNegate } }; - const returnTypeLabel = readableReturnType(returnType); + const returnTypeLabel = readableReturnType(selectedBlockDict?.return_type); const highlightedRuleTitle = (termToHighlight: string, title: string = '') => { const parts = title.split(/('\$.*?')/); @@ -122,13 +126,10 @@ const RuleBlockDisplay = ({ block, negatable = false, onEdit, onDelete, onNegate }); return (partsWithHighlight.map((item, index) => ( - - ( - - - {item} - - ) + // eslint-disable-next-line react/no-array-index-key + + {item} + ))); }; @@ -147,6 +148,9 @@ const RuleBlockDisplay = ({ block, negatable = false, onEdit, onDelete, onNegate {highlightedOutput ? ( highlightedRuleTitle(highlightedOutput, block?.step_title) ) : block?.step_title} + {selectedBlockDict?.deprecated && ( +  Deprecated + )} {block?.errors?.length > 0 && ( {errorMessage} )} diff --git a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.test.tsx b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.test.tsx index befea772cf54..a35c4cb6c717 100644 --- a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.test.tsx +++ b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.test.tsx @@ -170,4 +170,10 @@ describe('RuleBlockForm', () => { expect(screen.getByText('wrong 1')).toBeInTheDocument(); expect(screen.getByText('not right 2')).toBeInTheDocument(); }); + + it('shows a deprecated label for deprecating pipeline functions', async () => { + render(comp({ selectedBlockDict: actionsBlockDict[0] })); + + expect(screen.getByText('Deprecated')).toBeInTheDocument(); + }); }); diff --git a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.tsx b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.tsx index 2a3eeca7db16..7a2345c89554 100644 --- a/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.tsx +++ b/graylog2-web-interface/src/components/rules/rule-builder/RuleBlockForm.tsx @@ -19,7 +19,7 @@ import { Formik } from 'formik'; import styled, { css } from 'styled-components'; import { FormSubmit, Icon, OverlayTrigger, Select, NestedForm } from 'components/common'; -import { Button, Col, Row } from 'components/bootstrap'; +import { Button, Col, Label, Row } from 'components/bootstrap'; import RuleBlockFormField from 'components/rules/rule-builder/RuleBlockFormField'; import { getPathnameWithoutId } from 'util/URLUtils'; import useLocation from 'routing/useLocation'; @@ -32,7 +32,7 @@ import type { BlockType, RuleBlock, BlockDict, BlockFieldDict, OutputVariables } import RuleHelperTable from '../rule-helper/RulerHelperTable'; -type Option = { label: string, value: any, description?: string | null }; +type Option = { label: string, value: any, description?: string | null, deprecated?: boolean }; type Props = { existingBlock?: RuleBlock, @@ -81,16 +81,25 @@ const OptionDescription = styled.p<{ $isSelected: boolean }>(({ theme, $isSelect overflow: hidden; `); +const OptionContainer = styled.div` + display: flex; + justify-content: space-between; +`; + +const DeprecatedLabel = styled.span` + float: right; +`; + const RuleBlockForm = ({ - existingBlock, + existingBlock = undefined, onAdd, onCancel, onSelect, onUpdate, options, order, - outputVariableList, - selectedBlockDict, + outputVariableList = [], + selectedBlockDict = undefined, type, }: Props) => { const [initialValues, setInitialValues] = useState<{}>({}); @@ -166,7 +175,10 @@ const RuleBlockForm = ({ const optionRenderer = (option: Option, isSelected: boolean) => ( <> - {option.label} + + {option.label} + {option.deprecated && } + {option.description && ({option.description})} ); @@ -210,6 +222,9 @@ const RuleBlockForm = ({ data-testid="funcSyntaxHelpIcon" /> + {selectedBlockDict.deprecated && ( +   + )} {selectedBlockDict.description} @@ -225,8 +240,7 @@ const RuleBlockForm = ({ blockType={type} resetField={(fieldName) => resetField(fieldName, setFieldValue)} /> - ), - )} + ))} - )} diff --git a/graylog2-web-interface/src/components/rules/rule-builder/RuleBuilderBlock.tsx b/graylog2-web-interface/src/components/rules/rule-builder/RuleBuilderBlock.tsx index 8f00d47158ad..f0d416d1ee41 100644 --- a/graylog2-web-interface/src/components/rules/rule-builder/RuleBuilderBlock.tsx +++ b/graylog2-web-interface/src/components/rules/rule-builder/RuleBuilderBlock.tsx @@ -46,9 +46,9 @@ type Props = { const RuleBuilderBlock = ({ type, blockDict, - block, + block = undefined, order, - outputVariableList, + outputVariableList = [], addBlock, updateBlock, deleteBlock, @@ -210,7 +210,7 @@ const RuleBuilderBlock = ({ const isBlockNegatable = (): boolean => type === 'condition'; - const options = blockDict.map(({ name, description, rule_builder_name }) => ({ label: rule_builder_name, value: name, description: description })); + const options = blockDict.map(({ name, description, rule_builder_name, deprecated }) => ({ label: rule_builder_name, value: name, description, deprecated })); const showForm = !block || editMode; @@ -236,7 +236,7 @@ const RuleBuilderBlock = ({ onDuplicate={onDuplicate} onInsertAbove={onInsertAbove} onInsertBelow={onInsertBelow} - returnType={currentBlockDict?.return_type} + selectedBlockDict={currentBlockDict} negatable={isBlockNegatable()} type={type} /> {Boolean(insertMode) && ( diff --git a/graylog2-web-interface/src/components/rules/rule-builder/fixtures.ts b/graylog2-web-interface/src/components/rules/rule-builder/fixtures.ts index 4c943c465acf..ccfab4d82a12 100644 --- a/graylog2-web-interface/src/components/rules/rule-builder/fixtures.ts +++ b/graylog2-web-interface/src/components/rules/rule-builder/fixtures.ts @@ -20,6 +20,7 @@ import { RuleBuilderTypes } from './types'; const conditionsBlockDict: BlockDict[] = [ { name: 'has_field_less_or_equal', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Boolean, params: [ @@ -50,6 +51,7 @@ const conditionsBlockDict: BlockDict[] = [ }, { name: 'has_field', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Boolean, params: [ @@ -80,6 +82,7 @@ const conditionsBlockDict: BlockDict[] = [ }, { name: 'has_field_greater_or_equal', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Boolean, params: [ @@ -111,6 +114,7 @@ const conditionsBlockDict: BlockDict[] = [ }, { name: 'has_field_equals', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Boolean, params: [ @@ -144,6 +148,7 @@ const conditionsBlockDict: BlockDict[] = [ const actionsBlockDict: BlockDict[] = [ { name: 'has_field', + deprecated: true, pure: false, return_type: RuleBuilderTypes.Boolean, params: [ @@ -174,6 +179,7 @@ const actionsBlockDict: BlockDict[] = [ }, { name: 'to_long', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Number, params: [ @@ -204,6 +210,7 @@ const actionsBlockDict: BlockDict[] = [ }, { name: 'get_field', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Object, params: [ @@ -234,6 +241,7 @@ const actionsBlockDict: BlockDict[] = [ }, { name: 'set_grok_to_fields', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Void, params: [ @@ -291,6 +299,7 @@ const actionsBlockDict: BlockDict[] = [ }, { name: 'substring', + deprecated: false, pure: false, return_type: RuleBuilderTypes.String, params: [ @@ -330,6 +339,7 @@ const actionsBlockDict: BlockDict[] = [ }, { name: 'to_string', + deprecated: false, pure: false, return_type: RuleBuilderTypes.String, params: [ @@ -360,6 +370,7 @@ const actionsBlockDict: BlockDict[] = [ }, { name: 'set_field', + deprecated: false, pure: false, return_type: RuleBuilderTypes.Void, params: [ @@ -426,6 +437,7 @@ const actionsBlockDict: BlockDict[] = [ }, { name: 'format_date', + deprecated: false, pure: false, return_type: RuleBuilderTypes.String, params: [ diff --git a/graylog2-web-interface/src/components/rules/rule-builder/types.ts b/graylog2-web-interface/src/components/rules/rule-builder/types.ts index 056911ce211f..9de4aeffb19e 100644 --- a/graylog2-web-interface/src/components/rules/rule-builder/types.ts +++ b/graylog2-web-interface/src/components/rules/rule-builder/types.ts @@ -88,6 +88,7 @@ export type BlockFieldDict = { export type BlockDict = { name: string, pure: boolean, + deprecated: boolean, return_type: RuleBuilderTypes, params: Array, description: string | null, diff --git a/graylog2-web-interface/src/components/rules/rule-helper/RulerHelperTable.tsx b/graylog2-web-interface/src/components/rules/rule-helper/RulerHelperTable.tsx index 98528f6456c2..bcaa1e130770 100644 --- a/graylog2-web-interface/src/components/rules/rule-helper/RulerHelperTable.tsx +++ b/graylog2-web-interface/src/components/rules/rule-helper/RulerHelperTable.tsx @@ -16,7 +16,7 @@ */ import React from 'react'; -import { Table } from 'components/bootstrap'; +import { Label, Table } from 'components/bootstrap'; import { Icon } from 'components/common'; import RuleHelperStyle from './RuleHelper.css'; @@ -30,7 +30,7 @@ type Props = { onFunctionClick?: (functionName: string) => void } -const RuleHelperTable = ({ entries, expanded = {}, onFunctionClick } : Props) => { +const RuleHelperTable = ({ entries, expanded = {}, onFunctionClick = undefined } : Props) => { const parameters = (descriptor: BlockDict) => descriptor.params.map((p) => ( {p.name} @@ -72,17 +72,15 @@ const RuleHelperTable = ({ entries, expanded = {}, onFunctionClick } : Props) => return ( - {onFunctionClick ? ( - onFunctionClick(d.name)} className={RuleHelperStyle.clickableRow}> - {functionSignature(d)} - {d.description} - - ) : ( - - {functionSignature(d)} - {d.description} - - )} + onFunctionClick(d.name) : undefined} className={onFunctionClick ? RuleHelperStyle.clickableRow : undefined}> + {functionSignature(d)} + + {d.deprecated && ( +   + )} + {d.description} + + {details} ); From 8062b903fad5765fc7913aa5608c121320570d24 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 12:00:16 +0100 Subject: [PATCH 42/56] Bump posthog-js from 1.176.0 to 1.214.0 in /graylog2-web-interface (#21500) * Bump posthog-js from 1.176.0 to 1.214.0 in /graylog2-web-interface Bumps [posthog-js](https://github.com/PostHog/posthog-js) from 1.176.0 to 1.214.0. - [Release notes](https://github.com/PostHog/posthog-js/releases) - [Changelog](https://github.com/PostHog/posthog-js/blob/main/CHANGELOG.md) - [Commits](https://github.com/PostHog/posthog-js/compare/v1.176.0...v1.214.0) --- updated-dependencies: - dependency-name: posthog-js dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Using correct component in test. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dennis Oelkers Co-authored-by: Ousmane SAMBA --- .../src/logic/telemetry/TelemetryProvider.test.tsx | 6 +++--- graylog2-web-interface/yarn.lock | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/graylog2-web-interface/src/logic/telemetry/TelemetryProvider.test.tsx b/graylog2-web-interface/src/logic/telemetry/TelemetryProvider.test.tsx index b9edd79c479e..0420cfb0620b 100644 --- a/graylog2-web-interface/src/logic/telemetry/TelemetryProvider.test.tsx +++ b/graylog2-web-interface/src/logic/telemetry/TelemetryProvider.test.tsx @@ -19,10 +19,10 @@ import { render } from 'wrappedTestingLibrary'; import mockComponent from 'helpers/mocking/MockComponent'; import { asMock, MockStore } from 'helpers/mocking'; -import TelemetryInit from 'logic/telemetry/TelemetryInit'; import { TelemetrySettingsStore } from 'stores/telemetry/TelemetrySettingsStore'; import useTelemetryData from 'logic/telemetry/useTelemetryData'; import TelemetryContext from 'logic/telemetry/TelemetryContext'; +import TelemetryProvider from 'logic/telemetry/TelemetryProvider'; const mockedTelemetryConfig = { api_key: 'key', @@ -74,11 +74,11 @@ const renderSUT = () => { const consume = jest.fn(); render( - + {consume} - , + , ); return consume; diff --git a/graylog2-web-interface/yarn.lock b/graylog2-web-interface/yarn.lock index bf6a753be6a6..73806ed13ba7 100644 --- a/graylog2-web-interface/yarn.lock +++ b/graylog2-web-interface/yarn.lock @@ -13189,9 +13189,9 @@ postcss@^8.5.1: source-map-js "^1.2.1" posthog-js@^1.52.0: - version "1.176.0" - resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.176.0.tgz#39841ab213aa9c5500982659dc6d537a407f7205" - integrity sha512-T5XKNtRzp7q6CGb7Vc7wAI76rWap9fiuDUPxPsyPBPDkreKya91x9RIsSapAVFafwD1AEin1QMczCmt9Le9BWw== + version "1.214.0" + resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.214.0.tgz#e78a304b17db822bcbfb29affbc94b63b292d01a" + integrity sha512-zJpTAB/85wkr2YtpeH6K/JLeenVRoFnyA4pj8Yern3sGkLj1bRao4AzFJuTvY5IduDRUIkKup5pr5NxjZ0QPnw== dependencies: core-js "^3.38.1" fflate "^0.4.8" From 3059c77b25b76044e849a6006d79553d0cd913f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Mon, 3 Feb 2025 12:56:25 +0100 Subject: [PATCH 43/56] Test commit --- .../src/components/inputs/InputSetupWizard/Wizard.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx index ae4ab32cb097..b1186d3250bc 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx @@ -134,4 +134,5 @@ const Wizard = ({ show, input, onClose }: Props) => { ); }; +// test commit export default Wizard; From 7413515d3d209a6d871d50afe7c7382674a27305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Mon, 3 Feb 2025 13:01:44 +0100 Subject: [PATCH 44/56] Undo test commit --- .../src/components/inputs/InputSetupWizard/Wizard.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx index b1186d3250bc..ae4ab32cb097 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/Wizard.tsx @@ -134,5 +134,4 @@ const Wizard = ({ show, input, onClose }: Props) => { ); }; -// test commit export default Wizard; From 304fea387935755aed46df31f33b53bf70ba3a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Mon, 3 Feb 2025 13:24:00 +0100 Subject: [PATCH 45/56] Fix test --- .../inputs/InputSetupWizard/InputSetupWizard.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.test.tsx b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.test.tsx index 812dea79916c..5c7656612858 100644 --- a/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputSetupWizard/InputSetupWizard.test.tsx @@ -74,7 +74,7 @@ describe('InputSetupWizard', () => { it('should render the wizard and shows routing step as first step', async () => { renderWizard(); - const wizard = await screen.findByText('Setup Routing'); + const wizard = await screen.findByText('Routing'); expect(wizard).toBeInTheDocument(); }); From 8856b5ffd52616fe0b3a6cf61da636a7fb6a03cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Bergenthal-Grotl=C3=BCschen?= Date: Mon, 3 Feb 2025 13:35:27 +0100 Subject: [PATCH 46/56] Fix reviewbot issue --- .../src/components/configurationforms/ListField.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graylog2-web-interface/src/components/configurationforms/ListField.tsx b/graylog2-web-interface/src/components/configurationforms/ListField.tsx index 7f6e5474c382..1b8211ae6313 100644 --- a/graylog2-web-interface/src/components/configurationforms/ListField.tsx +++ b/graylog2-web-interface/src/components/configurationforms/ListField.tsx @@ -31,7 +31,7 @@ type Props = { value?: Array | string }; -const ListField = ({ autoFocus = false, field, onChange, title, typeName, value }: Props) => { +const ListField = ({ autoFocus = false, field, onChange, title, typeName, value = undefined }: Props) => { const handleChange = (nextValue) => { const values = (nextValue === '' ? [] : nextValue.split(',')); From 5f83831f6377f85461b1b54bbef5cbc1e653f03d Mon Sep 17 00:00:00 2001 From: Othello Maurer Date: Mon, 3 Feb 2025 13:49:19 +0100 Subject: [PATCH 47/56] Upgrade Mongojack to version 5.0.2 (#21493) * Gracefully remove DBQuery usages * Replace remaining usages of deprecated MongoJack API * Fix DBJobTriggerServiceTest * Update MongoJack to 5.0.2 * Remove unused fields from MongoUtils * Add upgrade notes * add changelog * Improve readability when creating a projection --- UPGRADING.md | 16 +- changelog/unreleased/pr-21493.toml | 4 + .../scheduler/DBJobDefinitionService.java | 7 - .../scheduler/DBJobTriggerService.java | 26 - .../graylog2/database/MongoCollections.java | 2 +- .../graylog2/database/PaginatedDbService.java | 335 -------- .../jackson/legacy/LegacyDeleteResult.java | 49 -- .../legacy/LegacyInsertManyResult.java | 86 --- .../jackson/legacy/LegacyInsertOneResult.java | 71 -- .../jackson/legacy/LegacyUpdateOneResult.java | 96 --- .../jackson/legacy/LegacyUpdateResult.java | 55 -- .../database/jackson/legacy/package-info.java | 24 - .../graylog2/database/utils/MongoUtils.java | 34 +- .../indexer/indexset/IndexSetService.java | 8 +- .../indexset/MongoIndexSetService.java | 8 +- ...0705071400_AddEventIndexSetsMigration.java | 15 +- .../V20230210102500_UniqueUserMigration.java | 13 +- .../java/org/graylog2/search/SearchQuery.java | 33 - .../graylog2/search/SearchQueryOperator.java | 32 - .../graylog2/streams/StreamServiceImpl.java | 9 +- .../activities/SystemMessageServiceImpl.java | 25 +- .../src/main/java/org/mongojack/DBCursor.java | 118 --- .../org/mongojack/JacksonDBCollection.java | 392 ---------- .../main/java/org/mongojack/WriteResult.java | 81 -- .../main/java/org/mongojack/package-info.java | 24 - .../scheduler/DBJobTriggerServiceTest.java | 16 +- .../database/PaginatedDbServiceTest.java | 301 -------- .../indexset/MongoIndexSetServiceTest.java | 14 +- .../search/SearchQueryOperatorTest.java | 2 +- .../search/SearchQueryParserTest.java | 60 +- .../mongojack/JacksonDBCollectionTest.java | 727 ------------------ .../java/org/mongojack/WriteResultTest.java | 36 - pom.xml | 2 +- 33 files changed, 100 insertions(+), 2621 deletions(-) create mode 100644 changelog/unreleased/pr-21493.toml delete mode 100644 graylog2-server/src/main/java/org/graylog2/database/PaginatedDbService.java delete mode 100644 graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyDeleteResult.java delete mode 100644 graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertManyResult.java delete mode 100644 graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertOneResult.java delete mode 100644 graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateOneResult.java delete mode 100644 graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateResult.java delete mode 100644 graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/package-info.java delete mode 100644 graylog2-server/src/main/java/org/mongojack/DBCursor.java delete mode 100644 graylog2-server/src/main/java/org/mongojack/JacksonDBCollection.java delete mode 100644 graylog2-server/src/main/java/org/mongojack/WriteResult.java delete mode 100644 graylog2-server/src/main/java/org/mongojack/package-info.java delete mode 100644 graylog2-server/src/test/java/org/graylog2/database/PaginatedDbServiceTest.java delete mode 100644 graylog2-server/src/test/java/org/mongojack/JacksonDBCollectionTest.java delete mode 100644 graylog2-server/src/test/java/org/mongojack/WriteResultTest.java diff --git a/UPGRADING.md b/UPGRADING.md index 0ded98b49637..dc077af9d35d 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -4,10 +4,11 @@ Upgrading to Graylog 6.2.x ## Breaking Changes ### Plugins - -Adjustment of `enterpriseWidgets` web interface plugin. The `editComponent` attribute now no longer has a `onSubmit` prop. -Before this change the prop had to be called to close the widget edit mode. Now it is enough to call `applyAllWidgetChanges` from the `WidgetEditApplyAllChangesContext`. -Alternatively the `SaveOrCancelButtons` component can be used in the edit component for custom widgets. It renders a cancel and submit button and calls `applyAllWidgetChanges` on submit. +* This release includes Java API changes which might require plugin authors to adjust their code. Please check + [Java API Changes](#java-api-changes) for details. +* Adjustment of `enterpriseWidgets` web interface plugin. The `editComponent` attribute now no longer has a `onSubmit` prop. + Before this change the prop had to be called to close the widget edit mode. Now it is enough to call `applyAllWidgetChanges` from the `WidgetEditApplyAllChangesContext`. + Alternatively the `SaveOrCancelButtons` component can be used in the edit component for custom widgets. It renders a cancel and submit button and calls `applyAllWidgetChanges` on submit. ## Configuration File Changes @@ -21,7 +22,12 @@ Alternatively the `SaveOrCancelButtons` component can be used in the edit compon ## Java API Changes -The following Java Code API changes have been made. +Upgraded [MongoJack](https://github.com/mongojack/mongojack) to version 5.x. This impacts the Java API for accessing +documents in MongoDB. Some previously deprecated MongoJack classes (like `org.mongojack.DBQuery`) have been removed. +Plugin authors will have to replace usages of removed classes to corresponding classes from the MongoDB driver +packages, most prominently `com.mongodb.client.model.Filters`. + +Additionally, the following Java Code API changes are included in this release: | File/method | Description | |------------------------------------------------|-------------| diff --git a/changelog/unreleased/pr-21493.toml b/changelog/unreleased/pr-21493.toml new file mode 100644 index 000000000000..54ecb04b1e7b --- /dev/null +++ b/changelog/unreleased/pr-21493.toml @@ -0,0 +1,4 @@ +type = "c" +message = "Upgraded MongoJack dependency to `5.0.2`. This might require changes to third-party plugins. Please check Graylog upgrade notes." + +pulls = ["21493"] diff --git a/graylog2-server/src/main/java/org/graylog/scheduler/DBJobDefinitionService.java b/graylog2-server/src/main/java/org/graylog/scheduler/DBJobDefinitionService.java index bd90c6c43538..55730ac56a25 100644 --- a/graylog2-server/src/main/java/org/graylog/scheduler/DBJobDefinitionService.java +++ b/graylog2-server/src/main/java/org/graylog/scheduler/DBJobDefinitionService.java @@ -26,7 +26,6 @@ import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; import org.graylog2.database.MongoCollections; import org.graylog2.database.utils.MongoUtils; -import org.mongojack.DBQuery; import java.util.ArrayList; import java.util.Collection; @@ -78,12 +77,6 @@ private static Bson buildConfigFieldQuery(String configField, Object value) { return Filters.eq(field, value); } - @Deprecated - public List getByQuery(DBQuery.Query query) { - mongoUtils.initializeLegacyMongoJackBsonObject(query); - return getByQuery((Bson) query); - } - public List getByQuery(Bson query) { return collection.find(query).into(new ArrayList<>()); } diff --git a/graylog2-server/src/main/java/org/graylog/scheduler/DBJobTriggerService.java b/graylog2-server/src/main/java/org/graylog/scheduler/DBJobTriggerService.java index 79ace11f2ec4..863e9d9f87a9 100644 --- a/graylog2-server/src/main/java/org/graylog/scheduler/DBJobTriggerService.java +++ b/graylog2-server/src/main/java/org/graylog/scheduler/DBJobTriggerService.java @@ -41,7 +41,6 @@ import org.graylog2.database.utils.MongoUtils; import org.graylog2.plugin.system.NodeId; import org.joda.time.DateTime; -import org.mongojack.DBQuery; import java.util.ArrayList; import java.util.Collection; @@ -335,22 +334,10 @@ public int deleteByQuery(Bson query) { return Ints.saturatedCast(collection.deleteMany(query).getDeletedCount()); } - @Deprecated - public int deleteByQuery(DBQuery.Query query) { - mongoUtils.initializeLegacyMongoJackBsonObject(query); - return deleteByQuery((Bson) query); - } - public long countByQuery(Bson query) { return collection.countDocuments(query); } - @Deprecated - public long countByQuery(DBQuery.Query query) { - mongoUtils.initializeLegacyMongoJackBsonObject(query); - return countByQuery((Bson) query); - } - /** * Locks and returns the next runnable trigger. The caller needs to take care of releasing the trigger lock. * @@ -545,13 +532,6 @@ public Optional cancelTriggerByQuery(Bson query) { return Optional.ofNullable(collection.findOneAndUpdate(query, update)); } - @Deprecated - public Optional cancelTriggerByQuery(DBQuery.Query query) { - mongoUtils.initializeLegacyMongoJackBsonObject(query); - return cancelTriggerByQuery((Bson) query); - } - - /** * Find triggers by using the provided query. Use judiciously! * @@ -562,12 +542,6 @@ public List findByQuery(Bson query) { return stream(collection.find(query).sort(descending(FIELD_UPDATED_AT))).toList(); } - @Deprecated - public List findByQuery(DBQuery.Query query) { - mongoUtils.initializeLegacyMongoJackBsonObject(query); - return findByQuery((Bson) query); - } - private record OverdueTrigger(@JsonProperty("_id") String type, @JsonProperty("count") long count) {} /** diff --git a/graylog2-server/src/main/java/org/graylog2/database/MongoCollections.java b/graylog2-server/src/main/java/org/graylog2/database/MongoCollections.java index 8b052af14575..de94fa53b599 100644 --- a/graylog2-server/src/main/java/org/graylog2/database/MongoCollections.java +++ b/graylog2-server/src/main/java/org/graylog2/database/MongoCollections.java @@ -103,7 +103,7 @@ public MongoUtils utils(String collectionName, Class< * Provides utility methods like getting documents by ID, etc. */ public MongoUtils utils(MongoCollection collection) { - return new MongoUtils<>(collection, objectMapper); + return new MongoUtils<>(collection); } /** diff --git a/graylog2-server/src/main/java/org/graylog2/database/PaginatedDbService.java b/graylog2-server/src/main/java/org/graylog2/database/PaginatedDbService.java deleted file mode 100644 index 26772aad4237..000000000000 --- a/graylog2-server/src/main/java/org/graylog2/database/PaginatedDbService.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.graylog2.database; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Streams; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.model.Sorts; -import org.bson.conversions.Bson; -import org.bson.types.ObjectId; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.mongojack.DBCursor; -import org.mongojack.DBQuery; -import org.mongojack.DBSort; -import org.mongojack.JacksonDBCollection; -import org.mongojack.WriteResult; - -import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * This class is a helper to implement a basic Mongojack-based database service that allows CRUD operations on a - * single DTO type and offers paginated access. - *

    - * It makes only a few assumptions, which are common to many Graylog entities: - *

      - *
    • The DTO class has a name which is unique
    • - *
    - *

    - *

    - * Subclasses can add more sophisticated query methods by access the protected "db" property.
    - * Indices can be added in the constructor. - *

    - * - * @param - * @deprecated Do not implement services based on this class anymore. Instead, use - * {@link MongoCollections#collection(String, Class)}, {@link MongoCollections#paginationHelper(MongoCollection)}, and - * {@link MongoCollections#utils(MongoCollection)} to implement common data access patterns. - */ -@Deprecated(since = "6.2.0", forRemoval = true) -public abstract class PaginatedDbService { - protected final JacksonDBCollection db; - - protected PaginatedDbService(MongoConnection mongoConnection, - MongoJackObjectMapperProvider mapper, - Class dtoClass, - String collectionName) { - this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection(collectionName), - dtoClass, - ObjectId.class, - mapper.get()); - } - - protected PaginatedDbService(MongoConnection mongoConnection, - MongoJackObjectMapperProvider mapper, - Class dtoClass, - String collectionName, - @Nullable DBObject dbOptions) { - DBCollection dbCollection; - if (!mongoConnection.getDatabase().collectionExists(collectionName)) { - dbCollection = mongoConnection.getDatabase().createCollection(collectionName, dbOptions); - } else { - dbCollection = mongoConnection.getDatabase().getCollection(collectionName); - } - - this.db = JacksonDBCollection.wrap(dbCollection, - dtoClass, - ObjectId.class, - mapper.get()); - } - - /** - * Get the {@link DTO} for the given ID. - * - * @param id the ID of the object - * @return an Optional containing the found object or an empty Optional if no object can be found for the given ID - */ - public Optional get(String id) { - return Optional.ofNullable(db.findOneById(new ObjectId(id))); - } - - /** - * Stores the given {@link DTO} in the database. - * - * @param dto the {@link DTO} to save - * @return the newly saved {@link DTO} - */ - public DTO save(DTO dto) { - final WriteResult save = db.save(dto); - return save.getSavedObject(); - } - - /** - * Deletes the {@link DTO} for the given ID from the database. - * - * @param id ID of the {@link DTO} to delete - * @return the number of deleted documents - */ - public int delete(String id) { - return db.removeById(new ObjectId(id)).getN(); - } - - /** - * Returns a {@link PaginatedList} for the given query and pagination parameters. - *

    - * This method is only accessible by subclasses to avoid exposure of the {@link DBQuery} and {@link DBSort} - * interfaces to consumers. - * - * @param query the query to execute - * @param sort the sort builder for the query - * @param page the page number that should be returned - * @param perPage the number of entries per page, 0 is unlimited - * @return the paginated list - */ - protected PaginatedList findPaginatedWithQueryAndSort(Bson query, Bson sort, int page, int perPage) { - try (final DBCursor cursor = db.find(query) - .sort(sort) - .limit(perPage) - .skip(perPage * Math.max(0, page - 1))) { - final long grandTotal = db.count(); - return new PaginatedList<>(asImmutableList(cursor), cursor.count(), page, perPage, grandTotal); - } - } - - protected ImmutableList asImmutableList(Iterator cursor) { - return ImmutableList.copyOf(cursor); - } - - /** - * Returns a {@link PaginatedList} for the given query, filter and pagination parameters. - *

    - * Since the database cannot execute the filter function directly, this method streams over the result cursor - * and executes the filter function for each database object. This increases memory consumption and should only be - * used if necessary. Use the - * {@link PaginatedDbService#findPaginatedWithQueryFilterAndSort(Bson, Predicate, Bson, int, int) #findPaginatedWithQueryAndSort()} - * method if possible. - *

    - * This method is only accessible by subclasses to avoid exposure of the query and sort - * interfaces to consumers. - * - * @param query the query to execute - * @param filter the filter to apply to each database entry - * @param sort the sort builder for the query - * @param page the page number that should be returned - * @param perPage the number of entries per page, 0 is unlimited - * @return the paginated list - */ - protected PaginatedList findPaginatedWithQueryFilterAndSort(Bson query, - Predicate filter, - Bson sort, - int page, - int perPage) { - return findPaginatedWithQueryFilterAndSortWithGrandTotal( - query, - filter, - sort, - DBQuery.empty(), - page, - perPage); - } - - - protected PaginatedList findPaginatedWithQueryFilterAndSortWithGrandTotal(Bson query, - Predicate filter, - Bson sort, - Bson grandTotalQuery, - int page, - int perPage) { - // Calculate the total amount of items matching the query/filter, but before pagination - final long total; - try (final Stream cursor = streamQueryWithSort(query, sort)) { - total = cursor.filter(filter).count(); - } - - // Then create another filtered stream and only collect the entries according to page and perPage - try (final Stream resultStream = streamQueryWithSort(query, sort)) { - Stream filteredResultStream = resultStream.filter(filter); - if (perPage > 0) { - filteredResultStream = filteredResultStream.skip(perPage * Math.max(0, page - 1)).limit(perPage); - } - - final long grandTotal = db.getCount(grandTotalQuery); - - return new PaginatedList<>(filteredResultStream.collect(Collectors.toList()), Math.toIntExact(total), page, perPage, grandTotal); - } - } - - /** - * Returns an unordered stream of all entries in the database. - *

    - * The returned stream needs to be closed to free the underlying database resources. - * - * @return stream of all database entries - */ - public Stream streamAll() { - return streamQuery(DBQuery.empty()); - } - - /** - * Returns an unordered stream of all entries in the database for the given IDs. - *

    - * The returned stream needs to be closed to free the underlying database resources. - * - * @param idSet set of IDs to query - * @return stream of database entries for the given IDs - */ - public Stream streamByIds(Set idSet) { - final List objectIds = idSet.stream() - .map(ObjectId::new) - .collect(Collectors.toList()); - - return streamQuery(DBQuery.in("_id", objectIds)); - } - - /** - * Returns an unordered stream of database entries for the given {@link DBQuery.Query}. - *

    - * The returned stream needs to be closed to free the underlying database resources. - * - * @param query the query to execute - * @return stream of database entries that match the query - */ - protected Stream streamQuery(Bson query) { - final DBCursor cursor = db.find(query); - return Streams.stream((Iterable) cursor).onClose(cursor::close); - } - - /** - * Returns a stream of database entries for the given {@link DBQuery.Query} sorted by the give {@link DBSort.SortBuilder}. - *

    - * The returned stream needs to be closed to free the underlying database resources. - * - * @param query the query to execute - * @param sort the sort order for the query - * @return stream of database entries that match the query - */ - protected Stream streamQueryWithSort(Bson query, Bson sort) { - final DBCursor cursor = db.find(query).sort(sort); - return Streams.stream((Iterable) cursor).onClose(cursor::close); - } - - /** - * Returns a sort builder for the given order and field name. - * - * @param order the order. either "asc" or "desc" - * @param field the field to sort on - * @return the sort builder - * @deprecated {@link DBSort} is deprecated. Consider using {@link Sorts} instead. - */ - @Deprecated - protected DBSort.SortBuilder getSortBuilder(String order, String field) { - DBSort.SortBuilder sortBuilder; - if ("desc".equalsIgnoreCase(order)) { - sortBuilder = DBSort.desc(field); - } else { - sortBuilder = DBSort.asc(field); - } - return sortBuilder; - } - - /** - * @deprecated {@link DBSort} is deprecated. Consider using {@link Sorts} instead. - */ - protected DBSort.SortBuilder getMultiFieldSortBuilder(String order, List fields) { - if (fields == null || fields.isEmpty()) { - return DBSort.asc("_id"); - } - final List distinctFields = fields.stream().distinct().toList(); - DBSort.SortBuilder sortBuilder = null; - if ("desc".equalsIgnoreCase(order)) { - for (String field : distinctFields) { - if (sortBuilder == null) { - sortBuilder = DBSort.desc(field); - } else { - sortBuilder = sortBuilder.desc(field); - } - } - } else { - for (String field : distinctFields) { - if (sortBuilder == null) { - sortBuilder = DBSort.asc(field); - } else { - sortBuilder = sortBuilder.asc(field); - } - } - } - return sortBuilder; - } - - /** - * Utility method to use, if you can't page it inside of MongoDB - * - * @param sourceList - * @param page - * @param pageSize - * @param - * @return - */ - public static List getPage(List sourceList, int page, int pageSize) { - if (pageSize <= 0 || page <= 0) { - throw new IllegalArgumentException("invalid page size: " + pageSize); - } - - int fromIndex = (page - 1) * pageSize; - if (sourceList == null || sourceList.size() <= fromIndex) { - return Collections.emptyList(); - } - - // toIndex exclusive - return sourceList.subList(fromIndex, Math.min(fromIndex + pageSize, sourceList.size())); - } -} diff --git a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyDeleteResult.java b/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyDeleteResult.java deleted file mode 100644 index b08c544b70a9..000000000000 --- a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyDeleteResult.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.graylog2.database.jackson.legacy; - -import com.google.common.primitives.Ints; -import com.mongodb.client.result.DeleteResult; -import org.mongojack.WriteResult; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -public class LegacyDeleteResult implements WriteResult { - private final DeleteResult deleteResult; - - public LegacyDeleteResult(DeleteResult deleteResult) { - this.deleteResult = deleteResult; - } - - @Override - public int getN() { - return Ints.saturatedCast(deleteResult.getDeletedCount()); - } - - @Override - public boolean wasAcknowledged() { - return deleteResult.wasAcknowledged(); - } - - @Override - public boolean isUpdateOfExisting() { - return false; - } -} diff --git a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertManyResult.java b/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertManyResult.java deleted file mode 100644 index bccfc323deed..000000000000 --- a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertManyResult.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.graylog2.database.jackson.legacy; - -import com.mongodb.MongoException; -import com.mongodb.ReadPreference; -import com.mongodb.client.result.InsertManyResult; -import org.bson.BsonValue; -import org.mongojack.JacksonMongoCollection; -import org.mongojack.WriteResult; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -@Deprecated -public class LegacyInsertManyResult implements WriteResult { - private final JacksonMongoCollection collection; - private final InsertManyResult insertOneResult; - private final Class idType; - - public LegacyInsertManyResult(JacksonMongoCollection collection, InsertManyResult insertManyResult, - Class idType) { - this.collection = collection.withReadPreference(ReadPreference.primary()); - this.insertOneResult = insertManyResult; - this.idType = idType; - } - - @Override - public T getSavedObject() { - final BsonValue firstId = getFirstId(); - - if (firstId != null) { - final T item = collection.findOneById(firstId); - if (item != null) { - return item; - } - } - - throw new MongoException("No objects to return"); - } - - @Override - public int getN() { - return 0; - } - - @Override - public boolean wasAcknowledged() { - return insertOneResult.wasAcknowledged(); - } - - @Override - public K getSavedId() { - final BsonValue firstId = getFirstId(); - - if (firstId != null) { - return WriteResult.toIdType(firstId, idType); - } - throw new MongoException("No objects to return"); - } - - @Override - public boolean isUpdateOfExisting() { - return false; - } - - private BsonValue getFirstId() { - return insertOneResult.getInsertedIds().get(0); - } -} diff --git a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertOneResult.java b/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertOneResult.java deleted file mode 100644 index 364fbdf5ae23..000000000000 --- a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyInsertOneResult.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.graylog2.database.jackson.legacy; - -import com.mongodb.ReadPreference; -import com.mongodb.client.result.InsertOneResult; -import org.bson.BsonValue; -import org.mongojack.JacksonMongoCollection; -import org.mongojack.WriteResult; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -@Deprecated -public class LegacyInsertOneResult implements WriteResult { - private final JacksonMongoCollection collection; - private final InsertOneResult insertOneResult; - private final Class idType; - - public LegacyInsertOneResult(JacksonMongoCollection collection, InsertOneResult insertOneResult, - Class idType) { - this.collection = collection.withReadPreference(ReadPreference.primary()); - this.insertOneResult = insertOneResult; - this.idType = idType; - } - - @Override - public T getSavedObject() { - final BsonValue insertedId = insertOneResult.getInsertedId(); - if (insertedId == null) { - return null; - } - return collection.findOneById(insertedId); - } - - @Override - public int getN() { - return 0; - } - - @Override - public boolean wasAcknowledged() { - return insertOneResult.wasAcknowledged(); - } - - @Override - public K getSavedId() { - return WriteResult.toIdType(insertOneResult.getInsertedId(), idType); - } - - @Override - public boolean isUpdateOfExisting() { - return false; - } -} diff --git a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateOneResult.java b/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateOneResult.java deleted file mode 100644 index bde63fddfeec..000000000000 --- a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateOneResult.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.graylog2.database.jackson.legacy; - -import com.google.common.primitives.Ints; -import com.mongodb.MongoException; -import com.mongodb.ReadPreference; -import com.mongodb.client.result.UpdateResult; -import org.bson.BsonValue; -import org.bson.codecs.CollectibleCodec; -import org.mongojack.JacksonMongoCollection; -import org.mongojack.WriteResult; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -@Deprecated -public class LegacyUpdateOneResult implements WriteResult { - protected final JacksonMongoCollection collection; - private final T object; - private final UpdateResult updateResult; - private final Class valueType; - private final Class idType; - - public LegacyUpdateOneResult(JacksonMongoCollection collection, T object, UpdateResult updateResult, Class valueType, Class idType) { - this.collection = collection.withReadPreference(ReadPreference.primary()); - this.object = object; - this.updateResult = updateResult; - this.valueType = valueType; - this.idType = idType; - } - - @Override - public T getSavedObject() { - if (!wasSaved()) { - throw new MongoException("No objects to return"); - } - return collection.findOneById(getId()); - } - - @Override - public K getSavedId() { - if (!wasSaved()) { - throw new MongoException("No objects to return"); - } - return WriteResult.toIdType(getId(), idType); - } - - @Override - public int getN() { - return (updateResult.getUpsertedId() != null) ? 1 : Ints.saturatedCast(updateResult.getMatchedCount()); - } - - @Override - public boolean wasAcknowledged() { - return updateResult.wasAcknowledged(); - } - - @Override - public Object getUpsertedId() { - return WriteResult.extractValue(updateResult.getUpsertedId()); - } - - @Override - public boolean isUpdateOfExisting() { - return updateResult.getMatchedCount() > 0; - } - - private BsonValue getId() { - if (updateResult.getUpsertedId() != null) { - return updateResult.getUpsertedId(); - } - final CollectibleCodec codec = (CollectibleCodec) collection.getCodecRegistry().get(valueType); - return codec.getDocumentId(object); - } - - private boolean wasSaved() { - return updateResult.getUpsertedId() != null || updateResult.getMatchedCount() > 0; - } -} diff --git a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateResult.java b/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateResult.java deleted file mode 100644 index 56afa9e22bf5..000000000000 --- a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/LegacyUpdateResult.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.graylog2.database.jackson.legacy; - -import com.google.common.primitives.Ints; -import com.mongodb.client.result.UpdateResult; -import org.mongojack.WriteResult; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -@Deprecated -public class LegacyUpdateResult implements WriteResult { - private final UpdateResult updateResult; - - public LegacyUpdateResult(UpdateResult updateResult) { - this.updateResult = updateResult; - } - - @Override - public int getN() { - return (getUpsertedId() != null) ? 1 : Ints.saturatedCast(updateResult.getMatchedCount()); - } - - @Override - public boolean wasAcknowledged() { - return updateResult.wasAcknowledged(); - } - - @Override - public Object getUpsertedId() { - return WriteResult.extractValue(updateResult.getUpsertedId()); - } - - @Override - public boolean isUpdateOfExisting() { - return updateResult.getMatchedCount() > 0; - } -} diff --git a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/package-info.java b/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/package-info.java deleted file mode 100644 index 789cff244917..000000000000 --- a/graylog2-server/src/main/java/org/graylog2/database/jackson/legacy/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -/** - * This package contains a compatibility layer to support old code using the Mongojack 2.x API. It is destined for - * removal as soon as all code has been migrated to use the MongoDB driver API directly. - *

    - * Instead of the classes from this package, use {@link org.graylog2.database.MongoCollections} as an entrypoint for - * interacting with MongoDB. - */ -package org.graylog2.database.jackson.legacy; diff --git a/graylog2-server/src/main/java/org/graylog2/database/utils/MongoUtils.java b/graylog2-server/src/main/java/org/graylog2/database/utils/MongoUtils.java index dfaaa72f2e80..bdb45e5b111f 100644 --- a/graylog2-server/src/main/java/org/graylog2/database/utils/MongoUtils.java +++ b/graylog2-server/src/main/java/org/graylog2/database/utils/MongoUtils.java @@ -16,7 +16,6 @@ */ package org.graylog2.database.utils; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Streams; import com.mongodb.ErrorCategory; import com.mongodb.MongoException; @@ -37,8 +36,6 @@ import org.bson.types.ObjectId; import org.graylog2.database.BuildableMongoEntity; import org.graylog2.database.MongoEntity; -import org.graylog2.database.jackson.CustomJacksonCodecRegistry; -import org.mongojack.InitializationRequiredForTransformation; import java.util.Collection; import java.util.Optional; @@ -55,16 +52,9 @@ */ public class MongoUtils { private final MongoCollection collection; - private final ObjectMapper objectMapper; - private final CustomJacksonCodecRegistry codecRegistry; - public MongoUtils(MongoCollection delegate, ObjectMapper objectMapper) { + public MongoUtils(MongoCollection delegate) { this.collection = delegate; - this.objectMapper = objectMapper; - - codecRegistry = new CustomJacksonCodecRegistry( - objectMapper, - collection.getCodecRegistry()); } /** @@ -254,7 +244,7 @@ public T getOrCreate(T entity) { * Saves an entity by either inserting or replacing the document. *

    * This method exists to avoid the repeated implementation of this functionality during migration from the old - * Mongojack API. + * MongoJack API. *

    * For new code, prefer implementing a separate "create" and "update" path instead. * @@ -273,24 +263,4 @@ public T save(BuildableMongoEntity entity) { return orig; } } - - /** - * Utility method to help moving away from the deprecated MongoJack Bson objects, like - * {@link org.mongojack.DBQuery.Query}. These objects require initialization before they can be used as regular - * {@link org.bson.conversions.Bson} objects with the MongoDB driver. - *

    - * The {@link org.mongojack.JacksonMongoCollection} would usually take care of that, but because we cannot use it, - * and instead use a regular {@link org.mongojack.MongoCollection}, we have to use this method. - * - * @deprecated This method is only meant as an interim solution. Rewrite your deprecated MongoJack objects so that - * you don't have to use it. - */ - @Deprecated - public void initializeLegacyMongoJackBsonObject(InitializationRequiredForTransformation mongoJackBsonObject) { - mongoJackBsonObject.initialize( - objectMapper, - objectMapper.constructType(collection.getDocumentClass()), - codecRegistry); - } - } diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/indexset/IndexSetService.java b/graylog2-server/src/main/java/org/graylog2/indexer/indexset/IndexSetService.java index d6c6773b32a1..56fa170cb058 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/indexset/IndexSetService.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/indexset/IndexSetService.java @@ -16,8 +16,8 @@ */ package org.graylog2.indexer.indexset; +import org.bson.conversions.Bson; import org.bson.types.ObjectId; -import org.mongojack.DBQuery; import java.util.List; import java.util.Optional; @@ -47,11 +47,11 @@ public interface IndexSetService { IndexSetConfig getDefault(); /** - * Retrieve an index set based on the given {@link DBQuery.Query}. + * Retrieve an index set based on the given MongoDB query. * * @return index set */ - Optional findOne(DBQuery.Query query); + Optional findOne(Bson query); /** * Retrieve all index sets. @@ -67,7 +67,7 @@ public interface IndexSetService { */ List findByIds(Set ids); - List findMany(DBQuery.Query query); + List findMany(Bson query); /** * Retrieve a paginated set of index set. diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/indexset/MongoIndexSetService.java b/graylog2-server/src/main/java/org/graylog2/indexer/indexset/MongoIndexSetService.java index eaeeb5aa9b56..7572672ba83e 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/indexset/MongoIndexSetService.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/indexset/MongoIndexSetService.java @@ -27,6 +27,7 @@ import com.mongodb.client.model.Updates; import com.mongodb.client.result.InsertOneResult; import jakarta.inject.Inject; +import org.bson.conversions.Bson; import org.bson.types.ObjectId; import org.graylog2.database.MongoCollections; import org.graylog2.database.utils.MongoUtils; @@ -35,7 +36,6 @@ import org.graylog2.indexer.indexset.events.IndexSetDeletedEvent; import org.graylog2.plugin.cluster.ClusterConfigService; import org.graylog2.streams.StreamService; -import org.mongojack.DBQuery; import java.util.ArrayList; import java.util.List; @@ -107,8 +107,7 @@ public IndexSetConfig getDefault() { * {@inheritDoc} */ @Override - public Optional findOne(DBQuery.Query query) { - mongoUtils.initializeLegacyMongoJackBsonObject(query); + public Optional findOne(Bson query) { return Optional.ofNullable(collection.find(query).first()); } @@ -126,8 +125,7 @@ public List findByIds(Set ids) { } @Override - public List findMany(DBQuery.Query query) { - mongoUtils.initializeLegacyMongoJackBsonObject(query); + public List findMany(Bson query) { return ImmutableList.copyOf(collection.find(query).sort(Sorts.ascending(FIELD_TITLE))); } diff --git a/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java b/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java index 113bdb6eeecc..fd8c7c871ec0 100644 --- a/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java +++ b/graylog2-server/src/main/java/org/graylog2/migrations/V20190705071400_AddEventIndexSetsMigration.java @@ -19,7 +19,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.mongodb.MongoException; +import com.mongodb.client.model.Filters; import jakarta.inject.Inject; +import org.bson.conversions.Bson; import org.bson.types.ObjectId; import org.graylog.events.notifications.EventNotificationSettings; import org.graylog.events.processor.DBEventDefinitionService; @@ -42,7 +44,6 @@ import org.graylog2.streams.StreamService; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.mongojack.DBQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -131,9 +132,9 @@ private void ensureEventsStreamAndIndexSet(String indexSetTitle, } private void checkIndexPrefixConflicts(String indexPrefix, String configKey) { - final DBQuery.Query query = DBQuery.and( - DBQuery.notEquals(FIELD_INDEX_TEMPLATE_TYPE, Optional.of(EVENT_TEMPLATE_TYPE)), - DBQuery.is(FIELD_INDEX_PREFIX, indexPrefix) + final Bson query = Filters.and( + Filters.ne(FIELD_INDEX_TEMPLATE_TYPE, Optional.of(EVENT_TEMPLATE_TYPE)), + Filters.eq(FIELD_INDEX_PREFIX, indexPrefix) ); if (indexSetService.findOne(query).isPresent()) { @@ -144,9 +145,9 @@ private void checkIndexPrefixConflicts(String indexPrefix, String configKey) { } private Optional getEventsIndexSetConfig(String indexPrefix) { - final DBQuery.Query query = DBQuery.and( - DBQuery.is(FIELD_INDEX_TEMPLATE_TYPE, Optional.of(EVENT_TEMPLATE_TYPE)), - DBQuery.is(FIELD_INDEX_PREFIX, indexPrefix) + final Bson query = Filters.and( + Filters.eq(FIELD_INDEX_TEMPLATE_TYPE, Optional.of(EVENT_TEMPLATE_TYPE)), + Filters.eq(FIELD_INDEX_PREFIX, indexPrefix) ); return indexSetService.findOne(query); } diff --git a/graylog2-server/src/main/java/org/graylog2/migrations/V20230210102500_UniqueUserMigration.java b/graylog2-server/src/main/java/org/graylog2/migrations/V20230210102500_UniqueUserMigration.java index cbbf279107a1..b160fc56d934 100644 --- a/graylog2-server/src/main/java/org/graylog2/migrations/V20230210102500_UniqueUserMigration.java +++ b/graylog2-server/src/main/java/org/graylog2/migrations/V20230210102500_UniqueUserMigration.java @@ -16,12 +16,13 @@ */ package org.graylog2.migrations; -import com.mongodb.DBCollection; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.IndexOptions; +import com.mongodb.client.model.Indexes; +import jakarta.inject.Inject; +import org.bson.Document; import org.graylog2.database.MongoConnection; import org.graylog2.users.UserImpl; -import org.mongojack.DBSort; - -import jakarta.inject.Inject; import java.time.ZonedDateTime; @@ -40,9 +41,9 @@ public ZonedDateTime createdAt() { @Override public void upgrade() { - DBCollection coll = mongoConnection.getDatabase().getCollection(UserImpl.COLLECTION_NAME); + MongoCollection coll = mongoConnection.getMongoDatabase().getCollection(UserImpl.COLLECTION_NAME); // NOOP, if index already exists - coll.createIndex(DBSort.asc(UserImpl.USERNAME), "unique_username", true); + coll.createIndex(Indexes.ascending(UserImpl.USERNAME), new IndexOptions().name("unique_username").unique(true)); } } diff --git a/graylog2-server/src/main/java/org/graylog2/search/SearchQuery.java b/graylog2-server/src/main/java/org/graylog2/search/SearchQuery.java index 83b847e5d1d8..8b95d17bcb07 100644 --- a/graylog2-server/src/main/java/org/graylog2/search/SearchQuery.java +++ b/graylog2-server/src/main/java/org/graylog2/search/SearchQuery.java @@ -21,7 +21,6 @@ import com.mongodb.client.model.Filters; import org.bson.Document; import org.bson.conversions.Bson; -import org.mongojack.DBQuery; import java.util.ArrayList; import java.util.Collection; @@ -50,38 +49,6 @@ public Multimap getQueryMap() { return queryMap; } - public DBQuery.Query toDBQuery() { - if (queryMap.isEmpty()) { - return DBQuery.empty(); - } - - final List dbQueries = new ArrayList<>(); - - for (Map.Entry> entry : queryMap.asMap().entrySet()) { - final List queries = new ArrayList<>(); - - final List include = selectValues(entry.getValue(), value -> !value.isNegate()); - final List exclude = selectValues(entry.getValue(), SearchQueryParser.FieldValue::isNegate); - - if (!include.isEmpty()) { - queries.add(DBQuery.or(toQuery(entry.getKey(), include))); - } - if (!exclude.isEmpty()) { - queries.add(DBQuery.nor(toQuery(entry.getKey(), exclude))); - } - - dbQueries.add(DBQuery.and(queries.toArray(new DBQuery.Query[0]))); - } - - return DBQuery.and(dbQueries.toArray(new DBQuery.Query[0])); - } - - private DBQuery.Query[] toQuery(String field, List values) { - return values.stream() - .map(value -> value.getOperator().buildQuery(field, value.getValue())) - .toArray(DBQuery.Query[]::new); - } - public Bson toBson() { if (queryMap.isEmpty()) { return new Document(); diff --git a/graylog2-server/src/main/java/org/graylog2/search/SearchQueryOperator.java b/graylog2-server/src/main/java/org/graylog2/search/SearchQueryOperator.java index b78028d61ec6..9807dc954b72 100644 --- a/graylog2-server/src/main/java/org/graylog2/search/SearchQueryOperator.java +++ b/graylog2-server/src/main/java/org/graylog2/search/SearchQueryOperator.java @@ -18,14 +18,12 @@ import com.mongodb.client.model.Filters; import org.bson.conversions.Bson; -import org.mongojack.DBQuery; import java.util.regex.Pattern; import static java.util.regex.Pattern.CASE_INSENSITIVE; public abstract class SearchQueryOperator { - public abstract DBQuery.Query buildQuery(String key, Object value); public abstract Bson buildBson(String key, Object value); @Override @@ -34,11 +32,6 @@ public boolean equals(Object obj) { } public static class Equals extends SearchQueryOperator { - @Override - public DBQuery.Query buildQuery(String key, Object value) { - return DBQuery.is(key, value); - } - @Override public Bson buildBson(String key, Object value) { return Filters.eq(key, value); @@ -46,11 +39,6 @@ public Bson buildBson(String key, Object value) { } public static class Regexp extends SearchQueryOperator { - @Override - public DBQuery.Query buildQuery(String key, Object value) { - return DBQuery.regex(key, Pattern.compile(Pattern.quote(value.toString()), CASE_INSENSITIVE)); - } - @Override public Bson buildBson(String key, Object value) { return Filters.regex(key, Pattern.compile(Pattern.quote(value.toString()), CASE_INSENSITIVE)); @@ -58,11 +46,6 @@ public Bson buildBson(String key, Object value) { } public static class Greater extends SearchQueryOperator { - @Override - public DBQuery.Query buildQuery(String key, Object value) { - return DBQuery.greaterThan(key, value); - } - @Override public Bson buildBson(String key, Object value) { return Filters.gt(key, value); @@ -70,11 +53,6 @@ public Bson buildBson(String key, Object value) { } public static class GreaterEquals extends SearchQueryOperator { - @Override - public DBQuery.Query buildQuery(String key, Object value) { - return DBQuery.greaterThanEquals(key, value); - } - @Override public Bson buildBson(String key, Object value) { return Filters.gte(key, value); @@ -82,11 +60,6 @@ public Bson buildBson(String key, Object value) { } public static class Less extends SearchQueryOperator { - @Override - public DBQuery.Query buildQuery(String key, Object value) { - return DBQuery.lessThan(key, value); - } - @Override public Bson buildBson(String key, Object value) { return Filters.lt(key, value); @@ -94,11 +67,6 @@ public Bson buildBson(String key, Object value) { } public static class LessEquals extends SearchQueryOperator { - @Override - public DBQuery.Query buildQuery(String key, Object value) { - return DBQuery.lessThanEquals(key, value); - } - @Override public Bson buildBson(String key, Object value) { return Filters.lte(key, value); diff --git a/graylog2-server/src/main/java/org/graylog2/streams/StreamServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/streams/StreamServiceImpl.java index c74ed318946f..1989f8ead358 100644 --- a/graylog2-server/src/main/java/org/graylog2/streams/StreamServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/streams/StreamServiceImpl.java @@ -29,6 +29,7 @@ import com.mongodb.DBObject; import com.mongodb.QueryBuilder; import com.mongodb.WriteResult; +import com.mongodb.client.model.Projections; import jakarta.annotation.Nonnull; import jakarta.inject.Inject; import org.bson.types.ObjectId; @@ -50,7 +51,6 @@ import org.graylog2.rest.resources.streams.requests.CreateStreamRequest; import org.graylog2.streams.events.StreamDeletedEvent; import org.graylog2.streams.events.StreamsChangedEvent; -import org.mongojack.DBProjection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -322,9 +322,8 @@ public Set loadByIds(Collection streamIds) { @Override public Set mapCategoriesToIds(Collection categories) { final DBObject query = QueryBuilder.start(StreamImpl.FIELD_CATEGORIES).in(categories).get(); - final DBObject onlyIdField = DBProjection.include(FIELD_ID); - try (var cursor = collection(StreamImpl.class).find(query, onlyIdField); - var stream = StreamSupport.stream(cursor.spliterator(), false)) { + final DBObject onlyIdField = new BasicDBObject(Projections.include(FIELD_ID).toBsonDocument()); + try (var cursor = collection(StreamImpl.class).find(query, onlyIdField); var stream = StreamSupport.stream(cursor.spliterator(), false)) { return stream.map(s -> s.get(FIELD_ID).toString()).collect(Collectors.toSet()); } } @@ -340,7 +339,7 @@ public Set indexSetIdsByIds(Collection streamIds) { .map(ObjectId::new) .collect(Collectors.toSet()); final DBObject query = QueryBuilder.start(StreamImpl.FIELD_ID).in(objectIds).get(); - final DBObject onlyIndexSetIdField = DBProjection.include(FIELD_INDEX_SET_ID); + final DBObject onlyIndexSetIdField = new BasicDBObject(Projections.include(FIELD_INDEX_SET_ID).toBsonDocument()); Set indexSets = StreamSupport.stream(collection(StreamImpl.class).find(query, onlyIndexSetIdField).spliterator(), false) .map(s -> s.get(FIELD_INDEX_SET_ID).toString()) .collect(Collectors.toSet()); diff --git a/graylog2-server/src/main/java/org/graylog2/system/activities/SystemMessageServiceImpl.java b/graylog2-server/src/main/java/org/graylog2/system/activities/SystemMessageServiceImpl.java index ede939ad42c9..6c9febb4725d 100644 --- a/graylog2-server/src/main/java/org/graylog2/system/activities/SystemMessageServiceImpl.java +++ b/graylog2-server/src/main/java/org/graylog2/system/activities/SystemMessageServiceImpl.java @@ -18,18 +18,17 @@ import com.google.common.collect.Lists; import com.mongodb.BasicDBObject; -import com.mongodb.BasicDBObjectBuilder; -import com.mongodb.DBCollection; import com.mongodb.DBObject; +import com.mongodb.client.model.CreateCollectionOptions; +import com.mongodb.client.model.Indexes; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; import org.bson.types.ObjectId; import org.graylog2.database.DbEntity; import org.graylog2.database.MongoConnection; import org.graylog2.database.PersistedServiceImpl; -import org.mongojack.DBSort; - -import jakarta.inject.Inject; -import jakarta.inject.Singleton; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -44,13 +43,13 @@ public SystemMessageServiceImpl(MongoConnection mongoConnection) { // Make sure that the system messages collection is always created capped. final String collectionName = SystemMessageImpl.class.getAnnotation(DbEntity.class).collection(); - if (!mongoConnection.getDatabase().collectionExists(collectionName)) { - final DBObject options = BasicDBObjectBuilder.start() - .add("capped", true) - .add("size", MAX_COLLECTION_BYTES) - .get(); - final DBCollection collection = mongoConnection.getDatabase().createCollection(collectionName, options); - collection.createIndex(DBSort.desc("timestamp")); + final var database = mongoConnection.getMongoDatabase(); + if (!database.listCollectionNames().into(new HashSet<>()).contains(collectionName)) { + final var options = new CreateCollectionOptions() + .capped(true) + .sizeInBytes(MAX_COLLECTION_BYTES); + database.createCollection(collectionName, options); + database.getCollection(collectionName).createIndex(Indexes.descending("timestamp")); } } diff --git a/graylog2-server/src/main/java/org/mongojack/DBCursor.java b/graylog2-server/src/main/java/org/mongojack/DBCursor.java deleted file mode 100644 index 28d5ab83b3ea..000000000000 --- a/graylog2-server/src/main/java/org/mongojack/DBCursor.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.mongojack; - -import com.google.common.primitives.Ints; -import com.mongodb.client.FindIterable; -import com.mongodb.client.MongoCursor; -import org.bson.Document; -import org.bson.conversions.Bson; -import jakarta.annotation.Nonnull; - -import javax.annotation.concurrent.NotThreadSafe; -import java.io.Closeable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.function.Supplier; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -@NotThreadSafe -@Deprecated -public class DBCursor implements Closeable, Iterator, Iterable { - private final JacksonMongoCollection collection; - private final FindIterable findIterable; - private final Bson filter; - private MongoCursor cursor; - - public DBCursor(JacksonMongoCollection collection, Bson filter, Supplier> findIterableSupplier) { - this.collection = collection; - this.findIterable = findIterableSupplier.get(); - this.filter = filter; - } - - public DBCursor sort(Bson sort) { - findIterable.sort(sort); - refreshCursor(); - return this; - } - - public DBCursor limit(int limit) { - findIterable.limit(limit); - refreshCursor(); - return this; - } - - public DBCursor skip(int skip) { - findIterable.skip(skip); - refreshCursor(); - return this; - } - - @Override - public void close() { - if (this.cursor != null) { - this.cursor.close(); - } - } - - public List toArray() { - return findIterable.into(new ArrayList<>()); - } - - @Override - public boolean hasNext() { - return getCursor().hasNext(); - } - - @Override - public T next() { - return getCursor().next(); - } - - private MongoCursor getCursor() { - if (this.cursor == null) { - this.cursor = findIterable.iterator(); - } - return cursor; - } - - private void refreshCursor() { - if (this.cursor != null) { - cursor.close(); - cursor = null; - } - } - - public int count() { - return Ints.saturatedCast(collection.countDocuments(filter)); - } - - @Nonnull - @Override - public Iterator iterator() { - return new DBCursor<>(collection, filter, () -> findIterable); - } - - public Document explain() { - return findIterable.explain(); - } -} diff --git a/graylog2-server/src/main/java/org/mongojack/JacksonDBCollection.java b/graylog2-server/src/main/java/org/mongojack/JacksonDBCollection.java deleted file mode 100644 index a45e7cc0fa89..000000000000 --- a/graylog2-server/src/main/java/org/mongojack/JacksonDBCollection.java +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.mongojack; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.DuplicateKeyException; -import com.mongodb.ErrorCategory; -import com.mongodb.MongoException; -import com.mongodb.MongoServerException; -import com.mongodb.WriteConcern; -import com.mongodb.WriteConcernResult; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.model.Collation; -import com.mongodb.client.model.CollationStrength; -import com.mongodb.client.model.Filters; -import com.mongodb.client.model.FindOneAndReplaceOptions; -import com.mongodb.client.model.FindOneAndUpdateOptions; -import com.mongodb.client.model.IndexOptions; -import com.mongodb.client.model.ReplaceOptions; -import com.mongodb.client.model.ReturnDocument; -import com.mongodb.client.model.UpdateOptions; -import org.bson.BsonDocument; -import org.bson.BsonString; -import org.bson.BsonValue; -import org.bson.UuidRepresentation; -import org.bson.codecs.CollectibleCodec; -import org.bson.conversions.Bson; -import org.graylog2.database.jackson.CustomJacksonCodecRegistry; -import org.graylog2.database.jackson.legacy.LegacyDeleteResult; -import org.graylog2.database.jackson.legacy.LegacyInsertManyResult; -import org.graylog2.database.jackson.legacy.LegacyInsertOneResult; -import org.graylog2.database.jackson.legacy.LegacyUpdateOneResult; -import org.graylog2.database.jackson.legacy.LegacyUpdateResult; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -@Deprecated(since = "6.2.0", forRemoval = true) -public class JacksonDBCollection { - - private final JacksonMongoCollection delegate; - private final Class valueType; - private final Class idType; - private final ObjectMapper objectMapper; - private final DBCollection dbCollection; - - public static JacksonDBCollection wrap( - DBCollection dbCollection, Class type, Class keyType, - ObjectMapper objectMapper) { - - return new JacksonDBCollection<>(dbCollection, type, keyType, objectMapper); - } - - private JacksonDBCollection(DBCollection dbCollection, Class valueType, Class idType, ObjectMapper objectMapper) { - - final MongoDatabase db = dbCollection.getDB().getMongoClient().getDatabase(dbCollection.getDB().getName()); - - this.dbCollection = dbCollection; - final JacksonMongoCollection jacksonMongoCollection = JacksonMongoCollection.builder() - .withObjectMapper(objectMapper) - .build(db, dbCollection.getName(), valueType, UuidRepresentation.UNSPECIFIED); - final CustomJacksonCodecRegistry jacksonCodecRegistry = new CustomJacksonCodecRegistry(objectMapper, - jacksonMongoCollection.getCodecRegistry()); - jacksonCodecRegistry.addCodecForClass(valueType); - this.delegate = (JacksonMongoCollection) jacksonMongoCollection.withCodecRegistry(jacksonCodecRegistry); - this.valueType = valueType; - this.idType = idType; - this.objectMapper = objectMapper; - } - - public void createIndex(DBObject keys, DBObject options) { - delegate.createIndex(new BasicDBObject(keys.toMap()), toIndexOptions(options)); - } - - public void createIndex(DBObject keys) { - delegate.createIndex(new BasicDBObject(keys.toMap())); - } - - public DBCursor find() { - return new DBCursor<>(delegate, null, delegate::find); - } - - public DBCursor find(Bson filter) { - return new DBCursor<>(delegate, filter, () -> delegate.find(filter)); - } - - public DBCursor find(DBObject dbObject) { - final BasicDBObject filter = new BasicDBObject(dbObject.toMap()); - return new DBCursor<>(delegate, filter, () -> delegate.find(filter)); - } - - public T findOneById(K objectId) { - return delegate.findOneById(objectId); - } - - public T findOne(Bson filter) throws MongoException { - return delegate.findOne(filter); - } - - public T findOne(DBObject filter) throws MongoException { - return delegate.findOne(new BasicDBObject(filter.toMap())); - } - - public T findOne() { - return delegate.findOne(); - } - - public Iterable distinct(String fieldName, Class tResultClass) { - return delegate.distinct(fieldName, tResultClass); - } - - public long count() { - return delegate.estimatedDocumentCount(); - } - - public long count(Bson filter) { - return delegate.countDocuments(filter); - } - - public long count(DBObject dbObject) { - return delegate.countDocuments(new BasicDBObject(dbObject.toMap())); - } - - public WriteResult save(T object) { - return save(object, null); - } - - public WriteResult save(T object, WriteConcern concern) { - return doSave(object, concern); - } - - private WriteResult doSave(T object, WriteConcern concern) { - final var collection = concern == null ? delegate : delegate.withWriteConcern(concern); - - final CollectibleCodec codec = (CollectibleCodec) delegate.getCodecRegistry().get(valueType); - final BsonValue id = codec.getDocumentId(object); - - try { - if (id == null || id.isNull()) { - return new LegacyInsertOneResult<>(collection, collection.insertOne(object), idType); - } else { - final var idQuery = Filters.eq("_id", id); - return new LegacyUpdateOneResult<>(collection, object, - collection.replaceOne(idQuery, object, new ReplaceOptions().upsert(true)), valueType, idType); - } - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public LegacyDeleteResult remove(DBObject query) { - return new LegacyDeleteResult<>(delegate.deleteMany(new BasicDBObject(query.toMap()))); - } - - public LegacyDeleteResult remove(Bson filter) { - return new LegacyDeleteResult<>(delegate.deleteMany(filter)); - } - - public WriteResult remove(Bson filter, WriteConcern concern) { - var coll = delegate.withWriteConcern(concern); - return new LegacyDeleteResult<>(coll.deleteMany(filter)); - } - - public LegacyDeleteResult removeById(K objectId) { - return new LegacyDeleteResult<>(delegate.removeById(objectId)); - } - - public WriteResult update(Bson filter, T object, boolean upsert, boolean multi) { - return update(filter, object, upsert, multi, delegate.getWriteConcern()); - } - - public WriteResult update(Bson filter, T object, boolean upsert, boolean multi, - @Nullable WriteConcern concern) { - if (multi) { - throw new IllegalArgumentException(("Multi-update is not supported for object-based updates.")); - } - final var coll = concern == null ? delegate : delegate.withWriteConcern(concern); - final var options = new ReplaceOptions().upsert(upsert); - try { - return new LegacyUpdateResult<>(coll.replaceOne(filter, object, options)); - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public WriteResult update(Bson filter, Bson update, boolean upsert, boolean multi) { - try { - if (multi) { - return new LegacyUpdateResult<>(delegate.updateMany(filter, update, new UpdateOptions().upsert(upsert))); - } else { - return new LegacyUpdateResult<>(delegate.updateOne(filter, update, new UpdateOptions().upsert(upsert))); - } - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public WriteResult update(Bson query, Bson update) { - return update(query, update, false, false); - } - - public WriteResult update(DBObject query, Bson update) { - return update((Bson) new BasicDBObject(query.toMap()), update); - } - - public WriteResult update(Bson query, T object) { - return update(query, object, false, false); - } - - public void updateById(K id, Bson update) { - try { - delegate.updateById(id, update); - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public WriteResult updateById(K id, T update) { - try { - return new LegacyUpdateResult<>(delegate.replaceOneById(id, update)); - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public WriteResult updateMulti(Bson query, Bson update) { - return update(query, update, false, true); - } - - public WriteResult insert(T object) { - try { - return new LegacyInsertOneResult<>(delegate, delegate.insertOne(object), idType); - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public WriteResult insert(List list) { - try { - return new LegacyInsertManyResult<>(delegate, delegate.insertMany(list), idType); - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public long getCount() { - return delegate.countDocuments(); - } - - public long getCount(Bson filter) { - return delegate.countDocuments(filter); - } - - public T findAndModify(Bson filter, Bson fields, Bson sort, boolean remove, Bson update, boolean returnNew, - boolean upsert) { - if (remove) { - throw new IllegalArgumentException("Removing objects is not supported!"); - } - - var options = new FindOneAndUpdateOptions() - .projection(fields) - .sort(sort) - .returnDocument(returnNew ? ReturnDocument.AFTER : ReturnDocument.BEFORE) - .upsert(upsert); - - try { - return delegate.findOneAndUpdate(filter, update, options); - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public T findAndModify(Bson query, Bson update) { - return findAndModify(query, null, null, false, update, false, false); - } - - public T findAndModify(Bson filter, Bson fields, Bson sort, boolean remove, T object, boolean returnNew, boolean upsert) { - if (remove) { - throw new IllegalArgumentException("Removing objects is not supported!"); - } - var options = new FindOneAndReplaceOptions() - .projection(fields) - .sort(sort) - .returnDocument(returnNew ? ReturnDocument.AFTER : ReturnDocument.BEFORE) - .upsert(upsert); - - try { - return delegate.findOneAndReplace(filter, object, options); - } catch (MongoServerException e) { - throw possiblyAsDuplicateKeyError(e); - } - } - - public T findAndRemove(Bson filter) { - return delegate.findOneAndDelete(filter); - } - - public void dropIndexes() { - delegate.dropIndexes(); - } - - public void dropIndex(Bson keys) { - delegate.dropIndex(keys); - } - - public void dropIndex(String name) { - delegate.dropIndex(name); - } - - public void drop() { - delegate.drop(); - } - - public List getIndexInfo() { - return delegate.listIndexes(DBObject.class).into(new ArrayList<>()); - } - - public DBCollection getDbCollection() { - return dbCollection; - } - - record IndexOptionDto( - @JsonProperty("unique") Optional unique, - @JsonProperty("name") Optional name, - @JsonProperty("expireAfterSeconds") Optional expireAfterSeconds, - @JsonProperty("sparse") Optional sparse, - @JsonProperty("collation") Optional collationDto) { - - public IndexOptions toIndexOptions() { - final var io = new IndexOptions(); - unique.ifPresent(io::unique); - name.ifPresent(io::name); - expireAfterSeconds.ifPresent(seconds -> io.expireAfter(seconds, TimeUnit.SECONDS)); - sparse.ifPresent(io::sparse); - collationDto.ifPresent(collation -> io.collation(collation.toCollation())); - return io; - } - } - - record CollationDto( - @JsonProperty("locale") Optional locale, - @JsonProperty("strength") Optional strength - ) { - public Collation toCollation() { - final var builder = Collation.builder(); - locale.ifPresent(builder::locale); - strength.ifPresent(s -> builder.collationStrength(CollationStrength.fromInt(s))); - return builder.build(); - } - } - - private IndexOptions toIndexOptions(DBObject options) { - return objectMapper.convertValue(options.toMap(), IndexOptionDto.class).toIndexOptions(); - } - - private MongoException possiblyAsDuplicateKeyError(final MongoServerException e) { - if (ErrorCategory.fromErrorCode(e.getCode()) == ErrorCategory.DUPLICATE_KEY) { - return new DuplicateKeyException(new BsonDocument("err", new BsonString(e.getMessage())), - e.getServerAddress(), - WriteConcernResult.acknowledged(0, false, null)); - } else { - return e; - } - } - -} diff --git a/graylog2-server/src/main/java/org/mongojack/WriteResult.java b/graylog2-server/src/main/java/org/mongojack/WriteResult.java deleted file mode 100644 index 5a234a377bd3..000000000000 --- a/graylog2-server/src/main/java/org/mongojack/WriteResult.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.mongojack; - -import com.mongodb.MongoException; -import org.bson.BsonValue; -import org.bson.types.ObjectId; - -import static org.graylog2.shared.utilities.StringUtils.f; - -/** - * Compatibility layer to support existing code interacting with the Mongojack 2.x API. - * - * @deprecated use {@link org.graylog2.database.MongoCollections} as an entrypoint for interacting with MongoDB. - */ -@Deprecated -public interface WriteResult { - default T getSavedObject() { - throw new MongoException("No objects to return"); - } - - int getN(); - - boolean wasAcknowledged(); - - default K getSavedId() { - throw new MongoException("No Id to return"); - } - - default Object getUpsertedId() { - return null; - } - - boolean isUpdateOfExisting(); - - @SuppressWarnings("unchecked") - static L toIdType(BsonValue id, Class idType) { - if (id == null) { - return null; - } - if (String.class.isAssignableFrom(idType)) { - if (id.isObjectId()) { - return (L) id.asObjectId().getValue().toHexString(); - } - if (id.isString()) { - return (L) id.asString().getValue(); - } - } - if (ObjectId.class.isAssignableFrom(idType)) { - return (L) id.asObjectId().getValue(); - } - throw new IllegalArgumentException(f("Only String and ObjectID types supported for ID. Got %s.", - id.getBsonType())); - } - - static Object extractValue(BsonValue bsonValue) { - if (bsonValue == null) { - return null; - } - return switch (bsonValue.getBsonType()) { - case OBJECT_ID -> bsonValue.asObjectId().getValue(); - case STRING -> bsonValue.asString().getValue(); - default -> throw new IllegalArgumentException(f("Only String and ObjectID types supported for ID. Got %s.", - bsonValue.getBsonType())); - }; - } -} diff --git a/graylog2-server/src/main/java/org/mongojack/package-info.java b/graylog2-server/src/main/java/org/mongojack/package-info.java deleted file mode 100644 index d769df5586d4..000000000000 --- a/graylog2-server/src/main/java/org/mongojack/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -/** - * This package contains a compatibility layer to support old code using the Mongojack 2.x API. It is destined for - * removal as soon as all code has been migrated to use the MongoDB driver API directly. - *

    - * Instead of the classes from this package, use {@link org.graylog2.database.MongoCollections} as an entrypoint for - * interacting with MongoDB. - */ -package org.mongojack; diff --git a/graylog2-server/src/test/java/org/graylog/scheduler/DBJobTriggerServiceTest.java b/graylog2-server/src/test/java/org/graylog/scheduler/DBJobTriggerServiceTest.java index 78d0eb0e97c1..4da9a28ee071 100644 --- a/graylog2-server/src/test/java/org/graylog/scheduler/DBJobTriggerServiceTest.java +++ b/graylog2-server/src/test/java/org/graylog/scheduler/DBJobTriggerServiceTest.java @@ -21,6 +21,7 @@ import com.github.joschi.jadconfig.util.Duration; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.mongodb.client.model.Filters; import org.bson.types.ObjectId; import org.graylog.events.JobSchedulerTestClock; import org.graylog.events.TestJobTriggerData; @@ -44,7 +45,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.mongojack.DBQuery; import java.util.Collections; import java.util.List; @@ -961,14 +961,14 @@ public void triggerWithConstraints() { dbJobTriggerService.create(triggerBuilder .build()); assertThat(dbJobTriggerService.nextRunnableTrigger()).isNotEmpty(); - dbJobTriggerService.deleteByQuery(DBQuery.empty()); + dbJobTriggerService.deleteByQuery(Filters.empty()); // two unfulfilled constraints dbJobTriggerService.create(triggerBuilder .constraints(ImmutableSet.of("IS_LEADER", "HAS_ARCHIVE")) .build()); assertThat(dbJobTriggerService.nextRunnableTrigger()).isEmpty(); - dbJobTriggerService.deleteByQuery(DBQuery.empty()); + dbJobTriggerService.deleteByQuery(Filters.empty()); // two fulfilled constraints when(schedulerCapabilitiesService.getNodeCapabilities()).thenReturn(ImmutableSet.of("HAS_ARCHIVE", "IS_LEADER")); @@ -976,7 +976,7 @@ public void triggerWithConstraints() { .constraints(ImmutableSet.of("IS_LEADER", "HAS_ARCHIVE")) .build()); assertThat(dbJobTriggerService.nextRunnableTrigger()).isNotEmpty(); - dbJobTriggerService.deleteByQuery(DBQuery.empty()); + dbJobTriggerService.deleteByQuery(Filters.empty()); // more capabilities than constraints when(schedulerCapabilitiesService.getNodeCapabilities()).thenReturn(ImmutableSet.of("HAS_ARCHIVE", "IS_LEADER", "ANOTHER_CAPABITILITY")); @@ -984,7 +984,7 @@ public void triggerWithConstraints() { .constraints(ImmutableSet.of("IS_LEADER", "HAS_ARCHIVE")) .build()); assertThat(dbJobTriggerService.nextRunnableTrigger()).isNotEmpty(); - dbJobTriggerService.deleteByQuery(DBQuery.empty()); + dbJobTriggerService.deleteByQuery(Filters.empty()); // more constraints than capabilities when(schedulerCapabilitiesService.getNodeCapabilities()).thenReturn(ImmutableSet.of("HAS_ARCHIVE", "IS_LEADER")); @@ -992,7 +992,7 @@ public void triggerWithConstraints() { .constraints(ImmutableSet.of("IS_LEADER", "HAS_ARCHIVE", "ANOTHER_CONSTRAINT")) .build()); assertThat(dbJobTriggerService.nextRunnableTrigger()).isEmpty(); - dbJobTriggerService.deleteByQuery(DBQuery.empty()); + dbJobTriggerService.deleteByQuery(Filters.empty()); } @Test @@ -1013,13 +1013,13 @@ public void updateProgress() { @MongoDBFixtures("locked-job-triggers.json") public void cancelTriggerByQuery() { // Must return an empty Optional if the query didn't match any trigger - assertThat(dbJobTriggerService.cancelTriggerByQuery(DBQuery.is("foo", "bar"))).isEmpty(); + assertThat(dbJobTriggerService.cancelTriggerByQuery(Filters.eq("foo", "bar"))).isEmpty(); final JobTriggerDto lockedTrigger = dbJobTriggerService.get("54e3deadbeefdeadbeef0001").orElseThrow(AssertionError::new); assertThat(lockedTrigger.isCancelled()).isFalse(); - assertThat(dbJobTriggerService.cancelTriggerByQuery(DBQuery.is("_id", "54e3deadbeefdeadbeef0001"))).isPresent(); + assertThat(dbJobTriggerService.cancelTriggerByQuery(MongoUtils.idEq("54e3deadbeefdeadbeef0001"))).isPresent(); final JobTriggerDto cancelledTrigger = dbJobTriggerService.get(lockedTrigger.id()).orElseThrow(AssertionError::new); diff --git a/graylog2-server/src/test/java/org/graylog2/database/PaginatedDbServiceTest.java b/graylog2-server/src/test/java/org/graylog2/database/PaginatedDbServiceTest.java deleted file mode 100644 index a77442b36508..000000000000 --- a/graylog2-server/src/test/java/org/graylog2/database/PaginatedDbServiceTest.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.graylog2.database; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableSet; -import org.graylog.testing.mongodb.MongoDBInstance; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mongojack.DBQuery; -import org.mongojack.DBSort; -import org.mongojack.Id; -import org.mongojack.ObjectId; - -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; - -public class PaginatedDbServiceTest { - @Rule - public final MongoDBInstance mongodb = MongoDBInstance.createForClass(); - - @JsonAutoDetect - public static class TestDTO { - @ObjectId - @Id - @JsonProperty("id") - public String id; - - @JsonProperty("title") - public String title; - - @JsonCreator - public TestDTO(@JsonProperty("id") @Id String id, @JsonProperty("title") String title) { - this.id = id; - this.title = title; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("id", id) - .add("title", title) - .toString(); - } - - public TestDTO(String title) { - this(null, title); - } - } - - public static class TestDbService extends PaginatedDbService { - protected TestDbService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper) { - super(mongoConnection, mapper, TestDTO.class, "db_service_test"); - } - } - - private TestDbService dbService; - - @Before - public void setUp() throws Exception { - final MongoJackObjectMapperProvider objectMapperProvider = new MongoJackObjectMapperProvider(new ObjectMapper()); - this.dbService = new TestDbService(mongodb.mongoConnection(), objectMapperProvider); - } - - @After - public void tearDown() { - mongodb.mongoConnection().getMongoDatabase().drop(); - } - - private TestDTO newDto(String title) { - return new TestDTO(title); - } - - @Test - public void saveAndGet() { - final TestDTO savedDto = dbService.save(newDto("hello")); - - assertThat(savedDto.title).isEqualTo("hello"); - assertThat(savedDto.id) - .isInstanceOf(String.class) - .isNotBlank() - .matches("^[a-z0-9]{24}$"); - - assertThat(dbService.get(savedDto.id)) - .isPresent() - .get() - .extracting("id", "title") - .containsExactly(savedDto.id, "hello"); - } - - @Test - public void delete() { - final TestDTO savedDto = dbService.save(newDto("hello")); - - assertThat(dbService.delete(savedDto.id)).isEqualTo(1); - assertThat(dbService.delete(savedDto.id)).isEqualTo(0); - - assertThat(dbService.get(savedDto.id)).isNotPresent(); - } - - @Test - public void findPaginatedWithQueryAndSort() { - dbService.save(newDto("hello1")); - dbService.save(newDto("hello2")); - dbService.save(newDto("hello3")); - dbService.save(newDto("hello4")); - dbService.save(newDto("hello5")); - - final PaginatedList page1 = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.asc("title"), 1, 2); - - assertThat(page1.pagination().count()).isEqualTo(2); - assertThat(page1.pagination().total()).isEqualTo(5); - assertThat(page1.delegate()) - .extracting("title") - .containsExactly("hello1", "hello2"); - - final PaginatedList page2 = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.asc("title"), 2, 2); - - assertThat(page2.pagination().count()).isEqualTo(2); - assertThat(page2.pagination().total()).isEqualTo(5); - assertThat(page2.delegate()) - .extracting("title") - .containsExactly("hello3", "hello4"); - - final PaginatedList page3 = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.asc("title"), 3, 2); - - assertThat(page3.pagination().count()).isEqualTo(1); - assertThat(page3.pagination().total()).isEqualTo(5); - assertThat(page3.delegate()) - .extracting("title") - .containsExactly("hello5"); - - final PaginatedList page1reverse = dbService.findPaginatedWithQueryAndSort(DBQuery.empty(), DBSort.desc("title"), 1, 2); - - assertThat(page1reverse.pagination().count()).isEqualTo(2); - assertThat(page1reverse.pagination().total()).isEqualTo(5); - assertThat(page1reverse.delegate()) - .extracting("title") - .containsExactly("hello5", "hello4"); - } - - @Test - public void findPaginatedWithQueryFilterAndSort() { - dbService.save(newDto("hello1")); - dbService.save(newDto("hello2")); - dbService.save(newDto("hello3")); - dbService.save(newDto("hello4")); - dbService.save(newDto("hello5")); - dbService.save(newDto("hello6")); - dbService.save(newDto("hello7")); - - final Predicate filter = view -> view.title.matches("hello[23456]"); - - final PaginatedList page1 = dbService.findPaginatedWithQueryFilterAndSort(DBQuery.empty(), filter, DBSort.asc("title"), 1, 2); - - assertThat(page1.pagination().count()).isEqualTo(2); - assertThat(page1.pagination().total()).isEqualTo(5); - assertThat(page1.delegate()) - .extracting("title") - .containsExactly("hello2", "hello3"); - - final PaginatedList page2 = dbService.findPaginatedWithQueryFilterAndSort(DBQuery.empty(), filter, DBSort.asc("title"), 2, 2); - - assertThat(page2.pagination().count()).isEqualTo(2); - assertThat(page2.pagination().total()).isEqualTo(5); - assertThat(page2.delegate()) - .extracting("title") - .containsExactly("hello4", "hello5"); - - final PaginatedList page3 = dbService.findPaginatedWithQueryFilterAndSort(DBQuery.empty(), filter, DBSort.asc("title"), 3, 2); - - assertThat(page3.pagination().count()).isEqualTo(1); - assertThat(page3.pagination().total()).isEqualTo(5); - assertThat(page3.delegate()) - .extracting("title") - .containsExactly("hello6"); - - final PaginatedList page4 = dbService.findPaginatedWithQueryFilterAndSort(DBQuery.empty(), filter, DBSort.asc("title"), 2, 4); - - assertThat(page4.pagination().count()).isEqualTo(1); - assertThat(page4.pagination().total()).isEqualTo(5); - assertThat(page4.delegate()) - .extracting("title") - .containsExactly("hello6"); - - final PaginatedList page1reverse = dbService.findPaginatedWithQueryFilterAndSort(DBQuery.empty(), filter, DBSort.desc("title"), 1, 2); - - assertThat(page1reverse.pagination().count()).isEqualTo(2); - assertThat(page1reverse.pagination().total()).isEqualTo(5); - assertThat(page1reverse.delegate()) - .extracting("title") - .containsExactly("hello6", "hello5"); - } - - @Test - public void streamAll() { - dbService.save(newDto("hello1")); - dbService.save(newDto("hello2")); - dbService.save(newDto("hello3")); - dbService.save(newDto("hello4")); - - try (final Stream cursor = dbService.streamAll()) { - assertThat(cursor.collect(Collectors.toList())) - .hasSize(4) - .extracting("title") - .containsExactly("hello1", "hello2", "hello3", "hello4"); - } - } - - @Test - public void streamByIds() { - final TestDTO hello1 = dbService.save(newDto("hello1")); - final TestDTO hello2 = dbService.save(newDto("hello2")); - final TestDTO hello3 = dbService.save(newDto("hello3")); - dbService.save(newDto("hello5")); - dbService.save(newDto("hello5")); - - try (final Stream cursor = dbService.streamByIds(ImmutableSet.of(hello1.id, hello2.id, hello3.id))) { - final List list = cursor.collect(Collectors.toList()); - - assertThat(list) - .hasSize(3) - .extracting("title") - .containsExactly("hello1", "hello2", "hello3"); - } - } - - @Test - public void streamQuery() { - dbService.save(newDto("hello1")); - dbService.save(newDto("hello2")); - dbService.save(newDto("hello3")); - dbService.save(newDto("hello4")); - dbService.save(newDto("hello5")); - - final DBQuery.Query query = DBQuery.in("title", "hello1", "hello3", "hello4"); - - try (final Stream cursor = dbService.streamQuery(query)) { - final List list = cursor.collect(Collectors.toList()); - - assertThat(list) - .hasSize(3) - .extracting("title") - .containsExactly("hello1", "hello3", "hello4"); - } - } - - @Test - public void streamQueryWithSort() { - dbService.save(newDto("hello1")); - dbService.save(newDto("hello2")); - dbService.save(newDto("hello3")); - dbService.save(newDto("hello4")); - dbService.save(newDto("hello5")); - - final DBQuery.Query query = DBQuery.in("title", "hello5", "hello3", "hello1"); - final DBSort.SortBuilder sort = DBSort.desc("title"); - - try (final Stream cursor = dbService.streamQueryWithSort(query, sort)) { - final List list = cursor.collect(Collectors.toList()); - - assertThat(list) - .hasSize(3) - .extracting("title") - .containsExactly("hello5", "hello3", "hello1"); - } - } - - @Test - public void sortBuilder() { - assertThat(dbService.getSortBuilder("asc", "f")).isEqualTo(DBSort.asc("f")); - assertThat(dbService.getSortBuilder("aSc", "f")).isEqualTo(DBSort.asc("f")); - assertThat(dbService.getSortBuilder("desc", "f")).isEqualTo(DBSort.desc("f")); - assertThat(dbService.getSortBuilder("dEsC", "f")).isEqualTo(DBSort.desc("f")); - } -} diff --git a/graylog2-server/src/test/java/org/graylog2/indexer/indexset/MongoIndexSetServiceTest.java b/graylog2-server/src/test/java/org/graylog2/indexer/indexset/MongoIndexSetServiceTest.java index e558132f6a87..ebb19323ca43 100644 --- a/graylog2-server/src/test/java/org/graylog2/indexer/indexset/MongoIndexSetServiceTest.java +++ b/graylog2-server/src/test/java/org/graylog2/indexer/indexset/MongoIndexSetServiceTest.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.eventbus.Subscribe; +import com.mongodb.client.model.Filters; import org.bson.types.ObjectId; import org.graylog.testing.mongodb.MongoDBFixtures; import org.graylog.testing.mongodb.MongoDBInstance; @@ -46,7 +47,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.mongojack.DBQuery; import java.time.ZoneOffset; import java.time.ZonedDateTime; @@ -172,11 +172,11 @@ public void getDefaultWithoutDefault() throws Exception { @Test @MongoDBFixtures("MongoIndexSetServiceTest.json") public void findOne() throws Exception { - final Optional config3 = indexSetService.findOne(DBQuery.is("title", "Test 2")); + final Optional config3 = indexSetService.findOne(Filters.eq("title", "Test 2")); assertThat(config3).isPresent(); assertThat(config3.get().id()).isEqualTo("57f3d721a43c2d59cb750002"); - final Optional config4 = indexSetService.findOne(DBQuery.is("title", "__yolo")); + final Optional config4 = indexSetService.findOne(Filters.eq("title", "__yolo")); assertThat(config4).isNotPresent(); } @@ -285,7 +285,7 @@ public void save() throws Exception { @Test @MongoDBFixtures("MongoIndexSetServiceTest.json") - public void deleteWithStringId() throws Exception { + public void deleteWithStringId() { final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber(); clusterEventBus.registerClusterEventSubscriber(subscriber); @@ -300,7 +300,7 @@ public void deleteWithStringId() throws Exception { @Test @MongoDBFixtures("MongoIndexSetServiceTest.json") - public void deleteRemovesExistingIndexSetConfig() throws Exception { + public void deleteRemovesExistingIndexSetConfig() { final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber(); clusterEventBus.registerClusterEventSubscriber(subscriber); @@ -315,7 +315,7 @@ public void deleteRemovesExistingIndexSetConfig() throws Exception { @Test @MongoDBFixtures("MongoIndexSetServiceTest.json") - public void deleteDoesNothingIfIndexSetConfigDoesNotExist() throws Exception { + public void deleteDoesNothingIfIndexSetConfigDoesNotExist() { final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber(); clusterEventBus.registerClusterEventSubscriber(subscriber); @@ -330,7 +330,7 @@ public void deleteDoesNothingIfIndexSetConfigDoesNotExist() throws Exception { @Test @MongoDBFixtures("MongoIndexSetServiceTest.json") - public void deleteWithAssignedStreams() throws Exception { + public void deleteWithAssignedStreams() { final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber(); clusterEventBus.registerClusterEventSubscriber(subscriber); diff --git a/graylog2-server/src/test/java/org/graylog2/search/SearchQueryOperatorTest.java b/graylog2-server/src/test/java/org/graylog2/search/SearchQueryOperatorTest.java index 6ae1b78d26bb..2cef0c4ce9ac 100644 --- a/graylog2-server/src/test/java/org/graylog2/search/SearchQueryOperatorTest.java +++ b/graylog2-server/src/test/java/org/graylog2/search/SearchQueryOperatorTest.java @@ -33,7 +33,7 @@ void setUp() { @Test void withRegexpMetaCharacters() { // Using regexp meta characters should now throw an exception - operator.buildQuery("hello", "foo\\"); + operator.buildBson("hello", "foo\\"); } } } diff --git a/graylog2-server/src/test/java/org/graylog2/search/SearchQueryParserTest.java b/graylog2-server/src/test/java/org/graylog2/search/SearchQueryParserTest.java index aa2aade2a2b1..910d0df67910 100644 --- a/graylog2-server/src/test/java/org/graylog2/search/SearchQueryParserTest.java +++ b/graylog2-server/src/test/java/org/graylog2/search/SearchQueryParserTest.java @@ -18,26 +18,21 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import org.apache.commons.lang3.tuple.Pair; +import org.bson.BsonValue; +import org.bson.conversions.Bson; import org.bson.types.ObjectId; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.junit.jupiter.api.Test; -import org.mongojack.DBQuery; -import org.mongojack.QueryCondition; -import org.mongojack.internal.query.CollectionQueryCondition; -import org.mongojack.internal.query.CompoundQueryCondition; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Map; -import java.util.Set; import java.util.regex.Matcher; -import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; import static org.graylog2.search.SearchQueryParser.DEFAULT_OPERATOR; @@ -56,8 +51,8 @@ void explicitAllowedField() { assertThat(query.hasDisallowedKeys()).isFalse(); assertThat(query.getDisallowedKeys()).isEmpty(); - final DBQuery.Query dbQuery = query.toDBQuery(); - final Collection fieldNamesUsed = extractFieldNames(dbQuery.conditions()); + final Bson dbQuery = query.toBson(); + final Collection fieldNamesUsed = extractFieldNames(dbQuery); assertThat(fieldNamesUsed).containsExactly("name"); } @@ -73,8 +68,8 @@ void decodeQuery() throws UnsupportedEncodingException { assertThat(query.hasDisallowedKeys()).isFalse(); assertThat(query.getDisallowedKeys()).isEmpty(); - final DBQuery.Query dbQuery = query.toDBQuery(); - final Collection fieldNamesUsed = extractFieldNames(dbQuery.conditions()); + final var dbQuery = query.toBson(); + final Collection fieldNamesUsed = extractFieldNames(dbQuery); assertThat(fieldNamesUsed).containsExactly("name"); } @@ -100,8 +95,8 @@ void disallowedField() { assertThat(queryMap.get("defaultfield")).containsOnly(new SearchQueryParser.FieldValue("foo", false)); assertThat(query.hasDisallowedKeys()).isTrue(); assertThat(query.getDisallowedKeys()).containsExactly("notallowed"); - final DBQuery.Query dbQuery = query.toDBQuery(); - final Collection fieldNames = extractFieldNames(dbQuery.conditions()); + final Bson dbQuery = query.toBson(); + final Collection fieldNames = extractFieldNames(dbQuery); assertThat(fieldNames).containsExactly("defaultfield"); } @@ -122,33 +117,32 @@ void mappedFields() { assertThat(queryMap.get("real_id")).containsOnly(new SearchQueryParser.FieldValue("1234", false)); assertThat(query.hasDisallowedKeys()).isFalse(); - final DBQuery.Query dbQuery = query.toDBQuery(); - final Collection fieldNames = extractFieldNames(dbQuery.conditions()); + final var dbQuery = query.toBson(); + final Collection fieldNames = extractFieldNames(dbQuery); assertThat(fieldNames).containsOnly("index_name", "real_id"); } - private Collection extractFieldNames(Set> conditions) { + private Collection extractFieldNames(Bson query) { final ImmutableSet.Builder names = ImmutableSet.builder(); - // recurse into the tree, conveniently there's no visitor we can use, so it's manual - conditions.forEach(entry -> { - final String op = entry.getKey(); - if (!op.startsWith("$")) { - names.add(op); + for (final var element : query.toBsonDocument().entrySet()) { + String key = element.getKey(); + BsonValue value = element.getValue(); + + if (!key.startsWith("$")) { + names.add(key); } - final QueryCondition queryCondition = entry.getValue(); - if (queryCondition instanceof CollectionQueryCondition) { - names.addAll( - extractFieldNames(((CollectionQueryCondition) queryCondition).getValues().stream() - .map(qc -> Maps.immutableEntry("$dummy", qc)) - .collect(Collectors.toSet())) - ); - } else if (queryCondition instanceof CompoundQueryCondition) { - names.addAll( - extractFieldNames(((CompoundQueryCondition) queryCondition).getQuery().conditions()) - ); + + if (value.isDocument()) { + names.addAll(extractFieldNames(value.asDocument())); + } else if (value.isArray()) { + for (BsonValue item : value.asArray()) { + if (item.isDocument()) { + names.addAll(extractFieldNames(item.asDocument())); + } + } } - }); + } return names.build(); } diff --git a/graylog2-server/src/test/java/org/mongojack/JacksonDBCollectionTest.java b/graylog2-server/src/test/java/org/mongojack/JacksonDBCollectionTest.java deleted file mode 100644 index 79dbc2c10134..000000000000 --- a/graylog2-server/src/test/java/org/mongojack/JacksonDBCollectionTest.java +++ /dev/null @@ -1,727 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.mongojack; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.mongodb.BasicDBObject; -import com.mongodb.BasicDBObjectBuilder; -import com.mongodb.DBObject; -import com.mongodb.MongoCommandException; -import com.mongodb.MongoException; -import com.mongodb.WriteConcern; -import com.mongodb.client.MongoCollection; -import org.bson.Document; -import org.graylog.testing.mongodb.MongoDBExtension; -import org.graylog.testing.mongodb.MongoDBTestService; -import org.graylog.testing.mongodb.MongoJackExtension; -import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - -@ExtendWith(MongoDBExtension.class) -@ExtendWith(MongoJackExtension.class) -class JacksonDBCollectionTest { - private MongoDBTestService mongoDBTestService; - private MongoJackObjectMapperProvider mongoJackObjectMapperProvider; - - record Simple(@Id @ObjectId @JsonProperty("id") @Nullable String id, - @JsonProperty("name") String name) {} - - @BeforeEach - void setUp(MongoDBTestService mongoDBTestService, MongoJackObjectMapperProvider mongoJackObjectMapperProvider) { - this.mongoDBTestService = mongoDBTestService; - this.mongoJackObjectMapperProvider = mongoJackObjectMapperProvider; - } - - @Test - void createIndex() { - final var collection = jacksonCollection("simple", Simple.class); - collection.createIndex(new BasicDBObject("name", 1)); - collection.createIndex(new BasicDBObject("_id", 1).append("name", 1)); - assertThat(mongoCollection("simple").listIndexes()).containsExactlyInAnyOrder( - new Document("key", new Document("_id", 1)) - .append("name", "_id_") - .append("v", 2), - new Document("key", new Document("name", 1)) - .append("name", "name_1") - .append("v", 2), - new Document("key", new Document("_id", 1) - .append("name", 1)) - .append("name", "_id_1_name_1") - .append("v", 2) - ); - } - - @Test - void createIndexWithOptions() { - final var collection = jacksonCollection("simple", Simple.class); - collection.createIndex(new BasicDBObject("name", 1), new BasicDBObject("sparse", true).append("unique", true)); - assertThat(mongoCollection("simple").listIndexes()).containsExactlyInAnyOrder( - new Document("key", new Document("_id", 1)) - .append("name", "_id_") - .append("v", 2), - new Document("key", new Document("name", 1)) - .append("name", "name_1") - .append("sparse", true) - .append("unique", true) - .append("v", 2) - ); - } - - @Test - void find() { - final var collection = jacksonCollection("simple", Simple.class); - final List items = List.of( - new Simple("000000000000000000000001", "foo"), - new Simple("000000000000000000000002", "bar") - ); - collection.insert(items); - assertThat((Iterable) collection.find()).containsAll(items); - assertThat((Iterable) collection.find(DBQuery.is("name", "bar"))) - .containsExactly(items.get(1)); - assertThat((Iterable) collection.find(new BasicDBObjectBuilder().add("name", "bar").get())) - .containsExactly(items.get(1)); - } - - @Test - void findWithIterator() { - final var collection = jacksonCollection("simple", Simple.class); - final Simple c = new Simple("000000000000000000000001", "c"); - final Simple a = new Simple("000000000000000000000002", "a"); - final Simple b = new Simple("000000000000000000000003", "b"); - final Simple d = new Simple("000000000000000000000004", "d"); - - collection.insert(List.of(c, a, b, d)); - - try (final DBCursor cursor = collection.find()) { - assertThat(cursor.count()).isEqualTo(4); - - assertThat(cursor.toArray()).isEqualTo(List.of(c, a, b, d)); - assertThat(cursor.iterator()).toIterable().isEqualTo(List.of(c, a, b, d)); - - var iterator = cursor.iterator(); - assertThat(iterator).hasNext(); - assertThat(iterator.next()).isEqualTo(c); - assertThat(iterator.next()).isEqualTo(a); - assertThat(iterator.next()).isEqualTo(b); - assertThat(iterator.next()).isEqualTo(d); - assertThat(iterator).isExhausted(); - - assertThat(cursor.sort(DBSort.asc("name")).skip(1).limit(2).toArray()).containsExactly(b, c); - assertThat(cursor.sort(DBSort.asc("name")).skip(1).limit(2).iterator()).toIterable() - .containsExactly(b, c); - } - - try (final DBCursor cursor = collection.find(DBQuery.in("name", "a", "b", "c"))) { - assertThat(cursor.count()).isEqualTo(3); - assertThat(cursor.toArray()).containsExactly(c, a, b); - assertThat(cursor.iterator()).toIterable().containsExactly(c, a, b); - - cursor.sort(DBSort.asc("name")); - assertThat(cursor.toArray()).containsExactly(a, b, c); - assertThat(cursor.iterator()).toIterable().containsExactly(a, b, c); - - cursor.skip(2); - assertThat(cursor.toArray()).containsExactly(c); - assertThat(cursor.iterator()).toIterable().containsExactly(c); - - cursor.skip(1); - assertThat(cursor.toArray()).containsExactly(b, c); - assertThat(cursor.iterator()).toIterable().containsExactly(b, c); - - cursor.skip(0); - cursor.limit(1); - assertThat(cursor.toArray()).containsExactly(a); - assertThat(cursor.iterator()).toIterable().containsExactly(a); - - cursor.limit(2); - assertThat(cursor.toArray()).containsExactly(a, b); - assertThat(cursor.iterator()).toIterable().containsExactly(a, b); - } - } - - @Test - void findOneById() { - final var collection = jacksonCollection("simple", Simple.class); - final List items = List.of( - new Simple("000000000000000000000001", "foo"), - new Simple("000000000000000000000002", "bar") - ); - collection.insert(items); - assertThat(collection.findOneById(items.get(1).id())).isEqualTo(items.get(1)); - assertThat(collection.findOneById(new org.bson.types.ObjectId().toHexString())).isNull(); - } - - @Test - void findOne() { - final var collection = jacksonCollection("simple", Simple.class); - final List items = List.of( - new Simple("000000000000000000000001", "foo"), - new Simple("000000000000000000000002", "bar") - ); - collection.insert(items); - assertThat(collection.findOne(new BasicDBObjectBuilder().add("name", "bar").get())) - .isEqualTo(items.get(1)); - assertThat(collection.findOne(DBQuery.is("name", "bar"))).isEqualTo(items.get(1)); - } - - @Test - void distinct() { - final var collection = jacksonCollection("simple", Simple.class); - final List items = List.of( - new Simple("000000000000000000000001", "foo"), - new Simple("000000000000000000000002", "bar") - ); - collection.insert(items); - } - - @Test - void count() { - final var collection = jacksonCollection("simple", Simple.class); - final List items = List.of( - new Simple("000000000000000000000001", "foo"), - new Simple("000000000000000000000002", "bar") - ); - collection.insert(items); - assertThat(collection.count()).isEqualTo(2); - assertThat(collection.count((DBObject) new BasicDBObject("name", "foo"))).isEqualTo(1); - } - - @Test - void save() { - final var collection = jacksonCollection("simple", Simple.class); - - final var foo = new Simple("000000000000000000000001", "foo"); - - final var saveFooResult = collection.save(foo); - assertThat(saveFooResult.getSavedObject()).isEqualTo(foo); - assertThat(collection.findOneById(saveFooResult.getSavedId())).isEqualTo(foo); - - final Simple updated = new Simple(foo.id(), "baz"); - final var saveUpdatedResult = collection.save(updated); - assertThat(saveUpdatedResult.getSavedObject()).isEqualTo(updated); - assertThat(collection.findOneById(foo.id())).isEqualTo(updated); - - final var saveBarResult = collection.save(new Simple(null, "bar")); - assertThat(collection.findOneById(saveBarResult.getSavedId()).name()).isEqualTo("bar"); - - assertThatThrownBy(() -> collection.save(foo, WriteConcern.W2)) - .isInstanceOf(MongoCommandException.class) - .hasMessageContaining("cannot use 'w' > 1 when a host is not replicated"); - } - - @Test - void remove() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple("000000000000000000000001", "foo"); - final var bar = new Simple("000000000000000000000002", "bar"); - - collection.insert(List.of(foo, bar)); - assertThat(collection.remove(DBQuery.is("name", "foo")).getN()).isEqualTo(1); - assertThat((Iterable) collection.find()).containsExactly(bar); - - collection.insert(foo); - assertThat(collection.remove(DBQuery.is("name", "foo")).getN()).isEqualTo(1); - assertThat((Iterable) collection.find()).containsExactly(bar); - - assertThatThrownBy(() -> collection.remove(DBQuery.empty(), WriteConcern.W2)) - .isInstanceOf(MongoCommandException.class) - .hasMessageContaining("cannot use 'w' > 1 when a host is not replicated"); - } - - @Test - void removeById() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple("000000000000000000000001", "foo"); - final var bar = new Simple("000000000000000000000002", "bar"); - - collection.insert(List.of(foo, bar)); - assertThat(collection.removeById(foo.id()).getN()).isEqualTo(1); - assertThat((Iterable) collection.find()).containsExactly(bar); - } - - @Test - void updateWithObject() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple("000000000000000000000001", "foo"); - - assertThatThrownBy(() -> collection.update(DBQuery.empty(), foo, false, false, WriteConcern.W2)) - .isInstanceOf(MongoCommandException.class) - .hasMessageContaining("cannot use 'w' > 1 when a host is not replicated"); - - collection.insert(foo); - assertThat(collection.findOneById(foo.id())).isEqualTo(foo); - - final var updated = new Simple(foo.id(), "baz"); - - final var updateResult = collection.update(DBQuery.is("_id", objectId(foo.id())), updated, false, false); - assertThat(updateResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isTrue(); - assertThat(wr.getN()).isOne(); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.findOneById(foo.id())).isEqualTo(updated); - - final var bar = new Simple("000000000000000000000002", "bar"); - - final var upsertAttemptResult = collection.update(DBQuery.is("_id", objectId(bar.id())), bar, false, false); - assertThat(upsertAttemptResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isZero(); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.findOneById(bar.id())).isNull(); - - final var upsertResult = collection.update(DBQuery.is("_id", objectId(bar.id())), bar, true, false); - assertThat(upsertResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isOne(); - assertThat(wr.getUpsertedId()).isEqualTo(objectId(bar.id())); - }); - assertThat(collection.findOneById(bar.id())).isEqualTo(bar); - } - - @Test - void updateWithObjectVariants() { - final var collection = spy(jacksonCollection("simple", Simple.class)); - final var foo = new Simple("000000000000000000000001", "foo"); - - final DBQuery.Query query = DBQuery.empty(); - collection.update(query, foo); - verify(collection).update(eq(query), eq(foo), eq(false), eq(false)); - verify(collection).update(eq(query), eq(foo), eq(false), eq(false), eq(WriteConcern.ACKNOWLEDGED)); - } - - @Test - void updateWithBson() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple("000000000000000000000001", "foo"); - - collection.insert(foo); - assertThat(collection.findOneById(foo.id())).isEqualTo(foo); - - final var updated = new Simple(foo.id(), "baz"); - - final var updateResult = collection.update(DBQuery.is("_id", objectId(foo.id())), - new DBUpdate.Builder().set("name", "baz"), false, false); - assertThat(updateResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isTrue(); - assertThat(wr.getN()).isOne(); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.findOneById(foo.id())).isEqualTo(updated); - - final var bar = new Simple("000000000000000000000002", "bar"); - - final var upsertAttemptResult = collection.update(DBQuery.is("_id", objectId(bar.id())), - new DBUpdate.Builder().set("name", "bar"), false, false); - assertThat(upsertAttemptResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isZero(); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.findOneById(bar.id())).isNull(); - - final var upsertResult = collection.update(DBQuery.is("_id", objectId(bar.id())), - new DBUpdate.Builder().set("name", "bar"), true, false); - assertThat(upsertResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isOne(); - assertThat(wr.getUpsertedId()).isEqualTo(objectId(bar.id())); - }); - assertThat(collection.findOneById(bar.id())).isEqualTo(bar); - } - - @Test - void updateWithBsonVariants() { - final var collection = spy(jacksonCollection("simple", Simple.class)); - - final DBQuery.Query query = DBQuery.empty(); - final DBUpdate.Builder update = new DBUpdate.Builder().set("name", "foo"); - - collection.update(query, update); - verify(collection).update(eq(query), eq(update), eq(false), eq(false)); - } - - @Test - void updateByIdWithObject() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple("000000000000000000000001", "foo"); - - final var upsertAttemptResult = collection.updateById(foo.id(), foo); - assertThat(upsertAttemptResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isZero(); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.findOneById(foo.id())).isNull(); - - collection.insert(foo); - assertThat(collection.findOneById(foo.id())).isEqualTo(foo); - - final var updated = new Simple(foo.id(), "bar"); - final var updateResult = collection.updateById(foo.id(), updated); - assertThat(updateResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isTrue(); - assertThat(wr.getN()).isOne(); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.findOneById(foo.id())).isEqualTo(updated); - } - - @Test - void updateByIdWithBson() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple("000000000000000000000001", "foo"); - - // no upserts allowed, therefore this should be a no-op - collection.updateById(foo.id(), new DBUpdate.Builder().set("name", "foo")); - assertThat(collection.findOneById(foo.id())).isNull(); - - collection.insert(foo); - assertThat(collection.findOneById(foo.id())).isEqualTo(foo); - - final var updated = new Simple(foo.id(), "bar"); - collection.updateById(foo.id(), new DBUpdate.Builder().set("name", "bar")); - assertThat(collection.findOneById(foo.id())).isEqualTo(updated); - } - - @Test - void updateMulti() { - final var collection = jacksonCollection("simple", Simple.class); - - final var foo = new Simple("000000000000000000000001", "foo"); - final var bar = new Simple("000000000000000000000002", "bar"); - - // no upserts allowed, therefore this should be a no-op - var upsertAttemptResult = collection.updateMulti( - DBQuery.in("_id", objectId(foo.id()), objectId(bar.id())), new DBUpdate.Builder().set("name", "baz")); - assertThat(upsertAttemptResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isZero(); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.count()).isZero(); - - collection.insert(List.of(foo, bar)); - assertThat((Iterable) collection.find()).containsExactlyInAnyOrder(foo, bar); - - var updateResult = collection.updateMulti( - DBQuery.in("_id", objectId(foo.id()), objectId(bar.id())), new DBUpdate.Builder().set("name", "baz")); - assertThat(updateResult).isNotNull().satisfies(wr -> { - assertThatThrownBy(wr::getSavedId).isInstanceOf(MongoException.class); - assertThatThrownBy(wr::getSavedObject).isInstanceOf(MongoException.class); - assertThat(wr.isUpdateOfExisting()).isTrue(); - assertThat(wr.getN()).isEqualTo(2); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat((Iterable) collection.find()).containsExactlyInAnyOrder( - new Simple(foo.id(), "baz"), new Simple(bar.id(), "baz")); - } - - @Test - void insertObject() { - final var collection = jacksonCollection("simple", Simple.class); - - assertThat(collection.count()).isZero(); - - final var foo = new Simple("000000000000000000000001", "foo"); - var withExistingIdResult = collection.insert(foo); - assertThat(withExistingIdResult).isNotNull().satisfies(wr -> { - assertThat(wr.getSavedId()).isEqualTo(foo.id()); - assertThat(wr.getSavedObject()).isEqualTo(foo); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isEqualTo(0); - assertThat(wr.getUpsertedId()).isNull(); - }); - assertThat(collection.findOneById(foo.id())).isEqualTo(foo); - - final var bar = new Simple(null, "bar"); - var withGeneratedIdResult = collection.insert(bar); - assertThat(withGeneratedIdResult).isNotNull().satisfies(wr -> { - assertThat(wr.getSavedId()).isNotNull(); - assertThat(wr.getSavedObject()).isEqualTo(new Simple(wr.getSavedId(), "bar")); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isEqualTo(0); - assertThat(wr.getUpsertedId()).isNull(); - }); - } - - @Test - void insertList() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple("000000000000000000000001", "foo"); - final var bar = new Simple(null, "bar"); - - assertThat(collection.insert(List.of(foo, bar))).isNotNull().satisfies(wr -> { - assertThat(wr.getSavedId()).isEqualTo(foo.id()); - assertThat(wr.getSavedObject()).isEqualTo(foo); - assertThat(wr.isUpdateOfExisting()).isFalse(); - assertThat(wr.getN()).isEqualTo(0); - assertThat(wr.getUpsertedId()).isNull(); - }); - - assertThat(collection.count()).isEqualTo(2); - assertThat(collection.findOne(DBQuery.is("name", "foo"))).isNotNull(); - assertThat(collection.findOne(DBQuery.is("name", "bar"))).isNotNull(); - } - - @Test - void getCount() { - final var collection = jacksonCollection("simple", Simple.class); - assertThat(collection.count()).isEqualTo(0); - collection.insert(new Simple(null, "foo")); - assertThat(collection.count()).isEqualTo(1); - collection.insert(new Simple(null, "bar")); - assertThat(collection.count()).isEqualTo(2); - assertThat(collection.count((DBObject) new BasicDBObject(Map.of("name", Map.of("$in", List.of("foo", "bar")))))) - .isEqualTo(2); - assertThat(collection.count((DBObject) new BasicDBObject("name", "bar"))).isOne(); - collection.remove(DBQuery.empty()); - assertThat(collection.count()).isEqualTo(0); - } - - @Test - void findAndModifyWithBson() { - final var collection = jacksonCollection("simple", Simple.class); - - var query = DBQuery.empty(); - var update = new DBUpdate.Builder().set("name", "foo"); - var returnNew = false; - var upsert = false; - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)).isNull(); - assertThat(collection.count()).isZero(); - - upsert = true; - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)).isNull(); - assertThat(collection.count()).isOne(); - - update = new DBUpdate.Builder().set("name", "bar"); - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)) - .satisfies(item -> assertThat(item.name()).isEqualTo("foo")); - assertThat(collection.count()).isOne(); - - update = new DBUpdate.Builder().set("name", "baz"); - returnNew = true; - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)) - .satisfies(item -> assertThat(item.name()).isEqualTo("baz")); - assertThat(collection.count()).isOne(); - - query = DBQuery.is("name", "foo"); - update = new DBUpdate.Builder().set("name", "foo"); - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)) - .satisfies(item -> assertThat(item.name()).isEqualTo("foo")); - assertThat(collection.count()).isEqualTo(2); - } - - @Test - void findAndModifyWithBsonVariants() { - final var collection = spy(jacksonCollection("simple", Simple.class)); - - final var query = DBQuery.empty(); - final var update = new DBUpdate.Builder().set("name", "foo"); - - collection.findAndModify(query, update); - verify(collection).findAndModify(eq(query), isNull(), isNull(), eq(false), eq(update), eq(false), eq(false)); - } - - @Test - void findAndModifyWithObject() { - final var collection = jacksonCollection("simple", Simple.class); - - var query = DBQuery.empty(); - var update = new Simple(null, "foo"); - var returnNew = false; - var upsert = false; - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)).isNull(); - assertThat(collection.count()).isZero(); - - upsert = true; - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)).isNull(); - assertThat(collection.count()).isOne(); - - update = new Simple(null, "bar"); - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)) - .satisfies(item -> assertThat(item.name()).isEqualTo("foo")); - assertThat(collection.count()).isOne(); - - update = new Simple(null, "baz"); - returnNew = true; - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)) - .satisfies(item -> assertThat(item.name()).isEqualTo("baz")); - assertThat(collection.count()).isOne(); - - query = DBQuery.is("name", "foo"); - update = new Simple(null, "foo"); - assertThat(collection.findAndModify(query, null, null, false, update, returnNew, upsert)) - .satisfies(item -> assertThat(item.name()).isEqualTo("foo")); - assertThat(collection.count()).isEqualTo(2); - } - - @Test - void findAndRemove() { - final var collection = jacksonCollection("simple", Simple.class); - - final var foo = new Simple("000000000000000000000001", "foo"); - final var bar = new Simple("000000000000000000000002", "bar"); - - collection.insert(List.of(foo, bar)); - - assertThat(collection.findAndRemove(DBQuery.is("_id", objectId(foo.id())))).isEqualTo(foo); - assertThat(collection.findAndRemove(DBQuery.is("_id", objectId(bar.id())))).isEqualTo(bar); - assertThat(collection.count()).isZero(); - } - - @Test - void dropIndexes() { - final var collection = jacksonCollection("simple", Simple.class); - - collection.createIndex(new BasicDBObject("name", 1)); - collection.createIndex(new BasicDBObject("name", 1).append("_id", 1)); - - assertThat(mongoCollection("simple").listIndexes()).extracting("name") - .containsExactlyInAnyOrder("_id_", "name_1", "name_1__id_1"); - - collection.dropIndexes(); - - assertThat(mongoCollection("simple").listIndexes()).extracting("name") - .containsExactlyInAnyOrder("_id_"); - } - - @Test - void dropIndex() { - final var collection = jacksonCollection("simple", Simple.class); - - collection.createIndex(new BasicDBObject("name", 1)); - collection.createIndex(new BasicDBObject("name", 1).append("_id", 1)); - - assertThat(mongoCollection("simple").listIndexes()).extracting("name") - .containsExactlyInAnyOrder("_id_", "name_1", "name_1__id_1"); - - collection.dropIndex("name_1"); - - assertThat(mongoCollection("simple").listIndexes()).extracting("name") - .containsExactlyInAnyOrder("_id_", "name_1__id_1"); - - collection.dropIndex(new BasicDBObject("name", 1).append("_id", 1)); - - assertThat(mongoCollection("simple").listIndexes()).extracting("name") - .containsExactlyInAnyOrder("_id_"); - } - - @Test - void drop() { - final var a = jacksonCollection("a", Simple.class); - final var b = jacksonCollection("b", Simple.class); - a.insert(new Simple(null, "foo")); - b.insert(new Simple(null, "foo")); - - assertThat(mongoDBTestService.mongoDatabase().listCollections()).extracting("name") - .containsExactlyInAnyOrder("a", "b"); - - a.drop(); - - assertThat(mongoDBTestService.mongoDatabase().listCollections()).extracting("name") - .containsExactlyInAnyOrder("b"); - } - - @Test - void getIndexInfo() { - final var collection = jacksonCollection("simple", Simple.class); - collection.createIndex(new BasicDBObject("name", 1)); - collection.createIndex(new BasicDBObject("_id", 1).append("name", 1)); - - assertThat(collection.getIndexInfo()).containsExactlyInAnyOrder( - new BasicDBObject("key", new Document("_id", 1)) - .append("name", "_id_") - .append("v", 2), - new BasicDBObject("key", new Document("name", 1)) - .append("name", "name_1") - .append("v", 2), - new BasicDBObject("key", new Document("_id", 1) - .append("name", 1)) - .append("name", "_id_1_name_1") - .append("v", 2) - ); - } - - @Test - void getDbCollection() { - final var collection = jacksonCollection("simple", Simple.class); - - assertThat(collection.getDbCollection()).isEqualTo( - mongoDBTestService.mongoConnection().getDatabase().getCollection("simple")); - } - - @Test - void wasAcknowledged() { - final var collection = jacksonCollection("simple", Simple.class); - final var foo = new Simple(null, "foo"); - - assertThat(collection.update(DBQuery.empty(), foo, false, false, WriteConcern.UNACKNOWLEDGED) - .wasAcknowledged()).isFalse(); - assertThat(collection.update(DBQuery.empty(), foo, false, false, WriteConcern.ACKNOWLEDGED) - .wasAcknowledged()).isTrue(); - } - - private JacksonDBCollection jacksonCollection(String collectionName, Class valueType) { - return JacksonDBCollection.wrap( - mongoDBTestService.mongoConnection().getDatabase().getCollection(collectionName), - valueType, - String.class, - mongoJackObjectMapperProvider.get() - ); - } - - private MongoCollection mongoCollection(String collectionName) { - return mongoDBTestService.mongoCollection(collectionName); - } - - private org.bson.types.ObjectId objectId(String id) { - return new org.bson.types.ObjectId(id); - } -} diff --git a/graylog2-server/src/test/java/org/mongojack/WriteResultTest.java b/graylog2-server/src/test/java/org/mongojack/WriteResultTest.java deleted file mode 100644 index 7bde569759fb..000000000000 --- a/graylog2-server/src/test/java/org/mongojack/WriteResultTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -package org.mongojack; - -import org.bson.BsonObjectId; -import org.bson.BsonString; -import org.bson.types.ObjectId; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class WriteResultTest { - - @Test - void toIdType() { - assertThat(WriteResult.toIdType(new BsonString("string-id"), String.class)).isEqualTo("string-id"); - assertThat(WriteResult.toIdType(new BsonObjectId(new ObjectId("54e3deadbeefdeadbeef0001")), String.class)). - isEqualTo("54e3deadbeefdeadbeef0001"); - assertThat(WriteResult.toIdType(new BsonObjectId(new ObjectId("54e3deadbeefdeadbeef0001")), ObjectId.class)). - isEqualTo(new ObjectId("54e3deadbeefdeadbeef0001")); - } -} diff --git a/pom.xml b/pom.xml index 597d01b0b306..669b7b71ce41 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ 9.12.0 4.2.30 5.3.1 - 4.11.0 + 5.0.2 0.13 4.1.117.Final 2.0.69.Final From 74a26902d12b870c3c1d2af739034ef91c1e2f5e Mon Sep 17 00:00:00 2001 From: Othello Maurer Date: Mon, 3 Feb 2025 14:12:14 +0100 Subject: [PATCH 48/56] Remove management of net.bytebuddy:byte-buddy (#21514) Managing byte-buddy ourselves doesn't seem to be necessary anymore. By removing the management, we don't have to take care of version upgrades anymore. Co-authored-by: Bernd Ahlers --- pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pom.xml b/pom.xml index 669b7b71ce41..84c4b8530284 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,6 @@ 2.2.0 1.80 - 1.16.1 3.2.0 0.0.1.10 4.8.179 @@ -504,16 +503,6 @@ hamcrest ${hamcrest.version} - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - - - net.bytebuddy - byte-buddy-agent - ${byte-buddy.version} - org.awaitility awaitility From b9ebea9aa1b309d82b020eb3c54fa36f042edbf5 Mon Sep 17 00:00:00 2001 From: Zack King <91903901+kingzacko1@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:18:37 -0600 Subject: [PATCH 49/56] Add escape character handling to key_value pipeline function (#21456) * Add use_escape_char param to key_value * CL and comment clarification --- changelog/unreleased/pr-21456.toml | 5 ++ .../functions/strings/KeyValue.java | 46 ++++++++++++++++++- .../functions/strings/KeyValueTest.java | 21 +++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/pr-21456.toml diff --git a/changelog/unreleased/pr-21456.toml b/changelog/unreleased/pr-21456.toml new file mode 100644 index 000000000000..d3276fa24e45 --- /dev/null +++ b/changelog/unreleased/pr-21456.toml @@ -0,0 +1,5 @@ +type = "added" +message = "Added escape character handling to the key_value pipeline function." + +pulls = ["21456"] +issues = ["graylog-plugin-enterprise#9552"] diff --git a/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValue.java b/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValue.java index c63006db6dbd..2ba304b9f2dc 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValue.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValue.java @@ -51,6 +51,8 @@ public class KeyValue extends AbstractFunction> { private final ParameterDescriptor duplicateHandlingParam; private final ParameterDescriptor trimCharactersParam; private final ParameterDescriptor trimValueCharactersParam; + private final ParameterDescriptor useEscapeCharacter; + public KeyValue() { valueParam = string("value").ruleBuilderVariable().description("The string to extract key/value pairs from").build(); @@ -70,6 +72,11 @@ public KeyValue() { .optional() .description("The characters to trim from values, default is not to trim") .build(); + useEscapeCharacter = bool("use_escape_char"). + optional() + .description("Whether to make use of the escape character '\\' or treat it as a normal character, defaults to false treating '\\' as a normal character.") + .defaultValue(Optional.of(false)) + .build(); } @Override @@ -81,7 +88,10 @@ public Map evaluate(FunctionArgs args, EvaluationContext context final CharMatcher kvPairsMatcher = splitParam.optional(args, context).orElse(CharMatcher.whitespace()); final CharMatcher kvDelimMatcher = valueSplitParam.optional(args, context).orElse(CharMatcher.anyOf("=")); - Splitter outerSplitter = Splitter.on(DelimiterCharMatcher.withQuoteHandling(kvPairsMatcher)) + final boolean allowEscaping = useEscapeCharacter.optional(args, context).orElse(false); + Splitter outerSplitter = Splitter.on( + allowEscaping ? DelimiterCharMatcher.withQuoteAndEscapeHandling(kvPairsMatcher) : DelimiterCharMatcher.withQuoteHandling(kvPairsMatcher) + ) .omitEmptyStrings() .trimResults(); @@ -139,6 +149,20 @@ static CharMatcher withQuoteHandling(CharMatcher charMatcher) { .and(charMatcher); } + /** + * An implementation that doesn't split when the given delimiter char matcher appears in double or single quotes + * or after the escape char '\'. + * + * @param charMatcher the char matcher + * @return a char matcher that can handle double, single quotes, and escape characters + */ + static CharMatcher withQuoteAndEscapeHandling(CharMatcher charMatcher) { + return new DelimiterCharMatcher('"') + .and(new DelimiterCharMatcher('\'')) + .and(new NotEscapedCharMatcher()) + .and(charMatcher); + } + private DelimiterCharMatcher(char wrapperChar) { this.wrapperChar = wrapperChar; } @@ -152,6 +176,26 @@ public boolean matches(char c) { } } + private static class NotEscapedCharMatcher extends CharMatcher { + private char lastChar = '\u0000'; + + @Override + public boolean matches(char c) { + if (lastChar == '\u0000') { + lastChar = c; + return true; + } else { + if (lastChar == '\\') { + lastChar = c; + return false; + } else { + lastChar = c; + return true; + } + } + } + } + private static class MapSplitter { private final Splitter outerSplitter; diff --git a/graylog2-server/src/test/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValueTest.java b/graylog2-server/src/test/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValueTest.java index 534195acbcb4..5b82b7bfa618 100644 --- a/graylog2-server/src/test/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValueTest.java +++ b/graylog2-server/src/test/java/org/graylog/plugins/pipelineprocessor/functions/strings/KeyValueTest.java @@ -137,4 +137,25 @@ void testValueSplitParam() { assertThat(result).containsExactlyInAnyOrderEntriesOf(expectedResult); } + + @Test + void testEscapeHandling() { + final Map arguments = Map.of( + "value", new StringExpression(new CommonToken(0), "field1=value1,dn=CN=Network Automation User\\,OU=Service Accounts\\,OU=GR\\,OU=Region\\,DC=company\\,DC=local,field3=value3"), + "kv_delimiters", new StringExpression(new CommonToken(0), "="), + "delimiters", new StringExpression(new CommonToken(0), ","), + "allow_dup_keys", new BooleanExpression(new CommonToken(0), true), + "use_escape_char", new BooleanExpression(new CommonToken(0), true), + "handle_dup_keys", new StringExpression(new CommonToken(0), ",") + ); + + Map result = classUnderTest.evaluate(new FunctionArgs(classUnderTest, arguments), evaluationContext); + + Map expectedResult = new HashMap<>(); + expectedResult.put("field1", "value1"); + expectedResult.put("dn", "CN=Network Automation User\\,OU=Service Accounts\\,OU=GR\\,OU=Region\\,DC=company\\,DC=local"); + expectedResult.put("field3", "value3"); + + assertThat(result).containsExactlyInAnyOrderEntriesOf(expectedResult); + } } From 74bc901863ad98a8af095b478ebb8bbffdffa6db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2025 09:52:45 +0100 Subject: [PATCH 50/56] Bump joda-time:joda-time from 2.13.0 to 2.13.1 (#21534) Bumps [joda-time:joda-time](https://github.com/JodaOrg/joda-time) from 2.13.0 to 2.13.1. - [Release notes](https://github.com/JodaOrg/joda-time/releases) - [Changelog](https://github.com/JodaOrg/joda-time/blob/main/RELEASE-NOTES.txt) - [Commits](https://github.com/JodaOrg/joda-time/compare/v2.13.0...v2.13.1) --- updated-dependencies: - dependency-name: joda-time:joda-time dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 84c4b8530284..51745ac1806d 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ 1.0 3.1.10 7.0.3 - 2.13.0 + 2.13.1 0.9.15 20250107 2.9.0 From 1d4084191d546e210fd3cb7f1aa40e0f1caf0187 Mon Sep 17 00:00:00 2001 From: Maksym Yadlovskyi Date: Tue, 4 Feb 2025 14:57:21 +0100 Subject: [PATCH 51/56] Refactoring of FilterPreview component (#21376) * Refactoring of FilterPreview component * changelog * fix tsc * fix changelog --- changelog/unreleased/pr-21376.toml | 5 + .../event-definition-types/FilterPreview.tsx | 142 +++++++++--------- 2 files changed, 73 insertions(+), 74 deletions(-) create mode 100644 changelog/unreleased/pr-21376.toml diff --git a/changelog/unreleased/pr-21376.toml b/changelog/unreleased/pr-21376.toml new file mode 100644 index 000000000000..55cb519c38f2 --- /dev/null +++ b/changelog/unreleased/pr-21376.toml @@ -0,0 +1,5 @@ +type = "fixed" +message = "Improve readability of filter preview error message in event definition wizard (dark mode)." + +issues = ["Graylog2/graylog-plugin-enterprise#9336"] +pulls = ["21376"] diff --git a/graylog2-web-interface/src/components/event-definitions/event-definition-types/FilterPreview.tsx b/graylog2-web-interface/src/components/event-definitions/event-definition-types/FilterPreview.tsx index 5ef4498b2ff4..c1a8d5f44b24 100644 --- a/graylog2-web-interface/src/components/event-definitions/event-definition-types/FilterPreview.tsx +++ b/graylog2-web-interface/src/components/event-definitions/event-definition-types/FilterPreview.tsx @@ -30,87 +30,81 @@ type FilterPreviewProps = { }; type Message = { - timestamp: string, - message: string, -} + index: string, + message: { + timestamp: string, + _id: string, + message: string, + }, -class FilterPreview extends React.Component { - static defaultProps = { - searchResult: {}, - errors: [], - isFetchingData: false, - displayPreview: false, - }; +} - renderMessages = (messages) => messages.map(({ index, message }) => ( - - {message.timestamp} - {message.message} - - )); +const Messages = ({ messages }: { messages: Array }) => messages.map(({ index, message }) => ( + + {message.timestamp} + {message.message} + +)); - renderSearchResult = (searchResult: { messages?: Array } = {}) => { - if (!searchResult.messages || searchResult.messages.length === 0) { - return

    Could not find any messages with the current search criteria.

    ; - } +const SearchResult = ({ searchResult, isFetchingData }: { isFetchingData: boolean, searchResult: { messages?: Array }}) => { + if (isFetchingData) return ; - return ( - - - - - - - - - {this.renderMessages(searchResult.messages)} - -
    TimestampMessage
    - ); - }; + if (!searchResult.messages || searchResult.messages.length === 0) { + return

    Could not find any messages with the current search criteria.

    ; + } - render() { - const { isFetchingData, searchResult, errors, displayPreview } = this.props; + return ( + + + + + + + + + + +
    TimestampMessage
    + ); +}; - const renderedResults = isFetchingData ? : this.renderSearchResult(searchResult); +const FilterPreview = ({ searchResult = {}, displayPreview = false, errors = [], isFetchingData = false }: FilterPreviewProps) => { + const hasError = errors?.length > 0; - return ( - <> - -

    - The Filter & Aggregation Condition will generate different number of Events, depending on how it is - configured: -

    -
      -
    • Filter: One Event per message matching the filter
    • -
    • - Aggregation without groups: One Event every time the aggregation result satisfies - the condition -
    • -
    • - Aggregation with groups: One Event per group whose aggregation result satisfies - the condition -
    • -
    -
    + return ( + <> + +

    + The Filter & Aggregation Condition will generate different number of Events, depending on how it is + configured: +

    +
      +
    • Filter: One Event per message matching the filter
    • +
    • + Aggregation without groups: One Event every time the aggregation result satisfies + the condition +
    • +
    • + Aggregation with groups: One Event per group whose aggregation result satisfies + the condition +
    • +
    +
    - {displayPreview && ( - - - Filter Preview - - - {errors.length > 0 ?

    {errors[0].description}

    : renderedResults} -
    -
    - )} - - ); - } -} + {displayPreview && ( + + + Filter Preview + + + {hasError ?

    {errors[0].description}

    : } +
    +
    + )} + + ); +}; export default FilterPreview; From 22e150b26b6331652aa6ad3ef50548394eb2087d Mon Sep 17 00:00:00 2001 From: Othello Maurer Date: Wed, 5 Feb 2025 08:04:25 +0100 Subject: [PATCH 52/56] Bump software.amazon.kinesis:amazon-kinesis-client from 2.6.0 to 2.6.1 (#21538) * Bump software.amazon.kinesis:amazon-kinesis-client from 2.6.0 to 2.6.1 * add changelog --- changelog/unreleased/pr-21538.toml | 5 +++++ pom.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/pr-21538.toml diff --git a/changelog/unreleased/pr-21538.toml b/changelog/unreleased/pr-21538.toml new file mode 100644 index 000000000000..a40ebd0787ff --- /dev/null +++ b/changelog/unreleased/pr-21538.toml @@ -0,0 +1,5 @@ +type = "fixed" +message = "Upgrade AWS Kinesis client libary to version 6.1.0 to fix potential shard processing issues." + +issues = ["21451"] +pulls = ["21538"] diff --git a/pom.xml b/pom.xml index 51745ac1806d..dd4e86635ec3 100644 --- a/pom.xml +++ b/pom.xml @@ -100,7 +100,7 @@ 2.5.2 1.12.675 2.30.4 - 2.6.0 + 2.6.1 2.2.0 1.80 From 3b0e8d5c723ee14e87d4bcaf765f5b8da93ef8ae Mon Sep 17 00:00:00 2001 From: Linus Pahl <46300478+linuspahl@users.noreply.github.com> Date: Wed, 5 Feb 2025 08:49:01 +0100 Subject: [PATCH 53/56] Improve menu label text color and size. (#21542) * Improve menu label text color. * Improve menu label text size. --- graylog2-web-interface/src/components/bootstrap/Menu.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/graylog2-web-interface/src/components/bootstrap/Menu.tsx b/graylog2-web-interface/src/components/bootstrap/Menu.tsx index 8458cf548862..32e6c1b0b9c2 100644 --- a/graylog2-web-interface/src/components/bootstrap/Menu.tsx +++ b/graylog2-web-interface/src/components/bootstrap/Menu.tsx @@ -82,7 +82,8 @@ const StyledMenuDivider = styled(MantineMenu.Divider)(({ theme }) => css` `); const StyledMenuLabel = styled(MantineMenu.Label)(({ theme }) => css` - font-size: ${theme.fonts.size.navigation}; + font-size: ${theme.fonts.size.small}; + color: ${theme.colors.global.textSecondary}; `); Menu.Target = MantineMenu.Target; From 55444bbc9c9aecec210ab990626063afb1d5feb7 Mon Sep 17 00:00:00 2001 From: Othello Maurer Date: Wed, 5 Feb 2025 16:19:34 +0100 Subject: [PATCH 54/56] Ban bouncycastle jdk15on dependencies (#21546) We are using jdk18on dependencies and don't want jdk15on dependencies to be pulled in accidentally. These would usually be rather outdated, and we don't want to take care of version bumps for the jdk15on dependencies. --- graylog-project-parent/pom.xml | 8 ++++++++ pom.xml | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/graylog-project-parent/pom.xml b/graylog-project-parent/pom.xml index b0aa1635483c..6b12942da229 100644 --- a/graylog-project-parent/pom.xml +++ b/graylog-project-parent/pom.xml @@ -483,6 +483,14 @@ org.apache.directory.api api-ldap-schema-data + + org.bouncycastle + bcprov-jdk15on + + + org.bouncycastle + bcpkix-jdk15on +
    diff --git a/pom.xml b/pom.xml index dd4e86635ec3..89982b8fa7ef 100644 --- a/pom.xml +++ b/pom.xml @@ -719,6 +719,10 @@ javax.inject:* javax.ws.rs:javax.* com.fasterxml.jackson.jaxrs:* + + org.bouncycastle:bcprov-jdk15on + org.bouncycastle:bcpkix-jdk15on + org.bouncycastle:bcutil-jdk15on From 3ff77bad9700bc1a74f60c5616a68fe7fcb8e8d8 Mon Sep 17 00:00:00 2001 From: Ousmane SAMBA Date: Wed, 5 Feb 2025 16:21:09 +0100 Subject: [PATCH 55/56] rename dwh to dataLake (#21507) * rename dwh to dataLake * fix linter * fix type * revert feature-flag * revert changelog --- .../src/@types/graylog-web-plugin/index.d.ts | 26 +++++++++---------- .../src/components/nodes/NodeOverview.tsx | 6 ++--- .../StreamDataRoutingDestinations.tsx | 4 +-- .../StreamDataRoutingProcessing.tsx | 2 +- .../streams/StreamDetails/StreamDetails.tsx | 6 ++--- .../output-filter/FilterRuleList.tsx | 2 +- .../IndexSetArchivingCell.tsx | 4 +-- .../StreamsOverview/ColumnRenderers.tsx | 4 +-- .../streams/StreamsOverview/Constants.ts | 10 +++---- .../StreamsOverview/StreamDeleteModal.tsx | 14 +++++----- ...abled.ts => useIsStreamDataLakeEnabled.ts} | 12 ++++----- ...HasData.ts => useStreamDataLakeHasData.ts} | 14 +++++----- 12 files changed, 52 insertions(+), 52 deletions(-) rename graylog2-web-interface/src/components/streams/StreamsOverview/hooks/{useIsStreamDataWarehouseEnabled.ts => useIsStreamDataLakeEnabled.ts} (65%) rename graylog2-web-interface/src/components/streams/StreamsOverview/hooks/{useStreamDataWarehouseHasData.ts => useStreamDataLakeHasData.ts} (62%) diff --git a/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts b/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts index 07551e8da009..a2605712699f 100644 --- a/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts +++ b/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts @@ -193,32 +193,32 @@ export type FieldValueProvider = { requiredFields: string[], } -interface PluginDataWarehouse { - StreamDataWarehouse: React.ComponentType<{ +interface PluginDataLake { + StreamDataLake: React.ComponentType<{ permissions: Immutable.List, }>, - DataWarehouseStatus: React.ComponentType<{ - datawareHouseEnabled: boolean; + DataLakeStatus: React.ComponentType<{ + dataLakeEnabled: boolean; }>, - DataWarehouseJournal: React.ComponentType<{ + DataLakeJournal: React.ComponentType<{ nodeId: string, }>, - DataWarehouseJobs: React.ComponentType<{ + DataLakeJobs: React.ComponentType<{ permissions: Immutable.List, streamId: string, }>, StreamIlluminateProcessingSection: React.ComponentType<{ stream: Stream, }>, - StreamIndexSetDataWarehouseWarning: React.ComponentType<{streamId: string, isArchivingEnabled: boolean}>, - fetchStreamDataWarehouseStatus: (streamId: string) => Promise<{ + StreamIndexSetDataLakeWarning: React.ComponentType<{streamId: string, isArchivingEnabled: boolean}>, + fetchStreamDataLakeStatus: (streamId: string) => Promise<{ id: string, archive_name: string, enabled: boolean, stream_id: string, retention_time: number, }>, - fetchStreamDataWarehouse: (streamId: string) => Promise<{ + fetchStreamDataLake: (streamId: string) => Promise<{ id: string, archive_config_id: string, message_count: number, @@ -228,18 +228,18 @@ interface PluginDataWarehouse { restore_history: Array<{id:string}>, }>; - getStreamDataWarehouseTableElements: (permission: Immutable.List) => { + getStreamDataLakeTableElements: (permission: Immutable.List) => { attributeName: string, attributes: Array<{ id: string, title: string }>, - columnRenderer: { datawarehouse: ColumnRenderer }, + columnRenderer: { data_lake: ColumnRenderer }, }, - DataWarehouseStreamDeleteWarning: React.ComponentType, + DataLakeStreamDeleteWarning: React.ComponentType, } declare module 'graylog-web-plugin/plugin' { interface PluginExports { navigation?: Array; - dataWarehouse?: Array + dataLake?: Array dataTiering?: Array defaultNavigation?: Array; navigationItems?: Array; diff --git a/graylog2-web-interface/src/components/nodes/NodeOverview.tsx b/graylog2-web-interface/src/components/nodes/NodeOverview.tsx index a1c7a636a6d3..d81dbbbbd91f 100644 --- a/graylog2-web-interface/src/components/nodes/NodeOverview.tsx +++ b/graylog2-web-interface/src/components/nodes/NodeOverview.tsx @@ -67,8 +67,8 @@ type Props = { systemOverview: SystemOverview, } -const NodeOverview = ({ node, plugins, inputStates, inputDescriptions, jvmInformation, systemOverview }: Props) => { - const DataWareHouseJournal = PluginStore.exports('dataWarehouse')?.[0]?.DataWarehouseJournal; +const NodeOverview = ({ node, plugins = null, inputStates = null, inputDescriptions = null, jvmInformation = null, systemOverview }: Props) => { + const DataLakeJournal = PluginStore.exports('dataLake')?.[0]?.DataLakeJournal; const pluginCount = `${plugins?.length || 0} plugins installed`; const runningInputs = inputStates?.filter((inputState) => inputState.state.toUpperCase() === 'RUNNING'); @@ -124,7 +124,7 @@ const NodeOverview = ({ node, plugins, inputStates, inputDescriptions, jvmInform - {DataWareHouseJournal && } + {DataLakeJournal && }

    System

    diff --git a/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingDestinations.tsx b/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingDestinations.tsx index d4d1f6e6c904..13a87517db6d 100644 --- a/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingDestinations.tsx +++ b/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingDestinations.tsx @@ -39,7 +39,7 @@ const Container = styled.div(({ theme }) => css` const StreamDataRoutingDestinations = ({ stream }: Props) => { const currentUser = useCurrentUser(); - const StreamDataWarehouseComponent = PluginStore.exports('dataWarehouse')?.[0]?.StreamDataWarehouse; + const StreamDataLakeComponent = PluginStore.exports('dataLake')?.[0]?.StreamDataLake; const destinationIndexset = isPermitted(currentUser.permissions, ['indexsets:read']) ? : ; const destinationOutput = isPermitted(currentUser.permissions, ['output:read']) ? : ; @@ -47,7 +47,7 @@ const StreamDataRoutingDestinations = ({ stream }: Props) => { return ( {destinationIndexset} - {StreamDataWarehouseComponent && } + {StreamDataLakeComponent && } {destinationOutput} ); diff --git a/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingProcessing.tsx b/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingProcessing.tsx index c932e1a33112..1ddb48875ce8 100644 --- a/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingProcessing.tsx +++ b/graylog2-web-interface/src/components/streams/StreamDetails/StreamDataRoutingProcessing.tsx @@ -43,7 +43,7 @@ const StreamDataRoutingProcessing = ({ stream }: Props) => { const hasConnectedPipelines = !isLoadingConnectPipelines && connectedPipelines?.length > 0; const { data: pipelines } = usePipelines(); const sortPipelines = (pipelinesList: StreamConnectedPipelines) => pipelinesList.sort((s1, s2) => naturalSort(s1.title, s2.title)); - const StreamIlluminateProcessingSection = PluginStore.exports('dataWarehouse')?.[0]?.StreamIlluminateProcessingSection; + const StreamIlluminateProcessingSection = PluginStore.exports('dataLake')?.[0]?.StreamIlluminateProcessingSection; return ( <> diff --git a/graylog2-web-interface/src/components/streams/StreamDetails/StreamDetails.tsx b/graylog2-web-interface/src/components/streams/StreamDetails/StreamDetails.tsx index 3d0e008def20..2cb9b37c5efc 100644 --- a/graylog2-web-interface/src/components/streams/StreamDetails/StreamDetails.tsx +++ b/graylog2-web-interface/src/components/streams/StreamDetails/StreamDetails.tsx @@ -59,7 +59,7 @@ const PROCESSING_SEGMENT = 'processing'; const DESTINATIONS_SEGMENT = 'destinations'; const INTAKE_DESCRIPTION = 'Stream Rules may be used to collect a filtered subset of messages directly from Inputs to this Stream. Note that Stream Rules are now a legacy feature, the recommended device to manage stream routing is now Pipeline Rules.'; const PROCESSING_DESCRIPTION = 'Pipelines let you transform and process messages coming from streams. Pipelines consist of stages where rules are evaluated and applied. Messages can go through one or more stages.'; -const DESTINATION_DESCRIPTION = 'The Destinations page lets you define where messages in this stream should be routed. A stream may have multiple destinations. Note that messages routed to only Data Warehouse will not count towards License usage, unless subsequently retrieved. On a per-destination basis, filters may be applied to limit the subset of messages that destination receives.'; +const DESTINATION_DESCRIPTION = 'The Destinations page lets you define where messages in this stream should be routed. A stream may have multiple destinations. Note that messages routed to only Data Lake will not count towards License usage, unless subsequently retrieved. On a per-destination basis, filters may be applied to limit the subset of messages that destination receives.'; const SEGMENTS_DETAILS = [ { @@ -159,7 +159,7 @@ const StreamDetails = ({ stream }: Props) => { const navigate = useNavigate(); const { segment } = useQuery(); const [currentSegment, setCurrentSegment] = useState(segment as DetailsSegment || INTAKE_SEGMENT); - const DataWarehouseJobComponent = PluginStore.exports('dataWarehouse')?.[0]?.DataWarehouseJobs; + const DataLakeJobComponent = PluginStore.exports('dataLake')?.[0]?.DataLakeJobs; const [showUpdateModal, setShowUpdateModal] = useState(false); const { indexSets } = useStore(IndexSetsStore); const queryClient = useQueryClient(); @@ -201,7 +201,7 @@ const StreamDetails = ({ stream }: Props) => { return ( <> - {DataWarehouseJobComponent && } + {DataLakeJobComponent && }
    diff --git a/graylog2-web-interface/src/components/streams/StreamDetails/output-filter/FilterRuleList.tsx b/graylog2-web-interface/src/components/streams/StreamDetails/output-filter/FilterRuleList.tsx index 696fd3f3c00f..346734badeed 100644 --- a/graylog2-web-interface/src/components/streams/StreamDetails/output-filter/FilterRuleList.tsx +++ b/graylog2-web-interface/src/components/streams/StreamDetails/output-filter/FilterRuleList.tsx @@ -102,7 +102,7 @@ const FilterRulesList = ({ streamId, destinationType, paginatedFilters, onPagina )}> - Messages which meet the criteria of the following filter rule(s) will not be routed to the {destinationType === 'indexer' ? 'Index Set' : 'Data Warehouse'}. + Messages which meet the criteria of the following filter rule(s) will not be routed to the {destinationType === 'indexer' ? 'Index Set' : 'Data Lake'}. { - const StreamIndexSetDataWarehouseWarning = PluginStore.exports('dataWarehouse')?.[0]?.StreamIndexSetDataWarehouseWarning; + const StreamIndexSetDataLakeWarning = PluginStore.exports('dataLake')?.[0]?.StreamIndexSetDataLakeWarning; return ( @@ -41,7 +41,7 @@ const IndexSetArchivingCell = ({ isArchivingEnabled, streamId }: Props) => { - {StreamIndexSetDataWarehouseWarning && ()} + {StreamIndexSetDataLakeWarning && ()} ); }; diff --git a/graylog2-web-interface/src/components/streams/StreamsOverview/ColumnRenderers.tsx b/graylog2-web-interface/src/components/streams/StreamsOverview/ColumnRenderers.tsx index 8258b50e441f..8dd4f8d3dc9d 100644 --- a/graylog2-web-interface/src/components/streams/StreamsOverview/ColumnRenderers.tsx +++ b/graylog2-web-interface/src/components/streams/StreamsOverview/ColumnRenderers.tsx @@ -32,7 +32,7 @@ import PipelinesCell from './cells/PipelinesCell'; import OutputsCell from './cells/OutputsCell'; import ArchivingsCell from './cells/ArchivingsCell'; -const getStreamDataWarehouseTableElements = PluginStore.exports('dataWarehouse')?.[0]?.getStreamDataWarehouseTableElements; +const getStreamDataLakeTableElements = PluginStore.exports('dataLake')?.[0]?.getStreamDataLakeTableElements; const pipelineRenderer = { pipelines: { renderCell: (_pipeline: any[], stream) => , @@ -70,7 +70,7 @@ const customColumnRenderers = (indexSets: Array, isPipelineColumnPermi renderCell: (_archiving:boolean, stream) => , staticWidth: 100, }, - ...(getStreamDataWarehouseTableElements?.(permissions)?.columnRenderer || {}), + ...(getStreamDataLakeTableElements?.(permissions)?.columnRenderer || {}), }, }); diff --git a/graylog2-web-interface/src/components/streams/StreamsOverview/Constants.ts b/graylog2-web-interface/src/components/streams/StreamsOverview/Constants.ts index bc24df8cba3f..d09d4d89a214 100644 --- a/graylog2-web-interface/src/components/streams/StreamsOverview/Constants.ts +++ b/graylog2-web-interface/src/components/streams/StreamsOverview/Constants.ts @@ -20,10 +20,10 @@ import type Immutable from 'immutable'; import type { Sort } from 'stores/PaginationTypes'; -const getStreamDataWarehouseTableElements = PluginStore.exports('dataWarehouse')?.[0]?.getStreamDataWarehouseTableElements; +const getStreamDataLakeTableElements = PluginStore.exports('dataLake')?.[0]?.getStreamDataLakeTableElements; const getStreamTableElements = (permissions: Immutable.List, isPipelineColumnPermitted: boolean) => { - const streamDataWarehouseTableElements = getStreamDataWarehouseTableElements?.(permissions); + const streamDataLakeTableElements = getStreamDataLakeTableElements?.(permissions); const defaultLayout = { entityTableId: 'streams', @@ -33,7 +33,7 @@ const getStreamTableElements = (permissions: Immutable.List, isPipelineC 'title', 'index_set_title', 'archiving', - ...(streamDataWarehouseTableElements?.attributeName ? [streamDataWarehouseTableElements.attributeName] : []), + ...(streamDataLakeTableElements?.attributeName ? [streamDataLakeTableElements.attributeName] : []), 'rules', ...(isPipelineColumnPermitted ? ['pipelines'] : []), 'outputs', @@ -45,7 +45,7 @@ const getStreamTableElements = (permissions: Immutable.List, isPipelineC 'title', 'index_set_title', 'archiving', - ...(streamDataWarehouseTableElements?.attributeName ? [streamDataWarehouseTableElements.attributeName] : []), + ...(streamDataLakeTableElements?.attributeName ? [streamDataLakeTableElements.attributeName] : []), 'rules', ...(isPipelineColumnPermitted ? ['pipelines'] : []), 'outputs', @@ -60,7 +60,7 @@ const getStreamTableElements = (permissions: Immutable.List, isPipelineC ...(isPipelineColumnPermitted ? [{ id: 'pipelines', title: 'Pipelines' }] : []), { id: 'outputs', title: 'Outputs' }, { id: 'archiving', title: 'Archiving' }, - ...(streamDataWarehouseTableElements?.attributes || []), + ...(streamDataLakeTableElements?.attributes || []), ]; return { diff --git a/graylog2-web-interface/src/components/streams/StreamsOverview/StreamDeleteModal.tsx b/graylog2-web-interface/src/components/streams/StreamsOverview/StreamDeleteModal.tsx index 79f1488d3057..ffa15a2aefd9 100644 --- a/graylog2-web-interface/src/components/streams/StreamsOverview/StreamDeleteModal.tsx +++ b/graylog2-web-interface/src/components/streams/StreamsOverview/StreamDeleteModal.tsx @@ -19,8 +19,8 @@ import { useMemo } from 'react'; import usePluginEntities from 'hooks/usePluginEntities'; import { ConfirmDialog } from 'components/common'; -import useStreamDataWarehouseHasData from 'components/streams/StreamsOverview/hooks/useStreamDataWarehouseHasData'; -import useIsStreamDataWarehouseEnabled from 'components/streams/StreamsOverview/hooks/useIsStreamDataWarehouseEnabled'; +import useStreamDataLakeHasData from 'components/streams/StreamsOverview/hooks/useStreamDataLakeHasData'; +import useIsStreamDataLakeEnabled from 'components/streams/StreamsOverview/hooks/useIsStreamDataLakeEnabled'; type Props = { onDelete: () => void, @@ -30,11 +30,11 @@ type Props = { }; const StreamDeleteModal = ({ onDelete, streamId, streamTitle, onCancel }: Props) => { - const DataWarehouseStreamDeleteWarning = usePluginEntities('dataWarehouse')?.[0]?.DataWarehouseStreamDeleteWarning; - const streamDataWarehouseHasData = useStreamDataWarehouseHasData(streamId, !!DataWarehouseStreamDeleteWarning); - const isDataWarehouseEnable = useIsStreamDataWarehouseEnabled(streamId, !!DataWarehouseStreamDeleteWarning); + const DataLakeStreamDeleteWarning = usePluginEntities('dataLake')?.[0]?.DataLakeStreamDeleteWarning; + const streamDataLakeHasData = useStreamDataLakeHasData(streamId, !!DataLakeStreamDeleteWarning); + const isDataLakeEnable = useIsStreamDataLakeEnabled(streamId, !!DataLakeStreamDeleteWarning); - const shouldShowWarning = useMemo(() => isDataWarehouseEnable || streamDataWarehouseHasData, [isDataWarehouseEnable, streamDataWarehouseHasData]); + const shouldShowWarning = useMemo(() => isDataLakeEnable || streamDataLakeHasData, [isDataLakeEnable, streamDataLakeHasData]); return ( - {shouldShowWarning ? : `Do you really want to remove stream: ${streamTitle}?`} + {shouldShowWarning ? : `Do you really want to remove stream: ${streamTitle}?`} ); }; diff --git a/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useIsStreamDataWarehouseEnabled.ts b/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useIsStreamDataLakeEnabled.ts similarity index 65% rename from graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useIsStreamDataWarehouseEnabled.ts rename to graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useIsStreamDataLakeEnabled.ts index dab63ad418e8..9a1f8854b33e 100644 --- a/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useIsStreamDataWarehouseEnabled.ts +++ b/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useIsStreamDataLakeEnabled.ts @@ -18,14 +18,14 @@ import { useQuery } from '@tanstack/react-query'; import usePluginEntities from 'hooks/usePluginEntities'; -const useIsStreamDataWarehouseEnabled = (streamId: string, enabled: boolean) => { - const { fetchStreamDataWarehouseStatus } = usePluginEntities('dataWarehouse')[0] ?? {}; - const { data: status, isError, isLoading } = useQuery(['data-warehouse-config', streamId, 'enabled'], - () => fetchStreamDataWarehouseStatus(streamId), - { enabled: fetchStreamDataWarehouseStatus && enabled }, +const useIsStreamDataLakeEnabled = (streamId: string, enabled: boolean) => { + const { fetchStreamDataLakeStatus } = usePluginEntities('dataLake')[0] ?? {}; + const { data: status, isError, isLoading } = useQuery(['data-lake-config', streamId, 'enabled'], + () => fetchStreamDataLakeStatus(streamId), + { enabled: fetchStreamDataLakeStatus && enabled }, ); return (isLoading || isError) ? undefined : status?.enabled; }; -export default useIsStreamDataWarehouseEnabled; +export default useIsStreamDataLakeEnabled; diff --git a/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useStreamDataWarehouseHasData.ts b/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useStreamDataLakeHasData.ts similarity index 62% rename from graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useStreamDataWarehouseHasData.ts rename to graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useStreamDataLakeHasData.ts index 97c8a9203355..68b8b90511c9 100644 --- a/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useStreamDataWarehouseHasData.ts +++ b/graylog2-web-interface/src/components/streams/StreamsOverview/hooks/useStreamDataLakeHasData.ts @@ -18,16 +18,16 @@ import { useQuery } from '@tanstack/react-query'; import usePluginEntities from 'hooks/usePluginEntities'; -const useStreamDataWarehouseHasData = (streamId: string, enabled: boolean) => { - const { fetchStreamDataWarehouse } = usePluginEntities('dataWarehouse')[0] ?? {}; - const { data: dataWarehouse, isError, isLoading } = useQuery(['stream', 'data-warehouse', streamId], - () => fetchStreamDataWarehouse(streamId), - { enabled: fetchStreamDataWarehouse && enabled }, +const useStreamDataLakeHasData = (streamId: string, enabled: boolean) => { + const { fetchStreamDataLake } = usePluginEntities('dataLake')[0] ?? {}; + const { data: dataLake, isError, isLoading } = useQuery(['stream', 'data-lake', streamId], + () => fetchStreamDataLake(streamId), + { enabled: fetchStreamDataLake && enabled }, ); return (isLoading || isError) ? undefined : ( - dataWarehouse?.message_count > 1 || dataWarehouse?.restore_history?.length > 0 + dataLake?.message_count > 1 || dataLake?.restore_history?.length > 0 ); }; -export default useStreamDataWarehouseHasData; +export default useStreamDataLakeHasData; From af91915dd9c0848065f58987ac4ec1924a174e6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:22:53 +0100 Subject: [PATCH 56/56] Bump com.fasterxml.jackson:jackson-bom from 2.17.2 to 2.18.2 (#21063) * Bump com.fasterxml.jackson:jackson-bom from 2.17.2 to 2.18.2 Bumps [com.fasterxml.jackson:jackson-bom](https://github.com/FasterXML/jackson-bom) from 2.17.2 to 2.18.2. - [Commits](https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.17.2...jackson-bom-2.18.2) --- updated-dependencies: - dependency-name: com.fasterxml.jackson:jackson-bom dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Remove redundant @JsonCreator annotations --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bernd Ahlers Co-authored-by: Othello Maurer --- .../retention/strategies/ClosingRetentionStrategyConfig.java | 4 +--- .../retention/strategies/DeletionRetentionStrategyConfig.java | 4 +--- .../retention/strategies/NoopRetentionStrategyConfig.java | 4 +--- .../strategies/MessageCountRotationStrategyConfig.java | 4 +--- .../rotation/strategies/SizeBasedRotationStrategyConfig.java | 4 +--- pom.xml | 2 +- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/ClosingRetentionStrategyConfig.java b/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/ClosingRetentionStrategyConfig.java index 538bfeebb489..183e5e66a190 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/ClosingRetentionStrategyConfig.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/ClosingRetentionStrategyConfig.java @@ -20,13 +20,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import jakarta.validation.constraints.Min; import org.graylog.autovalue.WithBeanGetter; import org.graylog2.configuration.ElasticsearchConfiguration; import org.graylog2.plugin.indexer.retention.RetentionStrategyConfig; import org.graylog2.plugin.rest.ValidationResult; -import jakarta.validation.constraints.Min; - import java.util.Set; @JsonAutoDetect @@ -45,7 +44,6 @@ public static ClosingRetentionStrategyConfig create(@JsonProperty(TYPE_FIELD) St return new AutoValue_ClosingRetentionStrategyConfig(type, maxNumberOfIndices); } - @JsonCreator public static ClosingRetentionStrategyConfig create(@JsonProperty("max_number_of_indices") @Min(1) int maxNumberOfIndices) { return new AutoValue_ClosingRetentionStrategyConfig(ClosingRetentionStrategyConfig.class.getCanonicalName(), maxNumberOfIndices); } diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/DeletionRetentionStrategyConfig.java b/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/DeletionRetentionStrategyConfig.java index df07bfdae976..e24094484466 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/DeletionRetentionStrategyConfig.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/DeletionRetentionStrategyConfig.java @@ -20,13 +20,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import jakarta.validation.constraints.Min; import org.graylog.autovalue.WithBeanGetter; import org.graylog2.configuration.ElasticsearchConfiguration; import org.graylog2.plugin.indexer.retention.RetentionStrategyConfig; import org.graylog2.plugin.rest.ValidationResult; -import jakarta.validation.constraints.Min; - import java.util.Set; @JsonAutoDetect @@ -45,7 +44,6 @@ public static DeletionRetentionStrategyConfig create(@JsonProperty(TYPE_FIELD) S return new AutoValue_DeletionRetentionStrategyConfig(type, maxNumberOfIndices); } - @JsonCreator public static DeletionRetentionStrategyConfig create(@JsonProperty("max_number_of_indices") @Min(1) int maxNumberOfIndices) { return new AutoValue_DeletionRetentionStrategyConfig(DeletionRetentionStrategyConfig.class.getCanonicalName(), maxNumberOfIndices); } diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/NoopRetentionStrategyConfig.java b/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/NoopRetentionStrategyConfig.java index b1574b79dcbc..2745308f15c1 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/NoopRetentionStrategyConfig.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/retention/strategies/NoopRetentionStrategyConfig.java @@ -20,13 +20,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import jakarta.validation.constraints.Min; import org.graylog.autovalue.WithBeanGetter; import org.graylog2.configuration.ElasticsearchConfiguration; import org.graylog2.plugin.indexer.retention.RetentionStrategyConfig; import org.graylog2.plugin.rest.ValidationResult; -import jakarta.validation.constraints.Min; - import java.util.Set; @JsonAutoDetect @@ -45,7 +44,6 @@ public static NoopRetentionStrategyConfig create(@JsonProperty(TYPE_FIELD) Strin return new AutoValue_NoopRetentionStrategyConfig(type, maxNumberOfIndices); } - @JsonCreator public static NoopRetentionStrategyConfig create(@JsonProperty("max_number_of_indices") @Min(1) int maxNumberOfIndices) { return new AutoValue_NoopRetentionStrategyConfig(NoopRetentionStrategyConfig.class.getCanonicalName(), maxNumberOfIndices); } diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/MessageCountRotationStrategyConfig.java b/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/MessageCountRotationStrategyConfig.java index 58eb9a82d3e8..01fcc34e3bcd 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/MessageCountRotationStrategyConfig.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/MessageCountRotationStrategyConfig.java @@ -20,11 +20,10 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import jakarta.validation.constraints.Min; import org.graylog.autovalue.WithBeanGetter; import org.graylog2.plugin.indexer.rotation.RotationStrategyConfig; -import jakarta.validation.constraints.Min; - @JsonAutoDetect @AutoValue @WithBeanGetter @@ -40,7 +39,6 @@ public static MessageCountRotationStrategyConfig create(@JsonProperty(TYPE_FIELD return new AutoValue_MessageCountRotationStrategyConfig(type, maxDocsPerIndex); } - @JsonCreator public static MessageCountRotationStrategyConfig create(@JsonProperty("max_docs_per_index") @Min(1) int maxDocsPerIndex) { return create(MessageCountRotationStrategyConfig.class.getCanonicalName(), maxDocsPerIndex); } diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/SizeBasedRotationStrategyConfig.java b/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/SizeBasedRotationStrategyConfig.java index 06e6a441b3b6..f01bce4b41aa 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/SizeBasedRotationStrategyConfig.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/rotation/strategies/SizeBasedRotationStrategyConfig.java @@ -21,11 +21,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.github.joschi.jadconfig.util.Size; import com.google.auto.value.AutoValue; +import jakarta.validation.constraints.Min; import org.graylog.autovalue.WithBeanGetter; import org.graylog2.plugin.indexer.rotation.RotationStrategyConfig; -import jakarta.validation.constraints.Min; - @JsonAutoDetect @AutoValue @WithBeanGetter @@ -41,7 +40,6 @@ public static SizeBasedRotationStrategyConfig create(@JsonProperty(TYPE_FIELD) S return new AutoValue_SizeBasedRotationStrategyConfig(type, maxSize); } - @JsonCreator public static SizeBasedRotationStrategyConfig create(@JsonProperty("max_size") @Min(1) long maxSize) { return create(SizeBasedRotationStrategyConfig.class.getCanonicalName(), maxSize); } diff --git a/pom.xml b/pom.xml index 89982b8fa7ef..ae01696af81d 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ 3.0 8.0.2.Final 3.1.1 - 2.17.2 + 2.18.2 0.15.0 0.10.2 1.3.2