├── .codecov.yml ├── .eclipseformat.xml ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── add-untriaged.yml │ ├── auto-release.yml │ ├── backport.yml │ ├── ci.yml │ ├── delete_backport_branch.yml │ └── maven-publish.yml ├── .gitignore ├── .whitesource ├── ADMINS.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DEVELOPER_GUIDE.md ├── LICENSE.txt ├── MAINTAINERS.md ├── NOTICE ├── README.md ├── RELEASING.md ├── SECURITY.md ├── build-tools └── opensearchplugin-coverage.gradle ├── build.gradle ├── detekt.yml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── release-notes ├── create_release_notes.py ├── opensearch-common-utils.release-notes-1.0.0.0-beta1.md ├── opensearch-common-utils.release-notes-1.0.0.0-rc1.md ├── opensearch-common-utils.release-notes-1.0.0.0.md ├── opensearch-common-utils.release-notes-1.2.0.0.md ├── opensearch-common-utils.release-notes-1.3.0.0.md ├── opensearch-common-utils.release-notes-2.0.0.0-rc1.md ├── opensearch-common-utils.release-notes-2.0.0.0.md ├── opensearch-common-utils.release-notes-2.1.0.0.md ├── opensearch-common-utils.release-notes-2.10.0.0.md ├── opensearch-common-utils.release-notes-2.12.0.0.md ├── opensearch-common-utils.release-notes-2.14.0.0.md ├── opensearch-common-utils.release-notes-2.15.0.0.md ├── opensearch-common-utils.release-notes-2.16.0.0.md ├── opensearch-common-utils.release-notes-2.17.0.0.md ├── opensearch-common-utils.release-notes-2.18.0.0.md ├── opensearch-common-utils.release-notes-2.19.0.0.md ├── opensearch-common-utils.release-notes-2.2.0.0.md ├── opensearch-common-utils.release-notes-2.4.0.0.md ├── opensearch-common-utils.release-notes-2.6.0.0.md ├── opensearch-common-utils.release-notes-2.7.0.0.md ├── opensearch-common-utils.release-notes-2.8.0.0.md ├── opensearch-common-utils.release-notes-2.9.0.0.md ├── opensearch-common-utils.release-notes-3.0.0.0-alpha1.md ├── opensearch-common-utils.release-notes-3.0.0.0-beta1.md └── opensearch-common-utils.release-notes-3.0.0.0.md ├── scripts └── build.sh ├── settings.gradle ├── spotless.license.java └── src ├── main ├── java │ └── org │ │ └── opensearch │ │ └── commons │ │ ├── ConfigConstants.java │ │ ├── InjectSecurity.java │ │ ├── authuser │ │ ├── AuthUserRequestBuilder.java │ │ ├── User.java │ │ └── Utils.java │ │ ├── destination │ │ ├── message │ │ │ ├── LegacyBaseMessage.java │ │ │ ├── LegacyChimeMessage.java │ │ │ ├── LegacyCustomWebhookMessage.java │ │ │ ├── LegacyDestinationType.java │ │ │ ├── LegacyEmailMessage.java │ │ │ ├── LegacySNSMessage.java │ │ │ └── LegacySlackMessage.java │ │ ├── response │ │ │ ├── LegacyBaseResponse.java │ │ │ └── LegacyDestinationResponse.java │ │ └── util │ │ │ └── Util.java │ │ └── rest │ │ ├── SecureRestClientBuilder.java │ │ └── TrustStore.java └── kotlin │ └── org │ └── opensearch │ └── commons │ ├── alerting │ ├── AlertingPluginInterface.kt │ ├── action │ │ ├── AcknowledgeAlertRequest.kt │ │ ├── AcknowledgeAlertResponse.kt │ │ ├── AcknowledgeChainedAlertRequest.kt │ │ ├── AlertingActions.kt │ │ ├── DeleteCommentRequest.kt │ │ ├── DeleteCommentResponse.kt │ │ ├── DeleteMonitorRequest.kt │ │ ├── DeleteMonitorResponse.kt │ │ ├── DeleteWorkflowRequest.kt │ │ ├── DeleteWorkflowResponse.kt │ │ ├── DocLevelMonitorFanOutAction.kt │ │ ├── DocLevelMonitorFanOutRequest.kt │ │ ├── DocLevelMonitorFanOutResponse.kt │ │ ├── GetAlertsRequest.kt │ │ ├── GetAlertsResponse.kt │ │ ├── GetFindingsRequest.kt │ │ ├── GetFindingsResponse.kt │ │ ├── GetMonitorRequest.kt │ │ ├── GetMonitorResponse.kt │ │ ├── GetWorkflowAlertsRequest.kt │ │ ├── GetWorkflowAlertsResponse.kt │ │ ├── GetWorkflowRequest.kt │ │ ├── GetWorkflowResponse.kt │ │ ├── IndexCommentRequest.kt │ │ ├── IndexCommentResponse.kt │ │ ├── IndexMonitorRequest.kt │ │ ├── IndexMonitorResponse.kt │ │ ├── IndexWorkflowRequest.kt │ │ ├── IndexWorkflowResponse.kt │ │ ├── PublishFindingsRequest.kt │ │ ├── SearchCommentRequest.kt │ │ ├── SearchMonitorRequest.kt │ │ └── SubscribeFindingsResponse.kt │ ├── aggregation │ │ └── bucketselectorext │ │ │ ├── BucketSelectorExtAggregationBuilder.kt │ │ │ ├── BucketSelectorExtAggregator.kt │ │ │ ├── BucketSelectorExtFilter.kt │ │ │ └── BucketSelectorIndices.kt │ ├── alerts │ │ └── AlertError.kt │ ├── model │ │ ├── ActionExecutionResult.kt │ │ ├── AggregationResultBucket.kt │ │ ├── Alert.kt │ │ ├── BaseAlert.kt │ │ ├── BucketLevelTrigger.kt │ │ ├── BucketLevelTriggerRunResult.kt │ │ ├── ChainedAlertTrigger.kt │ │ ├── ChainedAlertTriggerRunResult.kt │ │ ├── ChainedMonitorFindings.kt │ │ ├── ClusterMetricsInput.kt │ │ ├── ClusterMetricsTriggerRunResult.kt │ │ ├── Comment.kt │ │ ├── CompositeInput.kt │ │ ├── CorrelationAlert.kt │ │ ├── DataSources.kt │ │ ├── Delegate.kt │ │ ├── DocLevelMonitorInput.kt │ │ ├── DocLevelQuery.kt │ │ ├── DocumentLevelTrigger.kt │ │ ├── DocumentLevelTriggerRunResult.kt │ │ ├── Finding.kt │ │ ├── FindingDocument.kt │ │ ├── FindingWithDocs.kt │ │ ├── IndexExecutionContext.kt │ │ ├── Input.kt │ │ ├── Monitor.kt │ │ ├── MonitorMetadata.kt │ │ ├── MonitorRunResult.kt │ │ ├── NoOpTrigger.kt │ │ ├── QueryLevelTrigger.kt │ │ ├── QueryLevelTriggerRunResult.kt │ │ ├── Schedule.kt │ │ ├── ScheduledJob.kt │ │ ├── SearchInput.kt │ │ ├── Sequence.kt │ │ ├── Table.kt │ │ ├── Trigger.kt │ │ ├── TriggerRunResult.kt │ │ ├── Workflow.kt │ │ ├── WorkflowInput.kt │ │ ├── WorkflowMetadata.kt │ │ ├── WorkflowRunContext.kt │ │ ├── WorkflowRunResult.kt │ │ ├── action │ │ │ ├── Action.kt │ │ │ ├── ActionExecutionPolicy.kt │ │ │ ├── ActionExecutionScope.kt │ │ │ └── Throttle.kt │ │ └── remote │ │ │ └── monitors │ │ │ ├── RemoteDocLevelMonitorInput.kt │ │ │ ├── RemoteMonitorInput.kt │ │ │ └── RemoteMonitorTrigger.kt │ ├── settings │ │ └── SupportedClusterMetricsSettings.kt │ └── util │ │ ├── AlertingException.kt │ │ ├── IndexPatternUtils.kt │ │ └── IndexUtils.kt │ ├── notifications │ ├── NotificationConstants.kt │ ├── NotificationsPluginInterface.kt │ ├── action │ │ ├── BaseResponse.kt │ │ ├── CreateNotificationConfigRequest.kt │ │ ├── CreateNotificationConfigResponse.kt │ │ ├── DeleteNotificationConfigRequest.kt │ │ ├── DeleteNotificationConfigResponse.kt │ │ ├── GetChannelListRequest.kt │ │ ├── GetChannelListResponse.kt │ │ ├── GetNotificationConfigRequest.kt │ │ ├── GetNotificationConfigResponse.kt │ │ ├── GetPluginFeaturesRequest.kt │ │ ├── GetPluginFeaturesResponse.kt │ │ ├── LegacyPublishNotificationRequest.kt │ │ ├── LegacyPublishNotificationResponse.kt │ │ ├── NotificationsActions.kt │ │ ├── SendNotificationRequest.kt │ │ ├── SendNotificationResponse.kt │ │ ├── UpdateNotificationConfigRequest.kt │ │ └── UpdateNotificationConfigResponse.kt │ └── model │ │ ├── Attachment.kt │ │ ├── BaseConfigData.kt │ │ ├── BaseModel.kt │ │ ├── Channel.kt │ │ ├── ChannelList.kt │ │ ├── ChannelMessage.kt │ │ ├── Chime.kt │ │ ├── ConfigType.kt │ │ ├── DeliveryStatus.kt │ │ ├── Email.kt │ │ ├── EmailGroup.kt │ │ ├── EmailRecipient.kt │ │ ├── EmailRecipientStatus.kt │ │ ├── EventSource.kt │ │ ├── EventStatus.kt │ │ ├── HttpMethodType.kt │ │ ├── MethodType.kt │ │ ├── MicrosoftTeams.kt │ │ ├── NotificationConfig.kt │ │ ├── NotificationConfigInfo.kt │ │ ├── NotificationConfigSearchResult.kt │ │ ├── NotificationEvent.kt │ │ ├── SearchResults.kt │ │ ├── SesAccount.kt │ │ ├── SeverityType.kt │ │ ├── Slack.kt │ │ ├── SmtpAccount.kt │ │ ├── Sns.kt │ │ ├── Webhook.kt │ │ ├── XParser.kt │ │ └── config │ │ └── ConfigDataProperties.kt │ ├── replication │ ├── ReplicationPluginInterface.kt │ └── action │ │ ├── ReplicationActions.kt │ │ └── StopIndexReplicationRequest.kt │ └── utils │ ├── EnumHelpers.kt │ ├── EnumParser.kt │ ├── Helpers.kt │ ├── OpenForTesting.kt │ ├── SecureClientWrapper.kt │ ├── TransportHelpers.kt │ ├── ValidationHelpers.kt │ └── XContentHelpers.kt └── test ├── java └── org │ └── opensearch │ └── commons │ ├── ConfigConstantsTest.java │ ├── InjectSecurityTest.java │ ├── authuser │ ├── UserTest.java │ └── UtilsTest.java │ ├── destination │ ├── message │ │ ├── LegacyChimeMessageTest.java │ │ ├── LegacyCustomWebhookMessageTest.java │ │ ├── LegacyEmailMessageTest.java │ │ ├── LegacySNSMessageTest.java │ │ └── LegacySlackMessageTest.java │ ├── response │ │ └── LegacyDestinationResponseTest.java │ └── util │ │ └── UtilTest.java │ └── rest │ ├── IntegrationTests.java │ ├── SecureRestClientBuilderTest.java │ └── TrustStoreTest.java ├── kotlin └── org │ └── opensearch │ └── commons │ ├── alerting │ ├── AlertTests.kt │ ├── AlertingPluginInterfaceTests.kt │ ├── CorrelationAlertTests.kt │ ├── MonitorTests.kt │ ├── TestHelpers.kt │ ├── action │ │ ├── AcknowledgeAlertRequestTests.kt │ │ ├── AcknowledgeAlertResponseTests.kt │ │ ├── AcknowledgeChainedAlertRequestTests.kt │ │ ├── DeleteCommentRequestTests.kt │ │ ├── DeleteCommentResponseTests.kt │ │ ├── DeleteMonitorRequestTests.kt │ │ ├── DeleteWorkflowRequestTests.kt │ │ ├── DeleteWorkflowResponseTests.kt │ │ ├── DocLevelMonitorFanOutRequestTests.kt │ │ ├── DocLevelMonitorFanOutResponseTests.kt │ │ ├── GetAlertsRequestTests.kt │ │ ├── GetAlertsResponseTests.kt │ │ ├── GetFindingsRequestTests.kt │ │ ├── GetFindingsResponseTests.kt │ │ ├── GetMonitorRequestTests.kt │ │ ├── GetMonitorResponseTests.kt │ │ ├── GetWorkflowAlertsRequestTests.kt │ │ ├── GetWorkflowAlertsResponseTests.kt │ │ ├── GetWorkflowRequestTests.kt │ │ ├── GetWorkflowResponseTests.kt │ │ ├── IndexCommentRequestTests.kt │ │ ├── IndexCommentResponseTests.kt │ │ ├── IndexMonitorRequestTests.kt │ │ ├── IndexMonitorResponseTests.kt │ │ ├── IndexWorkflowRequestTests.kt │ │ ├── IndexWorkflowResponseTests.kt │ │ ├── PublishFindingsRequestTests.kt │ │ ├── SearchCommentRequestTests.kt │ │ └── SearchMonitorRequestTests.kt │ ├── alerts │ │ └── AlertErrorTests.kt │ ├── bucketselectorext │ │ └── BucketSelectorExtAggregatorTests.kt │ └── model │ │ ├── BucketLevelTriggerTests.kt │ │ ├── ClusterMetricsInputTests.kt │ │ ├── CompositeInputTests.kt │ │ ├── DataSourcesTests.kt │ │ ├── DocLevelMonitorInputTests.kt │ │ ├── DocumentLevelTriggerTests.kt │ │ ├── FindingTests.kt │ │ ├── MockScheduledJob.kt │ │ ├── MonitorsTests.kt │ │ ├── QueryLevelTriggerTests.kt │ │ ├── ScheduleTest.kt │ │ ├── SearchInputTests.kt │ │ ├── WriteableTests.kt │ │ ├── XContentTestBase.kt │ │ ├── XContentTests.kt │ │ └── action │ │ └── ActionTests.kt │ ├── notifications │ ├── NotificationsPluginInterfaceTests.kt │ ├── action │ │ ├── CreateNotificationConfigRequestTests.kt │ │ ├── CreateNotificationConfigResponseTests.kt │ │ ├── DeleteNotificationConfigRequestTests.kt │ │ ├── DeleteNotificationConfigResponseTests.kt │ │ ├── GetChannelListRequestTests.kt │ │ ├── GetChannelListResponseTests.kt │ │ ├── GetNotificationConfigRequestTests.kt │ │ ├── GetNotificationConfigResponseTests.kt │ │ ├── GetPluginFeaturesRequestTests.kt │ │ ├── GetPluginFeaturesResponseTests.kt │ │ ├── LegacyPublishNotificationRequestTests.kt │ │ ├── LegacyPublishNotificationResponseTests.kt │ │ ├── SendNotificationRequestTests.kt │ │ ├── SendNotificationResponseTests.kt │ │ ├── UpdateNotificationConfigRequestTests.kt │ │ └── UpdateNotificationConfigResponseTests.kt │ └── model │ │ ├── AttachmentTests.kt │ │ ├── ChannelListTests.kt │ │ ├── ChannelMessageTests.kt │ │ ├── ChannelTests.kt │ │ ├── ChimeTests.kt │ │ ├── ConfigTypeTests.kt │ │ ├── DeliveryStatusTests.kt │ │ ├── EmailGroupTests.kt │ │ ├── EmailRecipientStatusTests.kt │ │ ├── EmailRecipientTests.kt │ │ ├── EmailTests.kt │ │ ├── EventSourceTests.kt │ │ ├── EventStatusTests.kt │ │ ├── FilterConfigListTests.kt │ │ ├── FilterConfigTests.kt │ │ ├── MethodTypeTests.kt │ │ ├── MicrosoftTeamsTests.kt │ │ ├── NotificationConfigInfoTests.kt │ │ ├── NotificationConfigSearchResultsTests.kt │ │ ├── NotificationConfigTests.kt │ │ ├── NotificationEventTests.kt │ │ ├── SesAccountTests.kt │ │ ├── SeverityTypeTests.kt │ │ ├── SlackTests.kt │ │ ├── SmtpAccountTests.kt │ │ ├── SnsTests.kt │ │ ├── WebhookTests.kt │ │ └── config │ │ └── ConfigPropertiesTests.kt │ ├── replication │ ├── ReplicationPluginInterfaceTests.kt │ └── action │ │ └── StopIndexReplicationRequestTests.kt │ └── utils │ └── TestHelpers.kt └── resources ├── mockito-extensions └── org.mockito.plugins.MockMaker ├── sample.pem └── test-kirk.jks /.codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | require_ci_to_pass: yes 3 | 4 | coverage: 5 | precision: 2 6 | round: down 7 | range: "75...100" 8 | status: 9 | project: 10 | default: 11 | target: 75% # the required coverage value 12 | threshold: 1% # the leniency in hitting the target -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This should match the owning team set up in https://github.com/orgs/opensearch-project/teams @opensearch-project/common-utils 2 | * @lezzago @qreshi @bowenlan-amzn @rishabhmaurya @getsaurabh02 @eirsep @sbcd90 @AWSHurneyt @engechas @riysaxen-amzn @jowg-amazon 3 | 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug report 3 | about: Create a report to help us improve 4 | title: '[BUG]' 5 | labels: 'bug, untriaged' 6 | assignees: '' 7 | --- 8 | 9 | **What is the bug?** 10 | A clear and concise description of the bug. 11 | 12 | **How can one reproduce the bug?** 13 | Steps to reproduce the behavior: 14 | 1. Go to '...' 15 | 2. Click on '....' 16 | 3. Scroll down to '....' 17 | 4. See error 18 | 19 | **What is the expected behavior?** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **What is your host/environment?** 23 | - OS: [e.g. iOS] 24 | - Version [e.g. 22] 25 | - Plugins 26 | 27 | **Do you have any screenshots?** 28 | If applicable, add screenshots to help explain your problem. 29 | 30 | **Do you have any additional context?** 31 | Add any other context about the problem. 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: OpenSearch Community Support 3 | url: https://discuss.opendistrocommunity.dev/ 4 | about: Please ask and answer questions here. 5 | - name: AWS/Amazon Security 6 | url: https://aws.amazon.com/security/vulnerability-reporting/ 7 | about: Please report security vulnerabilities here. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🎆 Feature request 3 | about: Request a feature in this project 4 | title: '[FEATURE]' 5 | labels: 'enhancement, untriaged' 6 | assignees: '' 7 | --- 8 | **Is your feature request related to a problem?** 9 | A clear and concise description of what the problem is, e.g. _I'm always frustrated when [...]_ 10 | 11 | **What solution would you like?** 12 | A clear and concise description of what you want to happen. 13 | 14 | **What alternatives have you considered?** 15 | A clear and concise description of any alternative solutions or features you've considered. 16 | 17 | **Do you have any additional context?** 18 | Add any other context or screenshots about the feature request here. -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | [Describe what this change achieves] 3 | 4 | ### Related Issues 5 | Resolves #[Issue number to be closed when this PR is merged] 6 | 7 | 8 | ### Check List 9 | - [ ] New functionality includes testing. 10 | - [ ] New functionality has been documented. 11 | - [ ] API changes companion pull request [created](https://github.com/opensearch-project/opensearch-api-specification/blob/main/DEVELOPER_GUIDE.md). 12 | - [ ] Commits are signed per the DCO using `--signoff`. 13 | - [ ] Public documentation issue/PR [created](https://github.com/opensearch-project/documentation-website/issues/new/choose). 14 | 15 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 16 | For more information on following Developer Certificate of Origin and signing off your commits, please check [here](https://github.com/opensearch-project/common-utils/blob/main/CONTRIBUTING.md#developer-certificate-of-origin). 17 | -------------------------------------------------------------------------------- /.github/workflows/add-untriaged.yml: -------------------------------------------------------------------------------- 1 | name: Apply 'untriaged' label during issue lifecycle 2 | 3 | on: 4 | issues: 5 | types: [opened, reopened, transferred] 6 | 7 | jobs: 8 | apply-label: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/github-script@v6 12 | with: 13 | script: | 14 | github.rest.issues.addLabels({ 15 | issue_number: context.issue.number, 16 | owner: context.repo.owner, 17 | repo: context.repo.repo, 18 | labels: ['untriaged'] 19 | }) 20 | -------------------------------------------------------------------------------- /.github/workflows/auto-release.yml: -------------------------------------------------------------------------------- 1 | name: Releases 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | 10 | build: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: write 14 | steps: 15 | - name: GitHub App token 16 | id: github_app_token 17 | uses: tibdex/github-app-token@v1.5.0 18 | with: 19 | app_id: ${{ secrets.APP_ID }} 20 | private_key: ${{ secrets.APP_PRIVATE_KEY }} 21 | installation_id: 22958780 22 | - name: Get tag 23 | id: tag 24 | uses: dawidd6/action-get-tag@v1 25 | - uses: actions/checkout@v2 26 | - uses: ncipollo/release-action@v1 27 | with: 28 | github_token: ${{ steps.github_app_token.outputs.token }} 29 | bodyFile: release-notes/opensearch-common-utils.release-notes-${{steps.tag.outputs.tag}}.md -------------------------------------------------------------------------------- /.github/workflows/backport.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Backport 3 | on: 4 | pull_request_target: 5 | types: 6 | - closed 7 | - labeled 8 | 9 | jobs: 10 | backport: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: write 14 | pull-requests: write 15 | name: Backport 16 | steps: 17 | - name: GitHub App token 18 | id: github_app_token 19 | uses: tibdex/github-app-token@v1.5.0 20 | with: 21 | app_id: ${{ secrets.APP_ID }} 22 | private_key: ${{ secrets.APP_PRIVATE_KEY }} 23 | installation_id: 22958780 24 | 25 | - name: Backport 26 | uses: VachaShah/backport@v2.2.0 27 | with: 28 | github_token: ${{ steps.github_app_token.outputs.token }} 29 | branch_name: backport/backport-${{ github.event.number }} 30 | labels_template: "<%= JSON.stringify([...labels, 'autocut']) %>" 31 | failure_labels: "failed backport" 32 | -------------------------------------------------------------------------------- /.github/workflows/delete_backport_branch.yml: -------------------------------------------------------------------------------- 1 | name: Delete merged branch of the backport PRs 2 | on: 3 | pull_request: 4 | types: 5 | - closed 6 | 7 | jobs: 8 | delete-branch: 9 | runs-on: ubuntu-latest 10 | if: startsWith(github.event.pull_request.head.ref,'backport/') 11 | steps: 12 | - name: Delete merged branch 13 | uses: SvanBoxel/delete-merged-branch@main 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | -------------------------------------------------------------------------------- /.github/workflows/maven-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish snapshots to maven 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - main 8 | - '[0-9]+.[0-9]+' 9 | - '[0-9]+.x' 10 | jobs: 11 | build-and-publish-snapshots: 12 | strategy: 13 | fail-fast: false 14 | if: github.repository == 'opensearch-project/common-utils' 15 | runs-on: ubuntu-latest 16 | 17 | permissions: 18 | id-token: write 19 | contents: write 20 | 21 | steps: 22 | - uses: actions/setup-java@v3 23 | with: 24 | distribution: temurin # Temurin is a distribution of adoptium 25 | java-version: 21 26 | - uses: actions/checkout@v3 27 | - uses: aws-actions/configure-aws-credentials@v1 28 | with: 29 | role-to-assume: ${{ secrets.PUBLISH_SNAPSHOTS_ROLE }} 30 | aws-region: us-east-1 31 | - name: publish snapshots to maven 32 | run: | 33 | export SONATYPE_USERNAME=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-username --query SecretString --output text) 34 | export SONATYPE_PASSWORD=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text) 35 | echo "::add-mask::$SONATYPE_USERNAME" 36 | echo "::add-mask::$SONATYPE_PASSWORD" 37 | ./gradlew publishShadowPublicationToSnapshotsRepository 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | buildSrc/libs 2 | .gradle/ 3 | build/ 4 | .idea/ 5 | !.idea/codeStyles/codeStyleConfig.xml 6 | .DS_Store 7 | *.log 8 | out/ 9 | .classpath 10 | .project 11 | .settings 12 | .vscode 13 | bin/ 14 | -------------------------------------------------------------------------------- /.whitesource: -------------------------------------------------------------------------------- 1 | { 2 | "scanSettings": { 3 | "configMode": "AUTO", 4 | "configExternalURL": "", 5 | "projectToken": "", 6 | "baseBranches": [] 7 | }, 8 | "checkRunSettings": { 9 | "vulnerableCheckRunConclusionLevel": "failure", 10 | "displayMode": "diff" 11 | }, 12 | "issueSettings": { 13 | "minSeverityLevel": "LOW" 14 | } 15 | } -------------------------------------------------------------------------------- /ADMINS.md: -------------------------------------------------------------------------------- 1 | ## Admins 2 | 3 | | Admin | GitHub ID | Affiliation | 4 | | --------------- | --------------------------------------- | ----------- | 5 | | Henri Yandell | [hyandell](https://github.com/hyandell) | Amazon | 6 | 7 | [This document](https://github.com/opensearch-project/.github/blob/main/ADMINS.md) explains what admins do in this repo. and how they should be doing it. If you're interested in becoming a maintainer, see [MAINTAINERS](MAINTAINERS.md). If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md). 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | This code of conduct applies to all spaces provided by the OpenSource project including in code, documentation, issue trackers, mailing lists, chat channels, wikis, blogs, social media and any other communication channels used by the project. 2 | 3 | **Our open source communities endeavor to:** 4 | 5 | * Be Inclusive: We are committed to being a community where everyone can join and contribute. This means using inclusive and welcoming language. 6 | * Be Welcoming: We are committed to maintaining a safe space for everyone to be able to contribute. 7 | * Be Respectful: We are committed to encouraging differing viewpoints, accepting constructive criticism and work collaboratively towards decisions that help the project grow. Disrespectful and unacceptable behavior will not be tolerated. 8 | * Be Collaborative: We are committed to supporting what is best for our community and users. When we build anything for the benefit of the project, we should document the work we do and communicate to others on how this affects their work. 9 | 10 | **Our Responsibility. As contributors, members, or bystanders we each individually have the responsibility to behave professionally and respectfully at all times. Disrespectful and unacceptable behaviors include, but are not limited to:** 11 | 12 | * The use of violent threats, abusive, discriminatory, or derogatory language; 13 | * Offensive comments related to gender, gender identity and expression, sexual orientation, disability, mental illness, race, political or religious affiliation; 14 | * Posting of sexually explicit or violent content; 15 | * The use of sexualized language and unwelcome sexual attention or advances; 16 | * Public or private harassment of any kind; 17 | * Publishing private information, such as physical or electronic address, without permission; 18 | * Other conduct which could reasonably be considered inappropriate in a professional setting; 19 | * Advocating for or encouraging any of the above behaviors. 20 | * Enforcement and Reporting Code of Conduct Issues: 21 | 22 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported. [Contact us](mailto:opensource-codeofconduct@amazon.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. -------------------------------------------------------------------------------- /DEVELOPER_GUIDE.md: -------------------------------------------------------------------------------- 1 | - [Developer Guide](#developer-guide) 2 | - [Forking and Cloning](#forking-and-cloning) 3 | - [Install Prerequisites](#install-prerequisites) 4 | - [JDK 21](#jdk-21) 5 | - [Building](#building) 6 | - [Using IntelliJ IDEA](#using-intellij-idea) 7 | - [Submitting Changes](#submitting-changes) 8 | 9 | ## Developer Guide 10 | 11 | So you want to contribute code to this project? Excellent! We're glad you're here. Here's what you need to do. 12 | 13 | ### Forking and Cloning 14 | 15 | Fork this repository on GitHub, and clone locally with `git clone`. 16 | 17 | ### Install Prerequisites 18 | 19 | #### JDK 21 20 | 21 | OpenSearch components build using Java 21 at a minimum. This means you must have a JDK 21 installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK 21 installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-21`. 22 | 23 | ### Building 24 | 25 | To build from the command line, use `./gradlew`. 26 | 27 | ``` 28 | ./gradlew clean 29 | ./gradlew build 30 | ./gradlew publishToMavenLocal 31 | ``` 32 | 33 | ### Using IntelliJ IDEA 34 | 35 | Launch Intellij IDEA, choose **Import Project**, and select the `settings.gradle` file in the root of this package. 36 | 37 | ### Submitting Changes 38 | 39 | See [CONTRIBUTING](CONTRIBUTING.md). 40 | 41 | ### Backport 42 | 43 | - [Link to backport documentation](https://github.com/opensearch-project/opensearch-plugins/blob/main/BACKPORT.md) 44 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | This document contains a list of maintainers in this repo. See [opensearch-project/.github/RESPONSIBILITIES.md](https://github.com/opensearch-project/.github/blob/main/RESPONSIBILITIES.md#maintainer-responsibilities) that explains what the role of maintainer means, what maintainers do in this and other repos, and how they should be doing it. If you're interested in contributing, and becoming a maintainer, see [CONTRIBUTING](CONTRIBUTING.md). 4 | 5 | ## Current Maintainers 6 | 7 | | Maintainer | GitHub ID | Affiliation | 8 | |-----------------------|---------------------------------------------------|-------------| 9 | | Ashish Agrawal | [lezzago](https://github.com/lezzago) | Amazon | 10 | | Mohammad Qureshi | [qreshi](https://github.com/qreshi) | Amazon | 11 | | Bowen Lan | [bowenlan-amzn](https://github.com/bowenlan-amzn) | Amazon | 12 | | Rishabh Maurya | [rishabhmaurya](https://github.com/rishabhmaurya) | Amazon | 13 | | Saurabh Singh | [getsaurabh02](https://github.com/getsaurabh02) | Amazon | 14 | | Surya Sashank Nistala | [eirsep](https://github.com/eirsep) | Amazon | 15 | | Subhobrata Dey | [sbcd90](https://github.com/sbcd90) | Amazon | 16 | | Thomas Hurney | [AWSHurneyt](https://github.com/AWSHurneyt) | Amazon | 17 | | Chase Engelbrecht | [engechas](https://github.com/engechas) | Amazon | 18 | | Riya Saxena | [riysaxen-amzn](https://github.com/riysaxen-amzn) | Amazon | 19 | | Joanne Wang | [jowg-amazon](https://github.com/jowg-amazon) | Amazon | 20 | 21 | 22 | ## Emeritus 23 | 24 | | Maintainer | GitHub ID | Affiliation | 25 | |---------------|---------------------------------------------------|-------------| 26 | | Annie Lee | [leeyun-amzn](https://github.com/leeyun-amzn) | Amazon | 27 | | Sriram Kosuri | [skkosuri-amzn](https://github.com/skkosuri-amzn) | Amazon | 28 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | OpenSearch (https://opensearch.org/) 2 | Copyright OpenSearch Contributors 3 | 4 | This product includes software developed by 5 | Elasticsearch (http://www.elastic.co). 6 | Copyright 2009-2018 Elasticsearch 7 | 8 | This product includes software developed by The Apache Software 9 | Foundation (http://www.apache.org/). 10 | 11 | This product includes software developed by 12 | Joda.org (http://www.joda.org/). 13 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | This project follows the [OpenSearch release process](https://github.com/opensearch-project/.github/blob/main/RELEASING.md). -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Reporting a Vulnerability 2 | 3 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. Please do **not** create a public GitHub issue. -------------------------------------------------------------------------------- /build-tools/opensearchplugin-coverage.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | /** 7 | * OpenSearch Plugin build tools don't work with the Gradle Jacoco Plugin to report coverage out of the box. 8 | * https://github.com/elastic/elasticsearch/issues/28867. 9 | * 10 | * This code sets up coverage reporting manually for OpenSearch plugin tests. This is complicated because: 11 | * 1. The OpenSearch integTest Task doesn't implement Gradle's JavaForkOptions so we have to manually start the jacoco agent with the test JVM 12 | * 2. The cluster nodes are stopped using 'kill -9' which means jacoco can't dump it's execution output to a file on VM shutdown 13 | * 3. The Java Security Manager prevents JMX from writing execution output to the file. 14 | * 15 | * To workaround these we start the cluster with jmx enabled and then use Jacoco's JMX MBean to get the execution data before the 16 | * cluster is stopped and dump it to a file. Luckily our current security policy seems to allow this. This will also probably 17 | * break if there are multiple nodes in the integTestCluster. But for now... it sorta works. 18 | */ 19 | apply plugin: 'jacoco' 20 | 21 | // Get gradle to generate the required jvm agent arg for us using a dummy tasks of type Test. Unfortunately Elastic's 22 | // testing tasks don't derive from Test so the jacoco plugin can't do this automatically. 23 | def jacocoDir = "${buildDir}/jacoco" 24 | task dummyTest(type: Test) { 25 | enabled = false 26 | workingDir = file("/") // Force absolute path to jacoco agent jar 27 | jacoco { 28 | destinationFile = file("${jacocoDir}/test.exec") 29 | destinationFile.parentFile.mkdirs() 30 | jmx = true 31 | } 32 | } 33 | 34 | jacocoTestReport { 35 | dependsOn test 36 | executionData dummyTest.jacoco.destinationFile 37 | getSourceDirectories().from(sourceSets.main.allSource) 38 | getClassDirectories().from(sourceSets.main.output) 39 | reports { 40 | html.required = true // human readable 41 | xml.required = true // for coverlay 42 | } 43 | } 44 | 45 | project.gradle.projectsEvaluated { 46 | jacocoTestReport.dependsOn test 47 | } 48 | 49 | check.dependsOn jacocoTestReport 50 | -------------------------------------------------------------------------------- /detekt.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # 3 | # Copyright OpenSearch Contributors 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | style: 8 | ForbiddenComment: 9 | active: false 10 | LoopWithTooManyJumpStatements: 11 | maxJumpCount: 4 12 | MaxLineLength: 13 | maxLineLength: 200 14 | ThrowsCount: 15 | active: true 16 | max: 10 17 | ReturnCount: 18 | active: true 19 | max: 10 20 | UtilityClassWithPublicConstructor: 21 | active: false 22 | 23 | empty-blocks: 24 | EmptyCatchBlock: 25 | excludes: ['**/test/**'] 26 | 27 | exceptions: 28 | SwallowedException: 29 | excludes: ['**/test/**'] 30 | ignoredExceptionTypes: 31 | - 'ZoneRulesException' 32 | - 'DateTimeException' 33 | 34 | complexity: 35 | LargeClass: 36 | excludes: ['**/test/**'] 37 | LongMethod: 38 | excludes: ['**/test/**'] 39 | threshold: 110 40 | LongParameterList: 41 | excludes: ['**/test/**'] 42 | constructorThreshold: 8 43 | ComplexMethod: 44 | threshold: 27 45 | NestedBlockDepth: 46 | threshold: 10 47 | 48 | naming: 49 | ObjectPropertyNaming: 50 | constantPattern: '[_A-Za-z][_A-Za-z0-9]*' 51 | 52 | performance: 53 | SpreadOperator: 54 | active: false 55 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opensearch-project/common-utils/3e28c9218fb1229a49194a5850902b85697d770f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26 8 | -------------------------------------------------------------------------------- /release-notes/create_release_notes.py: -------------------------------------------------------------------------------- 1 | # raw note means the draft release content copied down which is generated by Github workflow 2 | # this script helps add the URLs to all PR and have the right release note filename 3 | 4 | import os 5 | import sys 6 | import fileinput 7 | import re 8 | 9 | link_prefix = "https://github.com/opensearch-project/common-utils/pull/" 10 | searchExp = re.compile("([\(\[]).*?([\)\]])") 11 | 12 | current_date = raw_input("what day is today (e.g. 2020-06-29): ") 13 | file_path = raw_input("Path to raw note file (e.g., note.md): ") 14 | plugin_name = "common-utils" 15 | plugin_version = raw_input('Plugin version (x.x.x.x): ') 16 | 17 | app = 'OpenSearch' 18 | 19 | app_version = raw_input(app + ' compatibility version (x.x.x): ') 20 | 21 | for line in fileinput.input(file_path, inplace=True): 22 | # Add title and OpenSearch/OpenSearchDashboards compatibility 23 | if fileinput.isfirstline(): 24 | line = "## Version " + plugin_version + " " + current_date + "\n\n" \ 25 | "Compatible with " + app + " " + app_version + "\n" 26 | 27 | # Add link to PRs 28 | if '*' in line: 29 | start = line.find('#') + 1 30 | end = line.find(')', start) 31 | pr_num = line[start:end] 32 | line = re.sub(searchExp, "([#" + pr_num + 33 | "](" + link_prefix + pr_num + "))", line) 34 | sys.stdout.write(line) 35 | 36 | new_file_path = "opensearch-" + plugin_name + ".release-notes-" + \ 37 | plugin_version + ".md" 38 | os.rename(file_path, new_file_path) 39 | 40 | print('\n\nDone!\n') -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-1.0.0.0-beta1.md: -------------------------------------------------------------------------------- 1 | ## Version 1.0.0.0-beta1 2021-04-26 2 | 3 | Compatible with OpenSearch 1.0.0 4 | 5 | ### Infrastructure 6 | * Updated templates from .github ([#7](https://github.com/opensearch-project/common-utils/pull/7)) 7 | * Publish to maven local and add CI ([#8](https://github.com/opensearch-project/common-utils/pull/8)) 8 | * Update test workflow for alpha1 ([#9](https://github.com/opensearch-project/common-utils/pull/9)) 9 | * Update test workflow and publish beta1 ([#14](https://github.com/opensearch-project/common-utils/pull/14)) 10 | ### Documentation 11 | * Update licenses ([#3](https://github.com/opensearch-project/common-utils/pull/3)) 12 | * Add new license header ([#5](https://github.com/opensearch-project/common-utils/pull/5)) 13 | * Update spotless license file ([#11](https://github.com/opensearch-project/common-utils/pull/11)) 14 | * Add release notes and script to generate release notes ([#16](https://github.com/opensearch-project/common-utils/pull/16)) 15 | ### Refactoring 16 | * Renaming lingering strings to OpenSearch ([#2](https://github.com/opensearch-project/common-utils/pull/2)) 17 | * Update version to 1.0.0.0-alpha2 ([#15](https://github.com/opensearch-project/common-utils/pull/15)) 18 | * Update version to 1.0.0.0-beta1 ([#17](https://github.com/opensearch-project/common-utils/pull/17)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-1.0.0.0-rc1.md: -------------------------------------------------------------------------------- 1 | ## Version 1.0.0.0-rc1 2021-05-25 2 | 3 | Compatible with OpenSearch 1.0.0-rc1 4 | 5 | ### Refactoring 6 | * Rename namespaces from OpenDistro to OpenSearch ([#20](https://github.com/opensearch-project/common-utils/pull/20)) 7 | * Rename classes, variables, methods to incorporate OpenSearch ([#21](https://github.com/opensearch-project/common-utils/pull/21)) 8 | * Rename remaining identifiers to OpenSearch ([#23](https://github.com/opensearch-project/common-utils/pull/23)) 9 | * Rename consts as per changes in security plugin ([#25](https://github.com/opensearch-project/common-utils/pull/25)) 10 | * Move workflow tags to rc1 ([#26](https://github.com/opensearch-project/common-utils/pull/26)) 11 | 12 | ### Documentation 13 | * Update issue template with multiple labels ([#18](https://github.com/opensearch-project/common-utils/pull/18)) 14 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-1.0.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 1.0.0.0 2021-07-01 2 | 3 | Compatible with OpenSearch 1.0.0 4 | 5 | ### Enhancements 6 | 7 | * Notification plugin interface and models ([#31](https://github.com/opensearch-project/common-utils/pull/31)) 8 | 9 | ### Infrastructure 10 | 11 | * Support for kotlin and JUnit5 with mockito ([#29](https://github.com/opensearch-project/common-utils/pull/29)) 12 | * Removing Kotlin Runtime library bundled into library ([#30](https://github.com/opensearch-project/common-utils/pull/30)) 13 | * Bump to version 1.0.0.0 #34 ([#34](https://github.com/opensearch-project/common-utils/pull/34)) 14 | 15 | ### Documentation 16 | 17 | * Update OpenSearch branch to 1.0 ([#28](https://github.com/opensearch-project/common-utils/pull/28)) 18 | * Cleanup READMEs. ([#32](https://github.com/opensearch-project/common-utils/pull/32)) 19 | 20 | ### Maintainence 21 | 22 | * Update issue template with multiple labels ([#18](https://github.com/opensearch-project/common-utils/pull/18)) 23 | * Rename namespaces from OpenDistro to OpenSearch ([#20](https://github.com/opensearch-project/common-utils/pull/20)) 24 | * Rename classes, variables, methods to incorporate OpenSearch ([#21](https://github.com/opensearch-project/common-utils/pull/21)) 25 | * Rename remaining identifiers to OpenSearch ([#23](https://github.com/opensearch-project/common-utils/pull/23)) 26 | * Version changed to rc1 #24 ([#24](https://github.com/opensearch-project/common-utils/pull/24)) 27 | * Rename consts as per changes in security plugin ([#25](https://github.com/opensearch-project/common-utils/pull/25)) 28 | * Move workflow tags to rc1 ([#26](https://github.com/opensearch-project/common-utils/pull/26)) 29 | * Add rc1 release notes ([#27](https://github.com/opensearch-project/common-utils/pull/27)) 30 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-1.2.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 1.2.0.0 2021-11-05 2 | 3 | Compatible with OpenSearch 1.2.0 4 | 5 | ### Infrastructure 6 | 7 | * Updates common-utils version to 1.2 ([#77](https://github.com/opensearch-project/common-utils/pull/77)) 8 | * Update maven publication to include cksums. ([#91](https://github.com/opensearch-project/common-utils/pull/91)) 9 | 10 | ### Documentation 11 | 12 | * Add themed logo to README ([#41](https://github.com/opensearch-project/common-utils/pull/41)) 13 | * Update copyright notice ([#90](https://github.com/opensearch-project/common-utils/pull/90)) 14 | * Add release notes for version 1.2.0.0 ([#92](https://github.com/opensearch-project/common-utils/pull/92)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-1.3.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 1.3.0.0 2022-03-11 2 | 3 | Compatible with OpenSearch 1.3.0 4 | 5 | ### Infrastructure 6 | 7 | * Updates common-utils version to 1.3 ([#99](https://github.com/opensearch-project/common-utils/pull/99)) 8 | * Update build.sh script to include optional platform param. ([#95](https://github.com/opensearch-project/common-utils/pull/95)) 9 | * Update copyright notice and add DCO check workflow. ([#94](https://github.com/opensearch-project/common-utils/pull/94)) 10 | 11 | ### Documentation 12 | 13 | * Update copyright headers ([#117](https://github.com/opensearch-project/common-utils/pull/117)) 14 | * Add release notes for version 1.3.0.0 ([#132](https://github.com/opensearch-project/common-utils/pull/132)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.0.0.0-rc1.md: -------------------------------------------------------------------------------- 1 | ## Version 2.0.0.0-rc1 2022-04-25 2 | 3 | Compatible with OpenSearch 2.0.0-rc1 4 | 5 | ### Enhancements 6 | 7 | * Add SQL/PPL transport request/response models for SQL plugin ([#155](https://github.com/opensearch-project/common-utils/pull/155)) 8 | * Support sending email message via Notifications pass-through API ([#158](https://github.com/opensearch-project/common-utils/pull/158)) 9 | 10 | ### Infrastructure 11 | 12 | * Upgrade gradle artifacts to 7.3.3 ([#135](https://github.com/opensearch-project/common-utils/pull/135) 13 | * Update common-utils to depend on the OpenSearch repositories plugin ([#137](https://github.com/opensearch-project/common-utils/pull/137)) 14 | * Add sign-off option for version workflow PR ([#143](https://github.com/opensearch-project/common-utils/pull/143)) 15 | * Add qualifier default to alpha1 in build.gradle ([#151](https://github.com/opensearch-project/common-utils/pull/151)) 16 | * Update issue templates from github for bugs and features ([#154](https://github.com/opensearch-project/common-utils/pull/154)) 17 | * Remove support for JDK 14 ([#159](https://github.com/opensearch-project/common-utils/pull/159)) 18 | 19 | ### Refactoring 20 | 21 | * Remove feature and feature_list usage for Notifications ([#136](https://github.com/opensearch-project/common-utils/pull/136)) 22 | * Rename references for Get Channels API for Notifications ([#140](https://github.com/opensearch-project/common-utils/pull/140)) 23 | * Remove allowedConfigFeatureList from GetPluginFeaturesResponse for Notifications ([#144](https://github.com/opensearch-project/common-utils/pull/144)) 24 | * Remove NotificationEvent Request, Response and SearchResults ([#153](https://github.com/opensearch-project/common-utils/pull/153)) 25 | * Add NotificationEvent to SendNotificationResponse and Removal of NotificationID ([#156](https://github.com/opensearch-project/common-utils/pull/156)) 26 | 27 | ### Documentation 28 | 29 | * Add release notes for version 2.0.0-rc1 ([#162](https://github.com/opensearch-project/common-utils/pull/162)) 30 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.0.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.0.0.0 2022-05-18 2 | 3 | Compatible with OpenSearch 2.0.0 4 | 5 | ### Enhancements 6 | 7 | * Add SQL/PPL transport request/response models for SQL plugin ([#155](https://github.com/opensearch-project/common-utils/pull/155)) 8 | * Support sending email message via Notifications pass-through API ([#158](https://github.com/opensearch-project/common-utils/pull/158)) 9 | 10 | ### Infrastructure 11 | 12 | * Upgrade gradle artifacts to 7.3.3 ([#135](https://github.com/opensearch-project/common-utils/pull/135) 13 | * Update common-utils to depend on the OpenSearch repositories plugin ([#137](https://github.com/opensearch-project/common-utils/pull/137)) 14 | * Add sign-off option for version workflow PR ([#143](https://github.com/opensearch-project/common-utils/pull/143)) 15 | * Add qualifier default to alpha1 in build.gradle ([#151](https://github.com/opensearch-project/common-utils/pull/151)) 16 | * Update issue templates from github for bugs and features ([#154](https://github.com/opensearch-project/common-utils/pull/154)) 17 | * Remove support for JDK 14 ([#159](https://github.com/opensearch-project/common-utils/pull/159)) 18 | * Remove RC1 as the qualifier from Common Utils ([#168](https://github.com/opensearch-project/common-utils/pull/168)) 19 | 20 | ### Refactoring 21 | 22 | * Remove feature and feature_list usage for Notifications ([#136](https://github.com/opensearch-project/common-utils/pull/136)) 23 | * Rename references for Get Channels API for Notifications ([#140](https://github.com/opensearch-project/common-utils/pull/140)) 24 | * Remove allowedConfigFeatureList from GetPluginFeaturesResponse for Notifications ([#144](https://github.com/opensearch-project/common-utils/pull/144)) 25 | * Remove NotificationEvent Request, Response and SearchResults ([#153](https://github.com/opensearch-project/common-utils/pull/153)) 26 | * Add NotificationEvent to SendNotificationResponse and Removal of NotificationID ([#156](https://github.com/opensearch-project/common-utils/pull/156)) 27 | * Change BaseModel to extend ToXContentObject instead of ToXContent ([#173](https://github.com/opensearch-project/common-utils/pull/173)) 28 | 29 | ### Documentation 30 | 31 | * Add release notes for version 2.0.0-rc1 ([#162](https://github.com/opensearch-project/common-utils/pull/162)) 32 | * Add release notes for version 2.0.0.0 ([#177](https://github.com/opensearch-project/common-utils/pull/177)) 33 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.1.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.1.0.0 2022-07-06 2 | 3 | Compatible with OpenSearch 2.1.0 4 | 5 | ### Maintenance 6 | * Upgrade gradle to 7.4.2. ([#191](https://github.com/opensearch-project/common-utils/pull/191)) 7 | * Bump up the version to 2.1. ([#190](https://github.com/opensearch-project/common-utils/pull/190)) 8 | 9 | ### Documentation 10 | * Added 2.1 release notes. ([#194](https://github.com/opensearch-project/common-utils/pull/194)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.10.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.10.0.0 2023-08-31 2 | 3 | Compatible with OpenSearch 2.10.0 4 | 5 | ### Maintenance 6 | * Upgrade the backport workflow ([#487](https://github.com/opensearch-project/common-utils/pull/487)) 7 | * Updates demo certs used in rest tests ([#518](https://github.com/opensearch-project/common-utils/pull/518)) 8 | 9 | ### Feature 10 | * common utils to support Microsoft teams in notifications ([#428](https://github.com/opensearch-project/common-utils/pull/428)) 11 | * support list of monitor ids in Chained Monitor Findings ([#514](https://github.com/opensearch-project/common-utils/pull/514)) 12 | 13 | ### Documentation 14 | * Added 2.10.0.0 release notes ([#531](https://github.com/opensearch-project/common-utils/pull/531)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.12.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.12.0.0 2023-02-06 2 | 3 | Compatible with OpenSearch 2.12.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.12.0-SNAPSHOT ([#545](https://github.com/opensearch-project/common-utils/pull/545)) 7 | * Onboard prod jenkins docker image to github actions ([#557](https://github.com/opensearch-project/common-utils/pull/557)) 8 | * Update Gradle to 8.4 ([#560](https://github.com/opensearch-project/common-utils/pull/560)) 9 | * Add Java 11/17/21 matrix for build, test and integration checks ([#561](https://github.com/opensearch-project/common-utils/pull/561)) 10 | * changed all usages of 'admin' as a password to something different ([#581](https://github.com/opensearch-project/common-utils/pull/581)) 11 | * Update dependency com.pinterest:ktlint to 0.47.1 and fix CVE-2023-6378 ([#585](https://github.com/opensearch-project/common-utils/pull/585)) 12 | 13 | ### Enhancement 14 | * add 'fields' parameter in doc level query object. ([#546](https://github.com/opensearch-project/common-utils/pull/546)) 15 | * add fields param in toxcontent() for doc level query ([#549](https://github.com/opensearch-project/common-utils/pull/549)) 16 | * Add User.isAdminDn to User class ([#547](https://github.com/opensearch-project/common-utils/pull/547)) 17 | 18 | ### Refactor 19 | * Move get monitor and search monitor action / request / responses to common-utils ([#566](https://github.com/opensearch-project/common-utils/pull/566)) 20 | 21 | # Features 22 | * Implemented cross-cluster monitor support ([#584](https://github.com/opensearch-project/common-utils/pull/584)) 23 | 24 | ### Documentation 25 | * Added 2.12.0.0 release notes ([#585](https://github.com/opensearch-project/common-utils/pull/585)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.14.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.14.0.0 2024-04-30 2 | 3 | Compatible with OpenSearch 2.14.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.14.0-SNAPSHOT ([#625](https://github.com/opensearch-project/common-utils/pull/625)) 7 | 8 | ### Refactor 9 | * Obfuscate ip addresses in alert error message ([#511](https://github.com/opensearch-project/common-utils/pull/511)) 10 | * Change doc level query name validation ([#630](https://github.com/opensearch-project/common-utils/pull/630)) 11 | * Added validation for the new clusters field. ([#633](https://github.com/opensearch-project/common-utils/pull/633)) 12 | * Wrapped URI syntax exception in IllegalArgument exception. ([#645](https://github.com/opensearch-project/common-utils/pull/645)) 13 | 14 | ### Documentation 15 | * Added 2.14.0.0 release notes. ([#648](https://github.com/opensearch-project/common-utils/pull/648)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.15.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.15.0.0 2024-06-10 2 | 3 | Compatible with OpenSearch 2.15.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.15.0-SNAPSHOT ([#651](https://github.com/opensearch-project/common-utils/pull/651)) 7 | 8 | 9 | ### Features 10 | * CorrelationAlert model added ([#631](https://github.com/opensearch-project/common-utils/pull/631), [#679](https://github.com/opensearch-project/common-utils/pull/679)) 11 | 12 | ### Bug Fixes 13 | * Bug fixes for correlation Alerts ([#670](https://github.com/opensearch-project/common-utils/pull/670), [#680](https://github.com/opensearch-project/common-utils/pull/680)) 14 | 15 | ### Enhancements 16 | * Add start_time and end_time filters to GetAlertsRequest. ([#655](https://github.com/opensearch-project/common-utils/pull/655)) 17 | * Added new models for Alerting Comments ([#663](https://github.com/opensearch-project/common-utils/pull/663), [#671](https://github.com/opensearch-project/common-utils/pull/671), [#674](https://github.com/opensearch-project/common-utils/pull/674) [#678](https://github.com/opensearch-project/common-utils/pull/678)) 18 | 19 | ### Documentation 20 | * Added 2.15.0.0 release notes. ([#672](https://github.com/opensearch-project/common-utils/pull/672)) 21 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.16.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.16.0.0 2024-07-25 2 | 3 | Compatible with OpenSearch 2.16.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.16.0-SNAPSHOT ([#688](https://github.com/opensearch-project/common-utils/pull/688)) 7 | 8 | ### Enhancements 9 | * [Backport 2.x] Add support for remote monitors ([#694](https://github.com/opensearch-project/common-utils/pull/694)) 10 | 11 | ### Documentation 12 | * Added 2.16.0.0 release notes. ([#700](https://github.com/opensearch-project/common-utils/pull/700)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.17.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.17.0.0 2024-09-03 2 | 3 | Compatible with OpenSearch 2.17.0 4 | 5 | ### Maintenance 6 | * Fixed Common-Utils CIs: ([#703](https://github.com/opensearch-project/common-utils/pull/703)) 7 | 8 | ### Bug Fixes 9 | * Added missing ctx variables ([#710](https://github.com/opensearch-project/common-utils/pull/710)) 10 | * Changed the names of security actions for Alerting Comments feature ([#724](https://github.com/opensearch-project/common-utils/pull/724)) 11 | 12 | ### Enhancements 13 | * Updated pull request template to include API spec change in checklist ([#696](https://github.com/opensearch-project/common-utils/pull/696)) 14 | 15 | ### Documentation 16 | * Added 2.17.0.0 release notes ([#727](https://github.com/opensearch-project/common-utils/pull/727)) 17 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.18.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.18.0.0 2024-10-28 2 | 3 | Compatible with OpenSearch 2.18.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.18.0-SNAPSHOT ([#729](https://github.com/opensearch-project/common-utils/pull/729)) 7 | * Update Gradle to 8.10.2 ([#746](https://github.com/opensearch-project/common-utils/pull/746)) 8 | 9 | ### Enhancements 10 | * changes to support dynamic deletion of doc-level monitor query indices ([#734](https://github.com/opensearch-project/common-utils/pull/734)) 11 | 12 | ### Documentation 13 | * Added 2.18.0.0 release notes. ([#750](https://github.com/opensearch-project/common-utils/pull/750)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.19.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.19.0.0 2025-02-03 2 | 3 | Compatible with OpenSearch 2.19.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.19.0-SNAPSHOT ([#749](https://github.com/opensearch-project/common-utils/pull/749)) 7 | * Remove version workflow ([#455](https://github.com/opensearch-project/common-utils/pull/455)) 8 | * Updates sample cert and admin keystore ([#598](https://github.com/opensearch-project/common-utils/pull/598)) 9 | * Fix 2.x branch github CI workflow. ([#777](https://github.com/opensearch-project/common-utils/pull/777)) 10 | 11 | ### Bug Fixes 12 | * Fix bucket selector aggregation writeable name. ([#773](https://github.com/opensearch-project/common-utils/pull/773)) 13 | 14 | ### Refactoring 15 | * add should_create_single_alert_for_findings field to security-analytics ([#757](https://github.com/opensearch-project/common-utils/pull/757)) 16 | * Monitor model changed to add an optional fanoutEnabled field ([#758](https://github.com/opensearch-project/common-utils/pull/758)) 17 | 18 | ### Documentation 19 | * Added 2.19.0.0 release notes. ([#780](https://github.com/opensearch-project/common-utils/pull/780)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.2.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.2.0.0 2022-08-09 2 | 3 | Compatible with OpenSearch 2.2.0 4 | 5 | ### Infrastructure 6 | * Execute version auto increment in staging ([#200](https://github.com/opensearch-project/common-utils/pull/200)) 7 | * Bump up the version to 2.2. ([#204](https://github.com/opensearch-project/common-utils/pull/204)) 8 | 9 | ### Documentation 10 | * Added 2.2 release notes. ([#212](https://github.com/opensearch-project/common-utils/pull/212)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.4.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.4.0.0 2022-11-04 2 | 3 | Compatible with OpenSearch 2.4.0 4 | 5 | ### Infrastructure 6 | * fix snakeyaml vulnerability issue by disabling detekt([#237](https://github.com/opensearch-project/common-utils/pull/237)) 7 | * upgrade 2.x to 2.4 ([#246](https://github.com/opensearch-project/common-utils/pull/246)) 8 | * remove force snakeyaml removal ([#263](https://github.com/opensearch-project/common-utils/pull/263)) 9 | 10 | ### Refactoring 11 | * Move Alerting data models over to common-utils ([#242](https://github.com/opensearch-project/common-utils/pull/242)) 12 | * Copy over monitor datasources config from alerting to common utils ([#247](https://github.com/opensearch-project/common-utils/pull/247)) 13 | * expose delete monitor api from alerting ([#251](https://github.com/opensearch-project/common-utils/pull/251)) 14 | * Move Findings and Alerts action, request, response and models from alerting to common-utils ([#254](https://github.com/opensearch-project/common-utils/pull/254)) 15 | * Move acknowledge alerts dtos from alerting to common-utils ([#283](https://github.com/opensearch-project/common-utils/pull/282)) 16 | 17 | ### Enhancements 18 | * Accept of list of monitor ids in findings and alerts request dtos ([#277](https://github.com/opensearch-project/common-utils/pull/277)) 19 | * Added legacy support for SNS messages. ([#269](https://github.com/opensearch-project/common-utils/pull/269)) 20 | * add list of alert ids in get alerts request ([#284](https://github.com/opensearch-project/common-utils/pull/284)) 21 | * fix security-analytics alerting findings api integration ([#292](https://github.com/opensearch-project/common-utils/pull/292)) 22 | * added params to Datasources ([#290](https://github.com/opensearch-project/common-utils/pull/290)) 23 | * fix security-analytics to alerting integration ([#293](https://github.com/opensearch-project/common-utils/pull/293)) 24 | * add findings enabled flag and findings field in bucket level monitor ([#305](https://github.com/opensearch-project/common-utils/pull/305)) 25 | * Support backend roles in indexMonitorRequest ([#308](https://github.com/opensearch-project/common-utils/pull/308)) 26 | * Added function for request recreation that considers the writeable request ([#303](https://github.com/opensearch-project/common-utils/pull/303)) 27 | * Adds owner field in monitor model ([#313](https://github.com/opensearch-project/common-utils/pull/313)) 28 | 29 | ### Documentation 30 | * Added 2.4 release notes. ([#316](https://github.com/opensearch-project/common-utils/pull/316)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.6.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.6.0.0 2023-02-21 2 | 3 | Compatible with OpenSearch 2.6.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.6.0-SNAPSHOT ([#344](https://github.com/opensearch-project/common-utils/pull/344)) 7 | 8 | ### Refactoring 9 | * Add a super admin client builder w/ hosts params ([#322](https://github.com/opensearch-project/common-utils/pull/322)) 10 | 11 | ### Bug Fixes 12 | * Fix streaming functions for LegacySNSMessage ([#324](https://github.com/opensearch-project/common-utils/pull/324)) 13 | 14 | ### Documentation 15 | * Added 2.6 release notes. ([#363](https://github.com/opensearch-project/common-utils/pull/363)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.7.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.7.0.0 2023-04-17 2 | 3 | Compatible with OpenSearch 2.7.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.7.0-SNAPSHOT. ([#371](https://github.com/opensearch-project/common-utils/pull/371)) 7 | 8 | ### Refactoring 9 | * Fixed xContent dependencies due to OSCore changes. ([#392](https://github.com/opensearch-project/common-utils/pull/392)) 10 | 11 | ### Infrastructure 12 | * Publish snapshots to maven via GHA. ([#365](https://github.com/opensearch-project/common-utils/pull/365)) 13 | * Add auto Github release workflow. ([#376](https://github.com/opensearch-project/common-utils/pull/376)) 14 | 15 | ### Feature 16 | * InjectSecurity - inject User object in UserInfo in threadContext. ([#396](https://github.com/opensearch-project/common-utils/pull/396)) 17 | 18 | ### Bug Fixes 19 | * Fix SNS regex for validation on notification channel to support SNS FIFO topics. ([#381](https://github.com/opensearch-project/common-utils/pull/381)) 20 | 21 | ### Documentation 22 | * Added 2.7 release notes. ([#407](https://github.com/opensearch-project/common-utils/pull/407)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.8.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.8.0.0 2023-05-26 2 | 3 | Compatible with OpenSearch 2.8.0 4 | 5 | ### Maintenance 6 | * upgrade gradle to 8.1.1. ([#418](https://github.com/opensearch-project/common-utils/pull/418)) 7 | * Sync up MAINTAINERS to CODEOWNERS. ([#427](https://github.com/opensearch-project/common-utils/pull/427)) 8 | * Fix build errors after refactoring of Strings class in core. ([#432](https://github.com/opensearch-project/common-utils/pull/432)) 9 | * updating maintainers and codeowners. ([#438](https://github.com/opensearch-project/common-utils/pull/438)) 10 | * fix codeowners file format. ([#440](https://github.com/opensearch-project/common-utils/pull/440)) 11 | 12 | ### Infrastructure 13 | * Switch publish maven branches to list. ([#423](https://github.com/opensearch-project/common-utils/pull/423)) 14 | 15 | ### Feature 16 | * integrate security-analytics & alerting for correlation engine. ([#412](https://github.com/opensearch-project/common-utils/pull/412)) 17 | * NoOpTrigger. ([#420](https://github.com/opensearch-project/common-utils/pull/420)) 18 | 19 | ### Documentation 20 | * Added 2.8 release notes. ([#441](https://github.com/opensearch-project/common-utils/pull/441)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-2.9.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 2.9.0.0 2023-07-11 2 | 3 | Compatible with OpenSearch 2.9.0 4 | 5 | ### Maintenance 6 | * Increment version to 2.9.0-SNAPSHOT. ([#444](https://github.com/opensearch-project/common-utils/pull/444)) 7 | * Modify triggers to push snapshots on all branches. ([#454](https://github.com/opensearch-project/common-utils/pull/454)) 8 | 9 | ### Feature 10 | * Adds Chained alerts triggers for workflows. ([#456](https://github.com/opensearch-project/common-utils/pull/456)) 11 | * Acknowledge chained alert request for workflow. ([#459](https://github.com/opensearch-project/common-utils/pull/459)) 12 | * Adds audit state in Alert. ([#461](https://github.com/opensearch-project/common-utils/pull/461)) 13 | * Add workflowId field in alert. (([#463](https://github.com/opensearch-project/common-utils/pull/463)) 14 | * APIs for get workflow alerts and acknowledge chained alerts. ([#472](https://github.com/opensearch-project/common-utils/pull/472)) 15 | * Add auditDelegateMonitorAlerts flag. ([#476](https://github.com/opensearch-project/common-utils/pull/476)) 16 | * Implemented support for configuring a cluster metrics monitor to call cat/indices, and cat/shards. ([#479](https://github.com/opensearch-project/common-utils/pull/479)) 17 | 18 | 19 | ### Bug Fixes 20 | * OpenSearch commons strings library dependency import. ([#474](https://github.com/opensearch-project/common-utils/pull/474)) 21 | 22 | ### Refactoring 23 | * Pass workflow id in alert constructors. ([#465](https://github.com/opensearch-project/common-utils/pull/465)) 24 | 25 | ### Documentation 26 | * Added 2.9 release notes. ([#482](https://github.com/opensearch-project/common-utils/pull/482)) -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-3.0.0.0-alpha1.md: -------------------------------------------------------------------------------- 1 | ## Version 3.0.0.0-alpha1 2025-03-18 2 | 3 | Compatible with OpenSearch 3.0.0-alpha1 4 | 5 | ### Features 6 | Adding replication (CCR) plugin interface and classes to common-utils ([#667](https://github.com/opensearch-project/common-utils/pull/667)) 7 | 8 | ### Maintenance 9 | Update common-utils shadow plugin repo and bump to 3.0.0.0-alpha1 ([#775](https://github.com/opensearch-project/common-utils/pull/775)) 10 | 11 | ### Bug Fixes 12 | Fix imports related to split package of org.opensearch.transport ([#790](https://github.com/opensearch-project/common-utils/pull/790)) 13 | 14 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-3.0.0.0-beta1.md: -------------------------------------------------------------------------------- 1 | ## Version 3.0.0.0-beta1 2025-03-31 2 | 3 | Compatible with OpenSearch 3.0.0-beta1 4 | 5 | ### Maintenance 6 | * Change 3.0.0 qualifier from alpha1 to beta1 ( ([#808](https://github.com/opensearch-project/common-utils/pull/808)) 7 | 8 | ### Bug fixes 9 | * Escape/Unescape pipe UserInfo in ThreadContext ([#801](https://github.com/opensearch-project/common-utils/pull/801)) 10 | -------------------------------------------------------------------------------- /release-notes/opensearch-common-utils.release-notes-3.0.0.0.md: -------------------------------------------------------------------------------- 1 | ## Version 3.0.0.0 2025-04-30 2 | 3 | Compatible with OpenSearch 3.0.0 4 | 5 | ### Features 6 | * Adding replication (CCR) plugin interface and classes to common-utils ([#667](https://github.com/opensearch-project/common-utils/pull/667)) 7 | 8 | ### Maintenance 9 | * Update common-utils shadow plugin repo and bump to 3.0.0.0-alpha1 ([#775](https://github.com/opensearch-project/common-utils/pull/775)) 10 | * Change 3.0.0 qualifier from alpha1 to beta1 ( ([#808](https://github.com/opensearch-project/common-utils/pull/808)) 11 | 12 | ### Bug fixes 13 | * Fix imports related to split package of org.opensearch.transport ([#790](https://github.com/opensearch-project/common-utils/pull/790)) 14 | * Escape/Unescape pipe UserInfo in ThreadContext ([#801](https://github.com/opensearch-project/common-utils/pull/801)) 15 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright OpenSearch Contributors. 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | set -ex 7 | 8 | function usage() { 9 | echo "Usage: $0 [args]" 10 | echo "" 11 | echo "Arguments:" 12 | echo -e "-v VERSION\t[Required] OpenSearch version." 13 | echo -e "-q QUALIFIER\t[Optional] Version qualifier." 14 | echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'." 15 | echo -e "-p PLATFORM\t[Optional] Platform, ignored." 16 | echo -e "-a ARCHITECTURE\t[Optional] Build architecture, ignored." 17 | echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'." 18 | echo -e "-h help" 19 | } 20 | 21 | while getopts ":h:v:q:s:o:p:a:" arg; do 22 | case $arg in 23 | h) 24 | usage 25 | exit 1 26 | ;; 27 | v) 28 | VERSION=$OPTARG 29 | ;; 30 | q) 31 | QUALIFIER=$OPTARG 32 | ;; 33 | s) 34 | SNAPSHOT=$OPTARG 35 | ;; 36 | o) 37 | OUTPUT=$OPTARG 38 | ;; 39 | p) 40 | PLATFORM=$OPTARG 41 | ;; 42 | a) 43 | ARCHITECTURE=$OPTARG 44 | ;; 45 | :) 46 | echo "Error: -${OPTARG} requires an argument" 47 | usage 48 | exit 1 49 | ;; 50 | ?) 51 | echo "Invalid option: -${arg}" 52 | exit 1 53 | ;; 54 | esac 55 | done 56 | 57 | if [ -z "$VERSION" ]; then 58 | echo "Error: You must specify the OpenSearch version" 59 | usage 60 | exit 1 61 | fi 62 | 63 | [[ ! -z "$QUALIFIER" ]] && VERSION=$VERSION-$QUALIFIER 64 | [[ "$SNAPSHOT" == "true" ]] && VERSION=$VERSION-SNAPSHOT 65 | [ -z "$OUTPUT" ] && OUTPUT=artifacts 66 | 67 | ./gradlew build -x test -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER 68 | ./gradlew publishShadowPublicationToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER 69 | ./gradlew publishShadowPublicationToStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER 70 | mkdir -p $OUTPUT/maven/org/opensearch 71 | cp -r ./build/local-staging-repo/org/opensearch/. $OUTPUT/maven/org/opensearch 72 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | rootProject.name = 'common-utils' -------------------------------------------------------------------------------- /spotless.license.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/authuser/AuthUserRequestBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.authuser; 7 | 8 | import org.opensearch.client.Request; 9 | import org.opensearch.client.RequestOptions; 10 | import org.opensearch.commons.ConfigConstants; 11 | import org.opensearch.core.common.Strings; 12 | 13 | public class AuthUserRequestBuilder { 14 | private final String auth; 15 | 16 | public AuthUserRequestBuilder(String auth) { 17 | if (Strings.isNullOrEmpty(auth)) { 18 | throw new IllegalArgumentException("Authorization token cannot be null"); 19 | } 20 | this.auth = auth; 21 | } 22 | 23 | public Request build() { 24 | Request request = new Request("GET", "/_opendistro/_security/authinfo"); 25 | request 26 | .setOptions( 27 | RequestOptions.DEFAULT 28 | .toBuilder() 29 | .addHeader(ConfigConstants.CONTENT_TYPE, ConfigConstants.CONTENT_TYPE_DEFAULT) 30 | .addHeader(ConfigConstants.AUTHORIZATION, auth) 31 | ); 32 | return request; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/authuser/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.authuser; 7 | 8 | public final class Utils { 9 | 10 | // Helper method to escape pipe characters 11 | public static String escapePipe(String input) { 12 | if (input == null) { 13 | return ""; 14 | } 15 | return input.replace("|", "\\|"); 16 | } 17 | 18 | // Helper method to un-escape pipe characters 19 | public static String unescapePipe(String input) { 20 | if (input == null) { 21 | return ""; 22 | } 23 | return input.replace("\\|", "|"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/destination/message/LegacyChimeMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.destination.message; 7 | 8 | import java.io.IOException; 9 | 10 | import org.opensearch.core.common.Strings; 11 | import org.opensearch.core.common.io.stream.StreamInput; 12 | 13 | /** 14 | * This class holds the contents of an Chime message 15 | */ 16 | public class LegacyChimeMessage extends LegacyBaseMessage { 17 | private final String message; 18 | 19 | private LegacyChimeMessage(final String destinationName, final String url, final String message) { 20 | super(LegacyDestinationType.LEGACY_CHIME, destinationName, message, url); 21 | 22 | if (Strings.isNullOrEmpty(message)) { 23 | throw new IllegalArgumentException("Message content is missing"); 24 | } 25 | 26 | this.message = message; 27 | } 28 | 29 | public LegacyChimeMessage(StreamInput streamInput) throws IOException { 30 | super(streamInput); 31 | this.message = super.getMessageContent(); 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "DestinationType: " + getChannelType() + ", DestinationName:" + destinationName + ", Url: " + url + ", Message: <...>"; 37 | } 38 | 39 | public static class Builder { 40 | private String message; 41 | private final String destinationName; 42 | private String url; 43 | 44 | public Builder(String destinationName) { 45 | this.destinationName = destinationName; 46 | } 47 | 48 | public LegacyChimeMessage.Builder withMessage(String message) { 49 | this.message = message; 50 | return this; 51 | } 52 | 53 | public LegacyChimeMessage.Builder withUrl(String url) { 54 | this.url = url; 55 | return this; 56 | } 57 | 58 | public LegacyChimeMessage build() { 59 | return new LegacyChimeMessage(this.destinationName, this.url, this.message); 60 | } 61 | } 62 | 63 | public String getMessage() { 64 | return message; 65 | } 66 | 67 | public String getUrl() { 68 | return url; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/destination/message/LegacyDestinationType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.destination.message; 7 | 8 | /** 9 | * Supported legacy notification destinations for Alerting and Index Management 10 | */ 11 | public enum LegacyDestinationType { 12 | LEGACY_CHIME, 13 | LEGACY_SLACK, 14 | LEGACY_CUSTOM_WEBHOOK, 15 | LEGACY_EMAIL, 16 | LEGACY_SNS 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/destination/message/LegacySlackMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.destination.message; 7 | 8 | import java.io.IOException; 9 | 10 | import org.opensearch.core.common.Strings; 11 | import org.opensearch.core.common.io.stream.StreamInput; 12 | 13 | /** 14 | * This class holds the content of an Slack message 15 | */ 16 | public class LegacySlackMessage extends LegacyBaseMessage { 17 | private final String message; 18 | 19 | private LegacySlackMessage(final String destinationName, final String url, final String message) { 20 | super(LegacyDestinationType.LEGACY_SLACK, destinationName, message, url); 21 | 22 | if (Strings.isNullOrEmpty(url)) { // add URL validation 23 | throw new IllegalArgumentException("Fully qualified URL is missing/invalid: " + url); 24 | } 25 | 26 | if (Strings.isNullOrEmpty(message)) { 27 | throw new IllegalArgumentException("Message content is missing"); 28 | } 29 | 30 | this.message = message; 31 | } 32 | 33 | public LegacySlackMessage(StreamInput streamInput) throws IOException { 34 | super(streamInput); 35 | this.message = super.getMessageContent(); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "DestinationType: " + getChannelType() + ", DestinationName:" + destinationName + ", Url: " + url + ", Message: <...>"; 41 | } 42 | 43 | public static class Builder { 44 | private String message; 45 | private String destinationName; 46 | private String url; 47 | 48 | public Builder(String channelName) { 49 | this.destinationName = channelName; 50 | } 51 | 52 | public LegacySlackMessage.Builder withMessage(String message) { 53 | this.message = message; 54 | return this; 55 | } 56 | 57 | public LegacySlackMessage.Builder withUrl(String url) { 58 | this.url = url; 59 | return this; 60 | } 61 | 62 | public LegacySlackMessage build() { 63 | return new LegacySlackMessage(this.destinationName, this.url, this.message); 64 | } 65 | } 66 | 67 | public String getMessage() { 68 | return message; 69 | } 70 | 71 | public String getUrl() { 72 | return url; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/destination/response/LegacyBaseResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.destination.response; 7 | 8 | import java.io.IOException; 9 | 10 | import org.opensearch.core.common.io.stream.StreamInput; 11 | import org.opensearch.core.common.io.stream.StreamOutput; 12 | import org.opensearch.core.common.io.stream.Writeable; 13 | 14 | /** 15 | * This class holds the generic response attributes 16 | */ 17 | public abstract class LegacyBaseResponse implements Writeable { 18 | protected Integer statusCode; 19 | 20 | LegacyBaseResponse(final Integer statusCode) { 21 | if (statusCode == null) { 22 | throw new IllegalArgumentException("status code is invalid"); 23 | } 24 | this.statusCode = statusCode; 25 | } 26 | 27 | public LegacyBaseResponse(StreamInput streamInput) throws IOException { 28 | this.statusCode = streamInput.readInt(); 29 | } 30 | 31 | public int getStatusCode() { 32 | return statusCode; 33 | } 34 | 35 | @Override 36 | public void writeTo(StreamOutput streamOutput) throws IOException { 37 | streamOutput.writeInt(statusCode); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/destination/response/LegacyDestinationResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.destination.response; 7 | 8 | import java.io.IOException; 9 | 10 | import org.opensearch.core.common.io.stream.StreamInput; 11 | import org.opensearch.core.common.io.stream.StreamOutput; 12 | 13 | /** 14 | * This class is a place holder for destination response metadata 15 | */ 16 | public class LegacyDestinationResponse extends LegacyBaseResponse { 17 | 18 | private final String responseContent; 19 | 20 | private LegacyDestinationResponse(final String responseString, final Integer statusCode) { 21 | super(statusCode); 22 | if (responseString == null) { 23 | throw new IllegalArgumentException("Response is missing"); 24 | } 25 | this.responseContent = responseString; 26 | } 27 | 28 | public LegacyDestinationResponse(StreamInput streamInput) throws IOException { 29 | super(streamInput); 30 | this.responseContent = streamInput.readString(); 31 | } 32 | 33 | public static class Builder { 34 | private String responseContent; 35 | private Integer statusCode; 36 | 37 | public LegacyDestinationResponse.Builder withResponseContent(String responseContent) { 38 | this.responseContent = responseContent; 39 | return this; 40 | } 41 | 42 | public LegacyDestinationResponse.Builder withStatusCode(Integer statusCode) { 43 | this.statusCode = statusCode; 44 | return this; 45 | } 46 | 47 | public LegacyDestinationResponse build() { 48 | return new LegacyDestinationResponse(responseContent, statusCode); 49 | } 50 | } 51 | 52 | public String getResponseContent() { 53 | return this.responseContent; 54 | } 55 | 56 | @Override 57 | public void writeTo(StreamOutput streamOutput) throws IOException { 58 | super.writeTo(streamOutput); 59 | streamOutput.writeString(responseContent); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/destination/util/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.destination.util; 7 | 8 | import java.util.regex.Pattern; 9 | 10 | import org.opensearch.common.ValidationException; 11 | import org.opensearch.core.common.Strings; 12 | 13 | public class Util { 14 | private Util() {} 15 | 16 | public static final Pattern SNS_ARN_REGEX = Pattern 17 | .compile("^arn:aws(-[^:]+)?:sns:([a-zA-Z0-9-]+):([0-9]{12}):([a-zA-Z0-9-_]+)(\\.fifo)?$"); 18 | public static final Pattern IAM_ARN_REGEX = Pattern.compile("^arn:aws(-[^:]+)?:iam::([0-9]{12}):([a-zA-Z0-9-/_+=@.,]+)$"); 19 | 20 | public static String getRegion(String arn) { 21 | // sample topic arn arn:aws:sns:us-west-2:075315751589:test-notification 22 | if (isValidSNSArn(arn)) { 23 | return arn.split(":")[3]; 24 | } 25 | throw new IllegalArgumentException("Unable to retrieve region from ARN " + arn); 26 | } 27 | 28 | public static boolean isValidIAMArn(String arn) { 29 | return Strings.hasLength(arn) && IAM_ARN_REGEX.matcher(arn).find(); 30 | } 31 | 32 | public static boolean isValidSNSArn(String arn) throws ValidationException { 33 | return Strings.hasLength(arn) && SNS_ARN_REGEX.matcher(arn).find(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/opensearch/commons/rest/TrustStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.rest; 7 | 8 | import java.io.FileInputStream; 9 | import java.io.IOException; 10 | import java.security.GeneralSecurityException; 11 | import java.security.KeyStore; 12 | import java.security.cert.Certificate; 13 | import java.security.cert.CertificateFactory; 14 | import java.security.cert.X509Certificate; 15 | import java.util.Collection; 16 | 17 | /** 18 | * Helper class to read raw pem files to keystore. 19 | */ 20 | public class TrustStore { 21 | 22 | private final String effectiveKeyAlias = "al"; 23 | private final String storeType = "JKS"; 24 | private final String certType = "X.509"; 25 | private final String cert; 26 | 27 | public TrustStore(final String file) { 28 | cert = file; 29 | } 30 | 31 | public KeyStore create() throws IOException, GeneralSecurityException { 32 | X509Certificate[] trustCerts = loadCertificatesFromFile(cert); 33 | return toTrustStore(effectiveKeyAlias, trustCerts); 34 | } 35 | 36 | private X509Certificate[] loadCertificatesFromFile(String file) throws IOException, GeneralSecurityException { 37 | if (file == null) { 38 | return null; 39 | } 40 | CertificateFactory fact = CertificateFactory.getInstance(certType); 41 | try (FileInputStream is = new FileInputStream(file)) { 42 | Collection certs = fact.generateCertificates(is); 43 | X509Certificate[] x509Certs = new X509Certificate[certs.size()]; 44 | int i = 0; 45 | for (Certificate cert : certs) { 46 | x509Certs[i++] = (X509Certificate) cert; 47 | } 48 | return x509Certs; 49 | } 50 | } 51 | 52 | private KeyStore toTrustStore(final String trustCertificatesAliasPrefix, final X509Certificate[] trustCertificates) throws IOException, 53 | GeneralSecurityException { 54 | if (trustCertificates == null) { 55 | return null; 56 | } 57 | KeyStore ks = KeyStore.getInstance(storeType); 58 | ks.load(null); 59 | 60 | if (trustCertificates != null) { 61 | for (int i = 0; i < trustCertificates.length; i++) { 62 | X509Certificate x509Certificate = trustCertificates[i]; 63 | ks.setCertificateEntry(trustCertificatesAliasPrefix + "_" + i, x509Certificate); 64 | } 65 | } 66 | return ks; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/AcknowledgeAlertRequest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.action.ActionRequest 9 | import org.opensearch.action.ActionRequestValidationException 10 | import org.opensearch.action.support.WriteRequest 11 | import org.opensearch.core.common.io.stream.StreamInput 12 | import org.opensearch.core.common.io.stream.StreamOutput 13 | import java.io.IOException 14 | import java.util.Collections 15 | 16 | class AcknowledgeAlertRequest : ActionRequest { 17 | val monitorId: String 18 | val alertIds: List 19 | val refreshPolicy: WriteRequest.RefreshPolicy 20 | 21 | constructor( 22 | monitorId: String, 23 | alertIds: List, 24 | refreshPolicy: WriteRequest.RefreshPolicy 25 | ) : super() { 26 | this.monitorId = monitorId 27 | this.alertIds = alertIds 28 | this.refreshPolicy = refreshPolicy 29 | } 30 | 31 | @Throws(IOException::class) 32 | constructor(sin: StreamInput) : this( 33 | sin.readString(), // monitorId 34 | Collections.unmodifiableList(sin.readStringList()), // alertIds 35 | WriteRequest.RefreshPolicy.readFrom(sin) // refreshPolicy 36 | ) 37 | 38 | override fun validate(): ActionRequestValidationException? { 39 | return null 40 | } 41 | 42 | @Throws(IOException::class) 43 | override fun writeTo(out: StreamOutput) { 44 | out.writeString(monitorId) 45 | out.writeStringCollection(alertIds) 46 | refreshPolicy.writeTo(out) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.action.ActionRequest 9 | import org.opensearch.action.ActionRequestValidationException 10 | import org.opensearch.core.common.io.stream.StreamInput 11 | import org.opensearch.core.common.io.stream.StreamOutput 12 | import java.io.IOException 13 | import java.util.Collections 14 | 15 | /** Request DTO for acknowledging chained alerts generated by workflow.*/ 16 | class AcknowledgeChainedAlertRequest : ActionRequest { 17 | val workflowId: String 18 | val alertIds: List 19 | 20 | constructor( 21 | workflowId: String, 22 | alertIds: List 23 | ) : super() { 24 | this.workflowId = workflowId 25 | this.alertIds = alertIds 26 | } 27 | 28 | @Throws(IOException::class) 29 | constructor(sin: StreamInput) : this( 30 | sin.readString(), // workflowId 31 | Collections.unmodifiableList(sin.readStringList()) // alertIds 32 | ) 33 | 34 | override fun validate(): ActionRequestValidationException? { 35 | return null 36 | } 37 | 38 | @Throws(IOException::class) 39 | override fun writeTo(out: StreamOutput) { 40 | out.writeString(workflowId) 41 | out.writeStringCollection(alertIds) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/DeleteCommentRequest.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.action.ActionRequest 4 | import org.opensearch.action.ActionRequestValidationException 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import java.io.IOException 8 | 9 | class DeleteCommentRequest : ActionRequest { 10 | val commentId: String 11 | 12 | constructor(commentId: String) : super() { 13 | this.commentId = commentId 14 | } 15 | 16 | @Throws(IOException::class) 17 | constructor(sin: StreamInput) : this( 18 | commentId = sin.readString() 19 | ) 20 | 21 | override fun validate(): ActionRequestValidationException? { 22 | if (commentId.isBlank()) { 23 | val exception = ActionRequestValidationException() 24 | exception.addValidationError("comment id must not be blank") 25 | return exception 26 | } 27 | return null 28 | } 29 | 30 | @Throws(IOException::class) 31 | override fun writeTo(out: StreamOutput) { 32 | out.writeString(commentId) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/DeleteCommentResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.util.IndexUtils 4 | import org.opensearch.commons.notifications.action.BaseResponse 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import org.opensearch.core.xcontent.ToXContent 8 | import org.opensearch.core.xcontent.XContentBuilder 9 | 10 | class DeleteCommentResponse : BaseResponse { 11 | var commentId: String 12 | 13 | constructor( 14 | id: String 15 | ) : super() { 16 | this.commentId = id 17 | } 18 | 19 | constructor(sin: StreamInput) : this( 20 | sin.readString() // commentId 21 | ) 22 | 23 | override fun writeTo(out: StreamOutput) { 24 | out.writeString(commentId) 25 | } 26 | 27 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 28 | return builder.startObject() 29 | .field(IndexUtils._ID, commentId) 30 | .endObject() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/DeleteMonitorRequest.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.action.ActionRequest 4 | import org.opensearch.action.ActionRequestValidationException 5 | import org.opensearch.action.support.WriteRequest 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | import org.opensearch.core.common.io.stream.StreamOutput 8 | import java.io.IOException 9 | 10 | class DeleteMonitorRequest : ActionRequest { 11 | 12 | val monitorId: String 13 | val refreshPolicy: WriteRequest.RefreshPolicy 14 | 15 | constructor(monitorId: String, refreshPolicy: WriteRequest.RefreshPolicy) : super() { 16 | this.monitorId = monitorId 17 | this.refreshPolicy = refreshPolicy 18 | } 19 | 20 | @Throws(IOException::class) 21 | constructor(sin: StreamInput) : this( 22 | monitorId = sin.readString(), 23 | refreshPolicy = WriteRequest.RefreshPolicy.readFrom(sin) 24 | ) 25 | 26 | override fun validate(): ActionRequestValidationException? { 27 | return null 28 | } 29 | 30 | @Throws(IOException::class) 31 | override fun writeTo(out: StreamOutput) { 32 | out.writeString(monitorId) 33 | refreshPolicy.writeTo(out) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/DeleteMonitorResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.util.IndexUtils 4 | import org.opensearch.commons.notifications.action.BaseResponse 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import org.opensearch.core.xcontent.ToXContent 8 | import org.opensearch.core.xcontent.XContentBuilder 9 | 10 | class DeleteMonitorResponse : BaseResponse { 11 | var id: String 12 | var version: Long 13 | 14 | constructor( 15 | id: String, 16 | version: Long 17 | ) : super() { 18 | this.id = id 19 | this.version = version 20 | } 21 | 22 | constructor(sin: StreamInput) : this( 23 | sin.readString(), // id 24 | sin.readLong() // version 25 | ) 26 | 27 | override fun writeTo(out: StreamOutput) { 28 | out.writeString(id) 29 | out.writeLong(version) 30 | } 31 | 32 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 33 | return builder.startObject() 34 | .field(IndexUtils._ID, id) 35 | .field(IndexUtils._VERSION, version) 36 | .endObject() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/DeleteWorkflowRequest.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.action.ActionRequest 4 | import org.opensearch.action.ActionRequestValidationException 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import java.io.IOException 8 | 9 | class DeleteWorkflowRequest : ActionRequest { 10 | 11 | val workflowId: String 12 | 13 | /** 14 | * Flag that indicates whether the delegate monitors should be deleted or not. 15 | * If the flag is set to true, Delegate monitors will be deleted only in the case when they are part of the specified workflow and no other. 16 | */ 17 | val deleteDelegateMonitors: Boolean? 18 | 19 | constructor(workflowId: String, deleteDelegateMonitors: Boolean?) : super() { 20 | this.workflowId = workflowId 21 | this.deleteDelegateMonitors = deleteDelegateMonitors 22 | } 23 | 24 | @Throws(IOException::class) 25 | constructor(sin: StreamInput) : this( 26 | workflowId = sin.readString(), 27 | deleteDelegateMonitors = sin.readOptionalBoolean() 28 | ) 29 | 30 | override fun validate(): ActionRequestValidationException? { 31 | return null 32 | } 33 | 34 | @Throws(IOException::class) 35 | override fun writeTo(out: StreamOutput) { 36 | out.writeString(workflowId) 37 | out.writeOptionalBoolean(deleteDelegateMonitors) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/DeleteWorkflowResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.util.IndexUtils 4 | import org.opensearch.commons.notifications.action.BaseResponse 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import org.opensearch.core.xcontent.ToXContent 8 | import org.opensearch.core.xcontent.XContentBuilder 9 | 10 | class DeleteWorkflowResponse : BaseResponse { 11 | var id: String 12 | var version: Long 13 | var nonDeletedMonitors: List? = null 14 | 15 | constructor( 16 | id: String, 17 | version: Long, 18 | nonDeletedMonitors: List? = null 19 | ) : super() { 20 | this.id = id 21 | this.version = version 22 | this.nonDeletedMonitors = nonDeletedMonitors 23 | } 24 | 25 | constructor(sin: StreamInput) : this( 26 | sin.readString(), // id 27 | sin.readLong(), // version 28 | sin.readOptionalStringList() 29 | ) 30 | 31 | override fun writeTo(out: StreamOutput) { 32 | out.writeString(id) 33 | out.writeLong(version) 34 | out.writeOptionalStringCollection(nonDeletedMonitors) 35 | } 36 | 37 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 38 | return builder.startObject() 39 | .field(IndexUtils._ID, id) 40 | .field(IndexUtils._VERSION, version) 41 | .field(NON_DELETED_MONITORS, nonDeletedMonitors) 42 | .endObject() 43 | } 44 | 45 | companion object { 46 | const val NON_DELETED_MONITORS = "NON_DELETED_MONITORS" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/DocLevelMonitorFanOutAction.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.action.ActionType 9 | 10 | class DocLevelMonitorFanOutAction private constructor() : ActionType(NAME, ::DocLevelMonitorFanOutResponse) { 11 | companion object { 12 | val INSTANCE = DocLevelMonitorFanOutAction() 13 | const val NAME = "cluster:admin/opensearch/alerting/monitor/doclevel/fanout" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.model.Alert 4 | import org.opensearch.commons.notifications.action.BaseResponse 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import org.opensearch.core.xcontent.ToXContent 8 | import org.opensearch.core.xcontent.XContentBuilder 9 | import java.io.IOException 10 | import java.util.Collections 11 | 12 | class GetAlertsResponse : BaseResponse { 13 | val alerts: List 14 | 15 | // totalAlerts is not the same as the size of alerts because there can be 30 alerts from the request, but 16 | // the request only asked for 5 alerts, so totalAlerts will be 30, but alerts will only contain 5 alerts 17 | val totalAlerts: Int? 18 | 19 | constructor( 20 | alerts: List, 21 | totalAlerts: Int? 22 | ) : super() { 23 | this.alerts = alerts 24 | this.totalAlerts = totalAlerts 25 | } 26 | 27 | @Throws(IOException::class) 28 | constructor(sin: StreamInput) : this( 29 | alerts = Collections.unmodifiableList(sin.readList(::Alert)), 30 | totalAlerts = sin.readOptionalInt() 31 | ) 32 | 33 | @Throws(IOException::class) 34 | override fun writeTo(out: StreamOutput) { 35 | out.writeCollection(alerts) 36 | out.writeOptionalInt(totalAlerts) 37 | } 38 | 39 | @Throws(IOException::class) 40 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 41 | builder.startObject() 42 | .field("alerts", alerts) 43 | .field("totalAlerts", totalAlerts) 44 | 45 | return builder.endObject() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.action.ActionRequest 4 | import org.opensearch.action.ActionRequestValidationException 5 | import org.opensearch.commons.alerting.model.Table 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | import org.opensearch.core.common.io.stream.StreamOutput 8 | import org.opensearch.index.query.BoolQueryBuilder 9 | import java.io.IOException 10 | 11 | class GetFindingsRequest : ActionRequest { 12 | val findingId: String? 13 | val table: Table 14 | val monitorId: String? 15 | val monitorIds: List? 16 | val findingIndex: String? 17 | val boolQueryBuilder: BoolQueryBuilder? 18 | constructor( 19 | findingId: String?, 20 | table: Table, 21 | monitorId: String? = null, 22 | findingIndexName: String? = null, 23 | monitorIds: List? = null, 24 | boolQueryBuilder: BoolQueryBuilder? = null 25 | ) : super() { 26 | this.findingId = findingId 27 | this.table = table 28 | this.monitorId = monitorId 29 | this.findingIndex = findingIndexName 30 | this.monitorIds = monitorIds 31 | this.boolQueryBuilder = boolQueryBuilder 32 | } 33 | 34 | @Throws(IOException::class) 35 | constructor(sin: StreamInput) : this( 36 | findingId = sin.readOptionalString(), 37 | table = Table.readFrom(sin), 38 | monitorId = sin.readOptionalString(), 39 | findingIndexName = sin.readOptionalString(), 40 | monitorIds = sin.readOptionalStringList(), 41 | boolQueryBuilder = BoolQueryBuilder(sin) 42 | ) 43 | 44 | override fun validate(): ActionRequestValidationException? { 45 | return null 46 | } 47 | 48 | @Throws(IOException::class) 49 | override fun writeTo(out: StreamOutput) { 50 | out.writeOptionalString(findingId) 51 | table.writeTo(out) 52 | out.writeOptionalString(monitorId) 53 | out.writeOptionalString(findingIndex) 54 | out.writeOptionalStringCollection(monitorIds) 55 | boolQueryBuilder?.writeTo(out) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.model.FindingWithDocs 4 | import org.opensearch.commons.notifications.action.BaseResponse 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import org.opensearch.core.rest.RestStatus 8 | import org.opensearch.core.xcontent.ToXContent 9 | import org.opensearch.core.xcontent.XContentBuilder 10 | import java.io.IOException 11 | 12 | class GetFindingsResponse : BaseResponse { 13 | private var status: RestStatus 14 | var totalFindings: Int? 15 | var findings: List 16 | 17 | constructor( 18 | status: RestStatus, 19 | totalFindings: Int?, 20 | findings: List 21 | ) : super() { 22 | this.status = status 23 | this.totalFindings = totalFindings 24 | this.findings = findings 25 | } 26 | 27 | @Throws(IOException::class) 28 | constructor(sin: StreamInput) { 29 | this.status = sin.readEnum(RestStatus::class.java) 30 | val findings = mutableListOf() 31 | this.totalFindings = sin.readOptionalInt() 32 | var currentSize = sin.readInt() 33 | for (i in 0 until currentSize) { 34 | findings.add(FindingWithDocs.readFrom(sin)) 35 | } 36 | this.findings = findings 37 | } 38 | 39 | @Throws(IOException::class) 40 | override fun writeTo(out: StreamOutput) { 41 | out.writeEnum(status) 42 | out.writeOptionalInt(totalFindings) 43 | out.writeInt(findings.size) 44 | for (finding in findings) { 45 | finding.writeTo(out) 46 | } 47 | } 48 | 49 | @Throws(IOException::class) 50 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 51 | builder.startObject() 52 | .field("total_findings", totalFindings) 53 | .field("findings", findings) 54 | 55 | return builder.endObject() 56 | } 57 | 58 | override fun getStatus(): RestStatus { 59 | return this.status 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorRequest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.action.ActionRequest 9 | import org.opensearch.action.ActionRequestValidationException 10 | import org.opensearch.core.common.io.stream.StreamInput 11 | import org.opensearch.core.common.io.stream.StreamOutput 12 | import org.opensearch.rest.RestRequest 13 | import org.opensearch.search.fetch.subphase.FetchSourceContext 14 | import java.io.IOException 15 | 16 | class GetMonitorRequest : ActionRequest { 17 | val monitorId: String 18 | val version: Long 19 | val method: RestRequest.Method 20 | val srcContext: FetchSourceContext? 21 | 22 | constructor( 23 | monitorId: String, 24 | version: Long, 25 | method: RestRequest.Method, 26 | srcContext: FetchSourceContext? 27 | ) : super() { 28 | this.monitorId = monitorId 29 | this.version = version 30 | this.method = method 31 | this.srcContext = srcContext 32 | } 33 | 34 | @Throws(IOException::class) 35 | constructor(sin: StreamInput) : this( 36 | sin.readString(), // monitorId 37 | sin.readLong(), // version 38 | sin.readEnum(RestRequest.Method::class.java), // method 39 | if (sin.readBoolean()) { 40 | FetchSourceContext(sin) // srcContext 41 | } else { 42 | null 43 | } 44 | ) 45 | 46 | override fun validate(): ActionRequestValidationException? { 47 | return null 48 | } 49 | 50 | @Throws(IOException::class) 51 | override fun writeTo(out: StreamOutput) { 52 | out.writeString(monitorId) 53 | out.writeLong(version) 54 | out.writeEnum(method) 55 | out.writeBoolean(srcContext != null) 56 | srcContext?.writeTo(out) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/GetWorkflowAlertsResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.model.Alert 4 | import org.opensearch.commons.notifications.action.BaseResponse 5 | import org.opensearch.core.common.io.stream.StreamInput 6 | import org.opensearch.core.common.io.stream.StreamOutput 7 | import org.opensearch.core.xcontent.ToXContent 8 | import org.opensearch.core.xcontent.XContentBuilder 9 | import java.io.IOException 10 | import java.util.Collections 11 | 12 | class GetWorkflowAlertsResponse : BaseResponse { 13 | val alerts: List 14 | val associatedAlerts: List 15 | 16 | // totalAlerts is not the same as the size of alerts because there can be 30 alerts from the request, but 17 | // the request only asked for 5 alerts, so totalAlerts will be 30, but alerts will only contain 5 alerts 18 | val totalAlerts: Int? 19 | 20 | constructor( 21 | alerts: List, 22 | associatedAlerts: List, 23 | totalAlerts: Int? 24 | ) : super() { 25 | this.alerts = alerts 26 | this.associatedAlerts = associatedAlerts 27 | this.totalAlerts = totalAlerts 28 | } 29 | 30 | @Throws(IOException::class) 31 | constructor(sin: StreamInput) : this( 32 | alerts = Collections.unmodifiableList(sin.readList(::Alert)), 33 | associatedAlerts = Collections.unmodifiableList(sin.readList(::Alert)), 34 | totalAlerts = sin.readOptionalInt() 35 | ) 36 | 37 | @Throws(IOException::class) 38 | override fun writeTo(out: StreamOutput) { 39 | out.writeCollection(alerts) 40 | out.writeCollection(associatedAlerts) 41 | out.writeOptionalInt(totalAlerts) 42 | } 43 | 44 | @Throws(IOException::class) 45 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 46 | builder.startObject() 47 | .field("alerts", alerts) 48 | .field("associatedAlerts", associatedAlerts) 49 | .field("totalAlerts", totalAlerts) 50 | return builder.endObject() 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/GetWorkflowRequest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.action.ActionRequest 9 | import org.opensearch.action.ActionRequestValidationException 10 | import org.opensearch.core.common.io.stream.StreamInput 11 | import org.opensearch.core.common.io.stream.StreamOutput 12 | import org.opensearch.rest.RestRequest 13 | import java.io.IOException 14 | 15 | class GetWorkflowRequest : ActionRequest { 16 | val workflowId: String 17 | val method: RestRequest.Method 18 | 19 | constructor( 20 | workflowId: String, 21 | method: RestRequest.Method 22 | ) : super() { 23 | this.workflowId = workflowId 24 | this.method = method 25 | } 26 | 27 | @Throws(IOException::class) 28 | constructor(sin: StreamInput) : this( 29 | sin.readString(), // workflowId 30 | sin.readEnum(RestRequest.Method::class.java) // method 31 | ) 32 | 33 | override fun validate(): ActionRequestValidationException? { 34 | return null 35 | } 36 | 37 | @Throws(IOException::class) 38 | override fun writeTo(out: StreamOutput) { 39 | out.writeString(workflowId) 40 | out.writeEnum(method) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/IndexCommentResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.model.Comment 4 | import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID 5 | import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM 6 | import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO 7 | import org.opensearch.commons.notifications.action.BaseResponse 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | import org.opensearch.core.common.io.stream.StreamOutput 10 | import org.opensearch.core.xcontent.ToXContent 11 | import org.opensearch.core.xcontent.XContentBuilder 12 | import java.io.IOException 13 | 14 | class IndexCommentResponse : BaseResponse { 15 | var id: String 16 | var seqNo: Long 17 | var primaryTerm: Long 18 | var comment: Comment 19 | 20 | constructor( 21 | id: String, 22 | seqNo: Long, 23 | primaryTerm: Long, 24 | comment: Comment 25 | ) : super() { 26 | this.id = id 27 | this.seqNo = seqNo 28 | this.primaryTerm = primaryTerm 29 | this.comment = comment 30 | } 31 | 32 | @Throws(IOException::class) 33 | constructor(sin: StreamInput) : this( 34 | sin.readString(), // id 35 | sin.readLong(), // seqNo 36 | sin.readLong(), // primaryTerm 37 | Comment.readFrom(sin) // comment 38 | ) 39 | 40 | @Throws(IOException::class) 41 | override fun writeTo(out: StreamOutput) { 42 | out.writeString(id) 43 | out.writeLong(seqNo) 44 | out.writeLong(primaryTerm) 45 | comment.writeTo(out) 46 | } 47 | 48 | @Throws(IOException::class) 49 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 50 | return builder.startObject() 51 | .field(_ID, id) 52 | .field(_SEQ_NO, seqNo) 53 | .field(_PRIMARY_TERM, primaryTerm) 54 | .field("comment", comment) 55 | .endObject() 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/IndexMonitorResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.model.Monitor 4 | import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID 5 | import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM 6 | import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO 7 | import org.opensearch.commons.alerting.util.IndexUtils.Companion._VERSION 8 | import org.opensearch.commons.notifications.action.BaseResponse 9 | import org.opensearch.core.common.io.stream.StreamInput 10 | import org.opensearch.core.common.io.stream.StreamOutput 11 | import org.opensearch.core.xcontent.ToXContent 12 | import org.opensearch.core.xcontent.XContentBuilder 13 | import java.io.IOException 14 | 15 | class IndexMonitorResponse : BaseResponse { 16 | var id: String 17 | var version: Long 18 | var seqNo: Long 19 | var primaryTerm: Long 20 | var monitor: Monitor 21 | 22 | constructor( 23 | id: String, 24 | version: Long, 25 | seqNo: Long, 26 | primaryTerm: Long, 27 | monitor: Monitor 28 | ) : super() { 29 | this.id = id 30 | this.version = version 31 | this.seqNo = seqNo 32 | this.primaryTerm = primaryTerm 33 | this.monitor = monitor 34 | } 35 | 36 | @Throws(IOException::class) 37 | constructor(sin: StreamInput) : this( 38 | sin.readString(), // id 39 | sin.readLong(), // version 40 | sin.readLong(), // seqNo 41 | sin.readLong(), // primaryTerm 42 | Monitor.readFrom(sin) as Monitor // monitor 43 | ) 44 | 45 | @Throws(IOException::class) 46 | override fun writeTo(out: StreamOutput) { 47 | out.writeString(id) 48 | out.writeLong(version) 49 | out.writeLong(seqNo) 50 | out.writeLong(primaryTerm) 51 | monitor.writeTo(out) 52 | } 53 | 54 | @Throws(IOException::class) 55 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 56 | return builder.startObject() 57 | .field(_ID, id) 58 | .field(_VERSION, version) 59 | .field(_SEQ_NO, seqNo) 60 | .field(_PRIMARY_TERM, primaryTerm) 61 | .field("monitor", monitor) 62 | .endObject() 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/IndexWorkflowResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.alerting.model.Workflow 4 | import org.opensearch.commons.alerting.util.IndexUtils 5 | import org.opensearch.commons.notifications.action.BaseResponse 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | import org.opensearch.core.common.io.stream.StreamOutput 8 | import org.opensearch.core.xcontent.ToXContent 9 | import org.opensearch.core.xcontent.XContentBuilder 10 | import java.io.IOException 11 | 12 | class IndexWorkflowResponse : BaseResponse { 13 | var id: String 14 | var version: Long 15 | var seqNo: Long 16 | var primaryTerm: Long 17 | var workflow: Workflow 18 | 19 | constructor( 20 | id: String, 21 | version: Long, 22 | seqNo: Long, 23 | primaryTerm: Long, 24 | workflow: Workflow 25 | ) : super() { 26 | this.id = id 27 | this.version = version 28 | this.seqNo = seqNo 29 | this.primaryTerm = primaryTerm 30 | this.workflow = workflow 31 | } 32 | 33 | @Throws(IOException::class) 34 | constructor(sin: StreamInput) : this( 35 | sin.readString(), // id 36 | sin.readLong(), // version 37 | sin.readLong(), // seqNo 38 | sin.readLong(), // primaryTerm 39 | Workflow.readFrom(sin) as Workflow // workflow 40 | ) 41 | 42 | @Throws(IOException::class) 43 | override fun writeTo(out: StreamOutput) { 44 | out.writeString(id) 45 | out.writeLong(version) 46 | out.writeLong(seqNo) 47 | out.writeLong(primaryTerm) 48 | workflow.writeTo(out) 49 | } 50 | 51 | @Throws(IOException::class) 52 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 53 | return builder.startObject() 54 | .field(IndexUtils._ID, id) 55 | .field(IndexUtils._VERSION, version) 56 | .field(IndexUtils._SEQ_NO, seqNo) 57 | .field(IndexUtils._PRIMARY_TERM, primaryTerm) 58 | .field("workflow", workflow) 59 | .endObject() 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/PublishFindingsRequest.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.action.ActionRequest 4 | import org.opensearch.action.ActionRequestValidationException 5 | import org.opensearch.commons.alerting.model.Finding 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | import org.opensearch.core.common.io.stream.StreamOutput 8 | import java.io.IOException 9 | 10 | class PublishFindingsRequest : ActionRequest { 11 | 12 | val monitorId: String 13 | 14 | val finding: Finding 15 | 16 | constructor( 17 | monitorId: String, 18 | finding: Finding 19 | ) : super() { 20 | this.monitorId = monitorId 21 | this.finding = finding 22 | } 23 | 24 | @Throws(IOException::class) 25 | constructor(sin: StreamInput) : this( 26 | monitorId = sin.readString(), 27 | finding = Finding.readFrom(sin) 28 | ) 29 | 30 | override fun validate(): ActionRequestValidationException? { 31 | return null 32 | } 33 | 34 | override fun writeTo(out: StreamOutput) { 35 | out.writeString(monitorId) 36 | finding.writeTo(out) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/SearchCommentRequest.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.action.ActionRequest 4 | import org.opensearch.action.ActionRequestValidationException 5 | import org.opensearch.action.search.SearchRequest 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | import org.opensearch.core.common.io.stream.StreamOutput 8 | import java.io.IOException 9 | 10 | class SearchCommentRequest : ActionRequest { 11 | 12 | val searchRequest: SearchRequest 13 | 14 | constructor( 15 | searchRequest: SearchRequest 16 | ) : super() { 17 | this.searchRequest = searchRequest 18 | } 19 | 20 | @Throws(IOException::class) 21 | constructor(sin: StreamInput) : this( 22 | searchRequest = SearchRequest(sin) 23 | ) 24 | 25 | override fun validate(): ActionRequestValidationException? { 26 | return null 27 | } 28 | 29 | @Throws(IOException::class) 30 | override fun writeTo(out: StreamOutput) { 31 | searchRequest.writeTo(out) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.action.ActionRequest 9 | import org.opensearch.action.ActionRequestValidationException 10 | import org.opensearch.action.search.SearchRequest 11 | import org.opensearch.core.common.io.stream.StreamInput 12 | import org.opensearch.core.common.io.stream.StreamOutput 13 | import java.io.IOException 14 | 15 | class SearchMonitorRequest : ActionRequest { 16 | 17 | val searchRequest: SearchRequest 18 | 19 | constructor( 20 | searchRequest: SearchRequest 21 | ) : super() { 22 | this.searchRequest = searchRequest 23 | } 24 | 25 | @Throws(IOException::class) 26 | constructor(sin: StreamInput) : this( 27 | searchRequest = SearchRequest(sin) 28 | ) 29 | 30 | override fun validate(): ActionRequestValidationException? { 31 | return null 32 | } 33 | 34 | @Throws(IOException::class) 35 | override fun writeTo(out: StreamOutput) { 36 | searchRequest.writeTo(out) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/action/SubscribeFindingsResponse.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.commons.notifications.action.BaseResponse 4 | import org.opensearch.core.common.io.stream.StreamInput 5 | import org.opensearch.core.common.io.stream.StreamOutput 6 | import org.opensearch.core.rest.RestStatus 7 | import org.opensearch.core.xcontent.ToXContent 8 | import org.opensearch.core.xcontent.XContentBuilder 9 | import java.io.IOException 10 | 11 | class SubscribeFindingsResponse : BaseResponse { 12 | 13 | private var status: RestStatus 14 | 15 | constructor(status: RestStatus) : super() { 16 | this.status = status 17 | } 18 | 19 | @Throws(IOException::class) 20 | constructor(sin: StreamInput) { 21 | this.status = sin.readEnum(RestStatus::class.java) 22 | } 23 | 24 | @Throws(IOException::class) 25 | override fun writeTo(out: StreamOutput) { 26 | out.writeEnum(status) 27 | } 28 | 29 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 30 | builder.startObject() 31 | .field("status", status.status) 32 | return builder.endObject() 33 | } 34 | 35 | override fun getStatus(): RestStatus { 36 | return this.status 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/model/BucketLevelTriggerRunResult.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.model 7 | 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | import org.opensearch.core.common.io.stream.StreamOutput 10 | import org.opensearch.core.xcontent.ToXContent 11 | import org.opensearch.core.xcontent.XContentBuilder 12 | import java.io.IOException 13 | 14 | data class BucketLevelTriggerRunResult( 15 | override var triggerName: String, 16 | override var error: Exception? = null, 17 | var aggregationResultBuckets: Map, 18 | var actionResultsMap: MutableMap> = mutableMapOf() 19 | ) : TriggerRunResult(triggerName, error) { 20 | 21 | @Throws(IOException::class) 22 | @Suppress("UNCHECKED_CAST") 23 | constructor(sin: StreamInput) : this( 24 | sin.readString(), 25 | sin.readException() as Exception?, // error 26 | sin.readMap(StreamInput::readString, ::AggregationResultBucket), 27 | sin.readMap() as MutableMap> 28 | ) 29 | 30 | override fun internalXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 31 | return builder 32 | .field(AGG_RESULT_BUCKETS, aggregationResultBuckets) 33 | .field(ACTIONS_RESULTS, actionResultsMap as Map) 34 | } 35 | 36 | @Throws(IOException::class) 37 | @Suppress("UNCHECKED_CAST") 38 | override fun writeTo(out: StreamOutput) { 39 | super.writeTo(out) 40 | out.writeMap(aggregationResultBuckets, StreamOutput::writeString) { 41 | valueOut: StreamOutput, aggResultBucket: AggregationResultBucket -> 42 | aggResultBucket.writeTo(valueOut) 43 | } 44 | out.writeMap(actionResultsMap as Map) 45 | } 46 | 47 | companion object { 48 | const val AGG_RESULT_BUCKETS = "agg_result_buckets" 49 | const val ACTIONS_RESULTS = "action_results" 50 | 51 | @JvmStatic 52 | @Throws(IOException::class) 53 | fun readFrom(sin: StreamInput): TriggerRunResult { 54 | return BucketLevelTriggerRunResult(sin) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/model/QueryLevelTriggerRunResult.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.model 7 | 8 | import org.opensearch.commons.alerting.alerts.AlertError 9 | import org.opensearch.core.common.io.stream.StreamInput 10 | import org.opensearch.core.common.io.stream.StreamOutput 11 | import org.opensearch.core.xcontent.ToXContent 12 | import org.opensearch.core.xcontent.XContentBuilder 13 | import org.opensearch.script.ScriptException 14 | import java.io.IOException 15 | import java.time.Instant 16 | 17 | open class QueryLevelTriggerRunResult( 18 | override var triggerName: String, 19 | open var triggered: Boolean, 20 | override var error: Exception?, 21 | open var actionResults: MutableMap = mutableMapOf() 22 | ) : TriggerRunResult(triggerName, error) { 23 | 24 | @Throws(IOException::class) 25 | @Suppress("UNCHECKED_CAST") 26 | constructor(sin: StreamInput) : this( 27 | triggerName = sin.readString(), 28 | error = sin.readException(), 29 | triggered = sin.readBoolean(), 30 | actionResults = sin.readMap() as MutableMap 31 | ) 32 | 33 | override fun alertError(): AlertError? { 34 | if (error != null) { 35 | return AlertError(Instant.now(), "Failed evaluating trigger:\n${error!!.userErrorMessage()}") 36 | } 37 | for (actionResult in actionResults.values) { 38 | if (actionResult.error != null) { 39 | return AlertError(Instant.now(), "Failed running action:\n${actionResult.error.userErrorMessage()}") 40 | } 41 | } 42 | return null 43 | } 44 | 45 | override fun internalXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 46 | if (error is ScriptException) error = Exception((error as ScriptException).toJsonString(), error) 47 | return builder 48 | .field("triggered", triggered) 49 | .field("action_results", actionResults as Map) 50 | } 51 | 52 | @Throws(IOException::class) 53 | override fun writeTo(out: StreamOutput) { 54 | super.writeTo(out) 55 | out.writeBoolean(triggered) 56 | out.writeMap(actionResults as Map) 57 | } 58 | 59 | companion object { 60 | @JvmStatic 61 | @Throws(IOException::class) 62 | fun readFrom(sin: StreamInput): TriggerRunResult { 63 | return QueryLevelTriggerRunResult(sin) 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/model/Table.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.opensearch.core.common.io.stream.StreamInput 4 | import org.opensearch.core.common.io.stream.StreamOutput 5 | import org.opensearch.core.common.io.stream.Writeable 6 | import java.io.IOException 7 | 8 | data class Table( 9 | val sortOrder: String, 10 | val sortString: String, 11 | val missing: String?, 12 | val size: Int, 13 | val startIndex: Int, 14 | val searchString: String? 15 | ) : Writeable { 16 | 17 | @Throws(IOException::class) 18 | constructor(sin: StreamInput) : this( 19 | sortOrder = sin.readString(), 20 | sortString = sin.readString(), 21 | missing = sin.readOptionalString(), 22 | size = sin.readInt(), 23 | startIndex = sin.readInt(), 24 | searchString = sin.readOptionalString() 25 | ) 26 | 27 | @Throws(IOException::class) 28 | override fun writeTo(out: StreamOutput) { 29 | out.writeString(sortOrder) 30 | out.writeString(sortString) 31 | out.writeOptionalString(missing) 32 | out.writeInt(size) 33 | out.writeInt(startIndex) 34 | out.writeOptionalString(searchString) 35 | } 36 | 37 | companion object { 38 | @JvmStatic 39 | @Throws(IOException::class) 40 | fun readFrom(sin: StreamInput): Table { 41 | return Table(sin) 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/model/TriggerRunResult.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.model 7 | 8 | import org.opensearch.commons.alerting.alerts.AlertError 9 | import org.opensearch.core.common.io.stream.StreamOutput 10 | import org.opensearch.core.common.io.stream.Writeable 11 | import org.opensearch.core.xcontent.ToXContent 12 | import org.opensearch.core.xcontent.XContentBuilder 13 | import java.io.IOException 14 | import java.time.Instant 15 | 16 | abstract class TriggerRunResult( 17 | open var triggerName: String, 18 | open var error: Exception? = null 19 | ) : Writeable, ToXContent { 20 | 21 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 22 | builder.startObject() 23 | .field("name", triggerName) 24 | 25 | internalXContent(builder, params) 26 | val msg = error?.message 27 | 28 | builder.field("error", msg) 29 | .endObject() 30 | return builder 31 | } 32 | 33 | abstract fun internalXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder 34 | 35 | /** Returns error information to store in the Alert. Currently it's just the stack trace but it can be more */ 36 | open fun alertError(): AlertError? { 37 | if (error != null) { 38 | return AlertError(Instant.now(), "Failed evaluating trigger:\n${error!!.userErrorMessage()}") 39 | } 40 | return null 41 | } 42 | 43 | @Throws(IOException::class) 44 | override fun writeTo(out: StreamOutput) { 45 | out.writeString(triggerName) 46 | out.writeException(error) 47 | } 48 | 49 | companion object { 50 | @Suppress("UNCHECKED_CAST") 51 | fun suppressWarning(map: MutableMap?): MutableMap { 52 | return map as MutableMap 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/model/WorkflowInput.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.opensearch.commons.notifications.model.BaseModel 4 | import org.opensearch.core.common.io.stream.StreamInput 5 | import org.opensearch.core.xcontent.XContentParser 6 | import org.opensearch.core.xcontent.XContentParserUtils 7 | import java.io.IOException 8 | 9 | interface WorkflowInput : BaseModel { 10 | 11 | enum class Type(val value: String) { 12 | COMPOSITE_INPUT(CompositeInput.COMPOSITE_INPUT_FIELD); 13 | 14 | override fun toString(): String { 15 | return value 16 | } 17 | } 18 | 19 | companion object { 20 | 21 | @Throws(IOException::class) 22 | fun parse(xcp: XContentParser): WorkflowInput { 23 | XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) 24 | XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp) 25 | XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) 26 | val input = if (xcp.currentName() == Type.COMPOSITE_INPUT.value) { 27 | CompositeInput.parse(xcp) 28 | } else { 29 | throw IllegalStateException("Unexpected input type when reading Input") 30 | } 31 | XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, xcp.nextToken(), xcp) 32 | return input 33 | } 34 | 35 | @JvmStatic 36 | @Throws(IOException::class) 37 | fun readFrom(sin: StreamInput): WorkflowInput { 38 | return when (val type = sin.readEnum(Type::class.java)) { 39 | Type.COMPOSITE_INPUT -> CompositeInput(sin) 40 | // This shouldn't be reachable but ensuring exhaustiveness as Kotlin warns 41 | // enum can be null in Java 42 | else -> throw IllegalStateException("Unexpected input [$type] when reading Trigger") 43 | } 44 | } 45 | } 46 | 47 | fun name(): String 48 | } 49 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/settings/SupportedClusterMetricsSettings.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.settings 2 | 3 | import org.opensearch.commons.alerting.model.ClusterMetricsInput 4 | 5 | interface SupportedClusterMetricsSettings { 6 | fun validateApiType(clusterMetricsInput: ClusterMetricsInput) 7 | } 8 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/alerting/util/IndexPatternUtils.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.util 2 | 3 | /** 4 | * Validates that index patterns, wildcards and regex are not used in index names. 5 | */ 6 | object IndexPatternUtils { 7 | private val PATTERN_SPECIAL_CHARS = setOf( 8 | '*', // wildcard for any number of characters 9 | '?', // wildcard for single character 10 | '+', // one or more quantifier 11 | '[', // character class start 12 | ']', // character class end 13 | '(', // group start 14 | ')', // group end 15 | '{', // range quantifier start 16 | '}', // range quantifier end 17 | '|', // OR operator 18 | '\\', // escape character 19 | '.', // any character 20 | '^', // start anchor/negation in character class 21 | '$' // end anchor 22 | ) 23 | 24 | fun containsPatternSyntax(indexName: String): Boolean { 25 | if (indexName.isEmpty() || indexName == "_all") { 26 | return true 27 | } 28 | 29 | // Check for date math expression <...> 30 | if (indexName.startsWith("<") && indexName.endsWith(">")) { 31 | return true 32 | } 33 | 34 | var i = 0 35 | while (i < indexName.length) { 36 | when (val currentChar = indexName[i]) { 37 | '\\' -> i += 2 // Skip escaped character 38 | in PATTERN_SPECIAL_CHARS -> return true 39 | else -> i++ 40 | } 41 | } 42 | return false 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/action/BaseResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.action 7 | 8 | import org.opensearch.core.action.ActionResponse 9 | import org.opensearch.core.common.io.stream.StreamInput 10 | import org.opensearch.core.rest.RestStatus 11 | import org.opensearch.core.xcontent.ToXContentObject 12 | import java.io.IOException 13 | 14 | /** 15 | * Base response which give REST status. 16 | */ 17 | abstract class BaseResponse : ActionResponse, ToXContentObject { 18 | 19 | /** 20 | * constructor for creating the class 21 | */ 22 | constructor() 23 | 24 | /** 25 | * {@inheritDoc} 26 | */ 27 | @Throws(IOException::class) 28 | constructor(input: StreamInput) : super(input) 29 | 30 | /** 31 | * get rest status for the response. Useful override for multi-status response. 32 | * @return RestStatus for the response 33 | */ 34 | open fun getStatus(): RestStatus { 35 | return RestStatus.OK 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/action/GetChannelListResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.action 6 | 7 | import org.opensearch.commons.notifications.model.ChannelList 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | import org.opensearch.core.common.io.stream.StreamOutput 10 | import org.opensearch.core.common.io.stream.Writeable 11 | import org.opensearch.core.xcontent.ToXContent 12 | import org.opensearch.core.xcontent.XContentBuilder 13 | import org.opensearch.core.xcontent.XContentParser 14 | import java.io.IOException 15 | 16 | /** 17 | * Action Response for creating new configuration. 18 | */ 19 | class GetChannelListResponse : BaseResponse { 20 | val searchResult: ChannelList 21 | 22 | companion object { 23 | 24 | /** 25 | * reader to create instance of class from writable. 26 | */ 27 | val reader = Writeable.Reader { GetChannelListResponse(it) } 28 | 29 | /** 30 | * Creator used in REST communication. 31 | * @param parser XContentParser to deserialize data from. 32 | */ 33 | @JvmStatic 34 | @Throws(IOException::class) 35 | fun parse(parser: XContentParser): GetChannelListResponse { 36 | return GetChannelListResponse(ChannelList(parser)) 37 | } 38 | } 39 | 40 | /** 41 | * constructor for creating the class 42 | * @param searchResult the notification configuration list 43 | */ 44 | constructor(searchResult: ChannelList) { 45 | this.searchResult = searchResult 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Throws(IOException::class) 52 | constructor(input: StreamInput) : super(input) { 53 | searchResult = ChannelList(input) 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Throws(IOException::class) 60 | override fun writeTo(output: StreamOutput) { 61 | searchResult.writeTo(output) 62 | } 63 | 64 | /** 65 | * {@inheritDoc} 66 | */ 67 | override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder { 68 | return searchResult.toXContent(builder, params) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/action/GetNotificationConfigResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.action 6 | 7 | import org.opensearch.commons.notifications.model.NotificationConfigSearchResult 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | import org.opensearch.core.common.io.stream.StreamOutput 10 | import org.opensearch.core.common.io.stream.Writeable 11 | import org.opensearch.core.xcontent.ToXContent 12 | import org.opensearch.core.xcontent.XContentBuilder 13 | import org.opensearch.core.xcontent.XContentParser 14 | import java.io.IOException 15 | 16 | /** 17 | * Action Response for getting notification configuration. 18 | */ 19 | class GetNotificationConfigResponse : BaseResponse { 20 | val searchResult: NotificationConfigSearchResult 21 | 22 | companion object { 23 | 24 | /** 25 | * reader to create instance of class from writable. 26 | */ 27 | val reader = Writeable.Reader { GetNotificationConfigResponse(it) } 28 | 29 | /** 30 | * Creator used in REST communication. 31 | * @param parser XContentParser to deserialize data from. 32 | */ 33 | @JvmStatic 34 | @Throws(IOException::class) 35 | fun parse(parser: XContentParser): GetNotificationConfigResponse { 36 | return GetNotificationConfigResponse(NotificationConfigSearchResult(parser)) 37 | } 38 | } 39 | 40 | /** 41 | * constructor for creating the class 42 | * @param searchResult the notification configuration list 43 | */ 44 | constructor(searchResult: NotificationConfigSearchResult) { 45 | this.searchResult = searchResult 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Throws(IOException::class) 52 | constructor(input: StreamInput) : super(input) { 53 | searchResult = NotificationConfigSearchResult(input) 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Throws(IOException::class) 60 | override fun writeTo(output: StreamOutput) { 61 | searchResult.writeTo(output) 62 | } 63 | 64 | /** 65 | * {@inheritDoc} 66 | */ 67 | override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder { 68 | return searchResult.toXContent(builder, params) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/action/LegacyPublishNotificationResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.action 7 | 8 | import org.opensearch.commons.destination.response.LegacyDestinationResponse 9 | import org.opensearch.core.common.io.stream.StreamInput 10 | import org.opensearch.core.common.io.stream.StreamOutput 11 | import org.opensearch.core.common.io.stream.Writeable 12 | import org.opensearch.core.xcontent.ToXContent 13 | import org.opensearch.core.xcontent.XContentBuilder 14 | import java.io.IOException 15 | 16 | /** 17 | * Action Response for legacy publish notification. 18 | */ 19 | class LegacyPublishNotificationResponse : BaseResponse { 20 | val destinationResponse: LegacyDestinationResponse 21 | 22 | companion object { 23 | /** 24 | * reader to create instance of class from writable. 25 | */ 26 | val reader = Writeable.Reader { LegacyPublishNotificationResponse(it) } 27 | } 28 | 29 | /** 30 | * constructor for creating the class 31 | * @param destinationResponse the response of the published notification 32 | */ 33 | constructor(destinationResponse: LegacyDestinationResponse) { 34 | this.destinationResponse = destinationResponse 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Throws(IOException::class) 41 | constructor(input: StreamInput) : super(input) { 42 | destinationResponse = LegacyDestinationResponse(input) 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Throws(IOException::class) 49 | override fun writeTo(output: StreamOutput) { 50 | destinationResponse.writeTo(output) 51 | } 52 | 53 | // This class is only used across transport wire and does not need to implement toXContent 54 | override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { 55 | throw IllegalStateException("Legacy notification response is not intended for REST or persistence and does not support XContent.") 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/action/SendNotificationResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.action 6 | 7 | import org.opensearch.commons.notifications.model.NotificationEvent 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | import org.opensearch.core.common.io.stream.StreamOutput 10 | import org.opensearch.core.common.io.stream.Writeable 11 | import org.opensearch.core.xcontent.ToXContent 12 | import org.opensearch.core.xcontent.XContentBuilder 13 | import org.opensearch.core.xcontent.XContentParser 14 | import java.io.IOException 15 | 16 | /** 17 | * Action Response for send notification. 18 | */ 19 | class SendNotificationResponse : BaseResponse { 20 | val notificationEvent: NotificationEvent 21 | 22 | companion object { 23 | 24 | /** 25 | * reader to create instance of class from writable. 26 | */ 27 | val reader = Writeable.Reader { SendNotificationResponse(it) } 28 | 29 | /** 30 | * Creator used in REST communication. 31 | * @param parser XContentParser to deserialize data from. 32 | */ 33 | @JvmStatic 34 | @Throws(IOException::class) 35 | fun parse(parser: XContentParser): SendNotificationResponse { 36 | return SendNotificationResponse(NotificationEvent.parse(parser)) 37 | } 38 | } 39 | 40 | /** 41 | * constructor for creating the class 42 | * @param notificationEvent the id of the created notification configuration 43 | */ 44 | constructor(notificationEvent: NotificationEvent) { 45 | this.notificationEvent = notificationEvent 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Throws(IOException::class) 52 | constructor(input: StreamInput) : super(input) { 53 | notificationEvent = NotificationEvent(input) 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Throws(IOException::class) 60 | override fun writeTo(output: StreamOutput) { 61 | notificationEvent.writeTo(output) 62 | } 63 | 64 | /** 65 | * {@inheritDoc} 66 | */ 67 | override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder { 68 | return notificationEvent.toXContent(builder, params) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/BaseConfigData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.model 7 | 8 | /** 9 | * Marker interface for Channel Data 10 | */ 11 | interface BaseConfigData : BaseModel 12 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/BaseModel.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.model 6 | 7 | import org.opensearch.core.common.io.stream.Writeable 8 | import org.opensearch.core.xcontent.ToXContentObject 9 | 10 | /** 11 | * interface for representing objects. 12 | */ 13 | interface BaseModel : Writeable, ToXContentObject 14 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/ChannelList.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.model 7 | 8 | import org.apache.lucene.search.TotalHits 9 | import org.opensearch.action.search.SearchResponse 10 | import org.opensearch.commons.notifications.NotificationConstants.CHANNEL_LIST_TAG 11 | import org.opensearch.core.common.io.stream.StreamInput 12 | import org.opensearch.core.xcontent.XContentParser 13 | 14 | /** 15 | * Channel search results 16 | */ 17 | class ChannelList : SearchResults { 18 | 19 | /** 20 | * single item result constructor 21 | */ 22 | constructor(objectItem: Channel) : super(CHANNEL_LIST_TAG, objectItem) 23 | 24 | /** 25 | * multiple items result constructor 26 | */ 27 | constructor(objectList: List) : this( 28 | 0, 29 | objectList.size.toLong(), 30 | TotalHits.Relation.EQUAL_TO, 31 | objectList 32 | ) 33 | 34 | /** 35 | * all param constructor 36 | */ 37 | constructor( 38 | startIndex: Long, 39 | totalHits: Long, 40 | totalHitRelation: TotalHits.Relation, 41 | objectList: List 42 | ) : super(startIndex, totalHits, totalHitRelation, CHANNEL_LIST_TAG, objectList) 43 | 44 | /** 45 | * Constructor used in transport action communication. 46 | * @param input StreamInput stream to deserialize data from. 47 | */ 48 | constructor(input: StreamInput) : super(input, Channel.reader) 49 | 50 | /** 51 | * Construct object from XContentParser 52 | */ 53 | constructor(parser: XContentParser) : super(parser, CHANNEL_LIST_TAG) 54 | 55 | /** 56 | * Construct object from SearchResponse 57 | */ 58 | constructor(from: Long, response: SearchResponse, searchHitParser: SearchHitParser) : super( 59 | from, 60 | response, 61 | searchHitParser, 62 | CHANNEL_LIST_TAG 63 | ) 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | override fun parseItem(parser: XContentParser): Channel { 69 | return Channel.parse(parser) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/ConfigType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.model 6 | 7 | import org.opensearch.commons.utils.EnumParser 8 | 9 | /** 10 | * Enum for Notification config type 11 | */ 12 | enum class ConfigType(val tag: String) { 13 | NONE("none") { 14 | override fun toString(): String { 15 | return tag 16 | } 17 | }, 18 | SLACK("slack") { 19 | override fun toString(): String { 20 | return tag 21 | } 22 | }, 23 | CHIME("chime") { 24 | override fun toString(): String { 25 | return tag 26 | } 27 | }, 28 | WEBHOOK("webhook") { 29 | override fun toString(): String { 30 | return tag 31 | } 32 | }, 33 | EMAIL("email") { 34 | override fun toString(): String { 35 | return tag 36 | } 37 | }, 38 | SNS("sns") { 39 | override fun toString(): String { 40 | return tag 41 | } 42 | }, 43 | SES_ACCOUNT("ses_account") { 44 | override fun toString(): String { 45 | return tag 46 | } 47 | }, 48 | SMTP_ACCOUNT("smtp_account") { 49 | override fun toString(): String { 50 | return tag 51 | } 52 | }, 53 | EMAIL_GROUP("email_group") { 54 | override fun toString(): String { 55 | return tag 56 | } 57 | }, 58 | MICROSOFT_TEAMS("microsoft_teams") { 59 | override fun toString(): String { 60 | return tag 61 | } 62 | }; 63 | 64 | companion object { 65 | private val tagMap = values().associateBy { it.tag } 66 | 67 | val enumParser = EnumParser { fromTagOrDefault(it) } 68 | 69 | /** 70 | * Get ConfigType from tag or NONE if not found 71 | * @param tag the tag 72 | * @return ConfigType corresponding to tag. NONE if invalid tag. 73 | */ 74 | fun fromTagOrDefault(tag: String): ConfigType { 75 | return tagMap[tag] ?: NONE 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/HttpMethodType.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.notifications.model 2 | 3 | import org.opensearch.commons.utils.EnumParser 4 | 5 | enum class HttpMethodType(val tag: String) { 6 | POST("POST") { 7 | override fun toString(): String { 8 | return tag 9 | } 10 | }, 11 | PUT("PUT") { 12 | override fun toString(): String { 13 | return tag 14 | } 15 | }, 16 | PATCH("PATCH") { 17 | override fun toString(): String { 18 | return tag 19 | } 20 | }; 21 | 22 | companion object { 23 | private val tagMap = values().associateBy { it.tag } 24 | 25 | val enumParser = EnumParser { fromTagOrDefault(it) } 26 | 27 | /** 28 | * Get HttpMethodType from tag or POST if not found 29 | * @param tag the tag 30 | * @return MethodType corresponding to tag. POST if invalid tag. 31 | */ 32 | fun fromTagOrDefault(tag: String): HttpMethodType { 33 | return tagMap[tag] ?: POST 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/MethodType.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.notifications.model 2 | 3 | import org.opensearch.commons.utils.EnumParser 4 | 5 | enum class MethodType(val tag: String) { 6 | NONE("none") { 7 | override fun toString(): String { 8 | return tag 9 | } 10 | }, 11 | SSL("ssl") { 12 | override fun toString(): String { 13 | return tag 14 | } 15 | }, 16 | START_TLS("start_tls") { 17 | override fun toString(): String { 18 | return tag 19 | } 20 | }; 21 | 22 | companion object { 23 | private val tagMap = values().associateBy { it.tag } 24 | 25 | val enumParser = EnumParser { fromTagOrDefault(it) } 26 | 27 | /** 28 | * Get MethodType from tag or NONE if not found 29 | * @param tag the tag 30 | * @return MethodType corresponding to tag. NONE if invalid tag. 31 | */ 32 | fun fromTagOrDefault(tag: String): MethodType { 33 | return tagMap[tag] ?: NONE 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfigSearchResult.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.model 7 | 8 | import org.apache.lucene.search.TotalHits 9 | import org.opensearch.action.search.SearchResponse 10 | import org.opensearch.commons.notifications.NotificationConstants.CONFIG_LIST_TAG 11 | import org.opensearch.core.common.io.stream.StreamInput 12 | import org.opensearch.core.xcontent.XContentParser 13 | 14 | /** 15 | * NotificationConfig search results 16 | */ 17 | class NotificationConfigSearchResult : SearchResults { 18 | 19 | /** 20 | * single item result constructor 21 | */ 22 | constructor(objectItem: NotificationConfigInfo) : super(CONFIG_LIST_TAG, objectItem) 23 | 24 | /** 25 | * multiple items result constructor 26 | */ 27 | constructor(objectList: List) : this( 28 | 0, 29 | objectList.size.toLong(), 30 | TotalHits.Relation.EQUAL_TO, 31 | objectList 32 | ) 33 | 34 | /** 35 | * all param constructor 36 | */ 37 | constructor( 38 | startIndex: Long, 39 | totalHits: Long, 40 | totalHitRelation: TotalHits.Relation, 41 | objectList: List 42 | ) : super(startIndex, totalHits, totalHitRelation, CONFIG_LIST_TAG, objectList) 43 | 44 | /** 45 | * Constructor used in transport action communication. 46 | * @param input StreamInput stream to deserialize data from. 47 | */ 48 | constructor(input: StreamInput) : super(input, NotificationConfigInfo.reader) 49 | 50 | /** 51 | * Construct object from XContentParser 52 | */ 53 | constructor(parser: XContentParser) : super(parser, CONFIG_LIST_TAG) 54 | 55 | /** 56 | * Construct object from SearchResponse 57 | */ 58 | constructor(from: Long, response: SearchResponse, searchHitParser: SearchHitParser) : super( 59 | from, 60 | response, 61 | searchHitParser, 62 | CONFIG_LIST_TAG 63 | ) 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | override fun parseItem(parser: XContentParser): NotificationConfigInfo { 69 | return NotificationConfigInfo.parse(parser) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/SeverityType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.model 7 | 8 | import org.opensearch.commons.utils.EnumParser 9 | 10 | /** 11 | * Notification severity type 12 | */ 13 | enum class SeverityType(val tag: String) { 14 | NONE("none") { 15 | override fun toString(): String { 16 | return tag 17 | } 18 | }, 19 | HIGH("high") { 20 | override fun toString(): String { 21 | return tag 22 | } 23 | }, 24 | INFO("info") { 25 | override fun toString(): String { 26 | return tag 27 | } 28 | }, 29 | CRITICAL("critical") { 30 | override fun toString(): String { 31 | return tag 32 | } 33 | }; 34 | 35 | companion object { 36 | private val tagMap = values().associateBy { it.tag } 37 | 38 | val enumParser = EnumParser { fromTagOrDefault(it) } 39 | 40 | /** 41 | * Get SeverityType from tag or NONE if not found 42 | * @param tag the tag 43 | * @return SeverityType corresponding to tag. NONE if invalid tag. 44 | */ 45 | fun fromTagOrDefault(tag: String): SeverityType { 46 | return tagMap[tag] ?: NONE 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/notifications/model/XParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.model 6 | 7 | import org.opensearch.core.xcontent.XContentParser 8 | 9 | /** 10 | * Functional interface to create config data object using XContentParser 11 | */ 12 | fun interface XParser { 13 | /** 14 | * Creator used in REST communication. 15 | * @param parser XContentParser to deserialize data from. 16 | */ 17 | fun parse(parser: XContentParser): V 18 | } 19 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/replication/action/ReplicationActions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.replication.action 6 | 7 | import org.opensearch.action.ActionType 8 | import org.opensearch.action.support.clustermanager.AcknowledgedResponse 9 | 10 | /** 11 | * Information related to the transport stop replication action for the Replication plugin 12 | */ 13 | object ReplicationActions { 14 | 15 | /** 16 | * Action names for stopping replication 17 | * STOP_REPLICATION_ACTION_NAME: action used for _replication/_stop REST API 18 | * INTERNAL_STOP_REPLICATION_ACTION_NAME: Internal only - Used by Index Management plugin to invoke stop replication 19 | */ 20 | const val STOP_REPLICATION_ACTION_NAME = "indices:admin/plugins/replication/index/stop" 21 | const val INTERNAL_STOP_REPLICATION_ACTION_NAME = "indices:internal/plugins/replication/index/stop" 22 | 23 | /** 24 | * Stop replication transport action types. 25 | */ 26 | val STOP_REPLICATION_ACTION_TYPE = 27 | ActionType(STOP_REPLICATION_ACTION_NAME, ::AcknowledgedResponse) 28 | val INTERNAL_STOP_REPLICATION_ACTION_TYPE = 29 | ActionType(INTERNAL_STOP_REPLICATION_ACTION_NAME, ::AcknowledgedResponse) 30 | } 31 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/utils/EnumHelpers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.utils 6 | 7 | import org.opensearch.core.common.io.stream.StreamOutput 8 | import org.opensearch.core.common.io.stream.Writeable 9 | import org.opensearch.core.xcontent.XContentParser 10 | import org.opensearch.core.xcontent.XContentParserUtils 11 | import java.util.EnumSet 12 | 13 | inline fun > XContentParser.enumSet(enumParser: EnumParser): EnumSet { 14 | val retSet: EnumSet = EnumSet.noneOf(E::class.java) 15 | XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_ARRAY, currentToken(), this) 16 | while (nextToken() != XContentParser.Token.END_ARRAY) { 17 | retSet.add(enumParser.fromTagOrDefault(text())) 18 | } 19 | return retSet 20 | } 21 | 22 | inline fun > enumReader(enumClass: Class): Writeable.Reader { 23 | return Writeable.Reader { 24 | it.readEnum(enumClass) 25 | } 26 | } 27 | 28 | @Suppress("UnusedPrivateMember") 29 | inline fun > enumWriter(ignore: Class): Writeable.Writer { 30 | return Writeable.Writer { streamOutput: StreamOutput, value: E -> 31 | streamOutput.writeEnum(value) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/utils/EnumParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.utils 6 | 7 | /** 8 | * Functional interface to create config data object using XContentParser 9 | */ 10 | fun interface EnumParser { 11 | /** 12 | * Get Enum from tag or default value if not found 13 | * @param tag the tag 14 | * @return Enum corresponding to tag. default value if invalid tag. 15 | */ 16 | fun fromTagOrDefault(tag: String): E 17 | } 18 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/utils/Helpers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.utils 7 | 8 | import org.apache.logging.log4j.LogManager 9 | import org.apache.logging.log4j.Logger 10 | 11 | fun logger(forClass: Class): Lazy { 12 | return lazy { LogManager.getLogger(forClass) } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/utils/OpenForTesting.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.utils 7 | 8 | /** 9 | * Annotation to elevate access for testing purpose. 10 | */ 11 | annotation class OpenForTesting 12 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/utils/TransportHelpers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.utils 7 | 8 | import org.opensearch.core.common.io.stream.InputStreamStreamInput 9 | import org.opensearch.core.common.io.stream.NamedWriteableAwareStreamInput 10 | import org.opensearch.core.common.io.stream.NamedWriteableRegistry 11 | import org.opensearch.core.common.io.stream.OutputStreamStreamOutput 12 | import org.opensearch.core.common.io.stream.StreamInput 13 | import org.opensearch.core.common.io.stream.StreamOutput 14 | import org.opensearch.core.common.io.stream.Writeable 15 | import java.io.ByteArrayInputStream 16 | import java.io.ByteArrayOutputStream 17 | 18 | val STRING_READER = Writeable.Reader { 19 | it.readString() 20 | } 21 | 22 | val STRING_WRITER = Writeable.Writer { output: StreamOutput, value: String -> 23 | output.writeString(value) 24 | } 25 | 26 | /** 27 | * Re create the object from the writeable. 28 | * This method needs to be inline and reified so that when this is called from 29 | * doExecute() of transport action, the object may be created from other JVM. 30 | */ 31 | inline fun recreateObject(writeable: Writeable, block: (StreamInput) -> Request): Request { 32 | ByteArrayOutputStream().use { byteArrayOutputStream -> 33 | OutputStreamStreamOutput(byteArrayOutputStream).use { 34 | writeable.writeTo(it) 35 | InputStreamStreamInput(ByteArrayInputStream(byteArrayOutputStream.toByteArray())).use { streamInput -> 36 | return block(streamInput) 37 | } 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * Re create the object from the writeable. Uses NamedWriteableRegistry in order to build the aggregations. 44 | * This method needs to be inline and reified so that when this is called from 45 | * doExecute() of transport action, the object may be created from other JVM. 46 | */ 47 | inline fun recreateObject(writeable: Writeable, namedWriteableRegistry: NamedWriteableRegistry, block: (StreamInput) -> Request): Request { 48 | ByteArrayOutputStream().use { byteArrayOutputStream -> 49 | OutputStreamStreamOutput(byteArrayOutputStream).use { 50 | writeable.writeTo(it) 51 | InputStreamStreamInput(ByteArrayInputStream(byteArrayOutputStream.toByteArray())).use { streamInput -> 52 | return block(NamedWriteableAwareStreamInput(streamInput, namedWriteableRegistry)) 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/kotlin/org/opensearch/commons/utils/XContentHelpers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.utils 7 | 8 | import org.opensearch.common.xcontent.XContentType 9 | import org.opensearch.core.common.io.stream.StreamInput 10 | import org.opensearch.core.xcontent.DeprecationHandler 11 | import org.opensearch.core.xcontent.NamedXContentRegistry 12 | import org.opensearch.core.xcontent.ToXContent 13 | import org.opensearch.core.xcontent.ToXContentObject 14 | import org.opensearch.core.xcontent.XContentBuilder 15 | import org.opensearch.core.xcontent.XContentParser 16 | import org.opensearch.core.xcontent.XContentParserUtils 17 | import org.opensearch.rest.RestRequest 18 | 19 | fun StreamInput.createJsonParser(): XContentParser { 20 | return XContentType.JSON.xContent() 21 | .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.IGNORE_DEPRECATIONS, this) 22 | } 23 | 24 | fun RestRequest.contentParserNextToken(): XContentParser { 25 | val parser = this.contentParser() 26 | parser.nextToken() 27 | return parser 28 | } 29 | 30 | fun XContentParser.stringList(): List { 31 | val retList: MutableList = mutableListOf() 32 | XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_ARRAY, currentToken(), this) 33 | while (nextToken() != XContentParser.Token.END_ARRAY) { 34 | retList.add(text()) 35 | } 36 | return retList 37 | } 38 | 39 | fun XContentBuilder.fieldIfNotNull(name: String, value: Any?): XContentBuilder { 40 | if (value != null) { 41 | this.field(name, value) 42 | } 43 | return this 44 | } 45 | 46 | fun XContentBuilder.objectIfNotNull(name: String, xContentObject: ToXContentObject?): XContentBuilder { 47 | if (xContentObject != null) { 48 | this.field(name) 49 | xContentObject.toXContent(this, ToXContent.EMPTY_PARAMS) 50 | } 51 | return this 52 | } 53 | 54 | fun XContentParser.objectList(block: (XContentParser) -> T): List { 55 | val retList: MutableList = mutableListOf() 56 | XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_ARRAY, currentToken(), this) 57 | while (nextToken() != XContentParser.Token.END_ARRAY) { 58 | retList.add(block(this)) 59 | } 60 | return retList 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/opensearch/commons/ConfigConstantsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons; 7 | 8 | import org.junit.jupiter.api.Assertions; 9 | import org.junit.jupiter.api.Test; 10 | import org.opensearch.common.settings.MockSecureSettings; 11 | import org.opensearch.common.settings.Settings; 12 | 13 | public class ConfigConstantsTest { 14 | private void assertPasswords(Settings settings, String expectedPassword, String expectedKeyPassword) { 15 | final var password = ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD_SETTING.get(settings); 16 | Assertions.assertEquals(expectedPassword, password.toString()); 17 | 18 | final var keyPassword = ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD_SETTING.get(settings); 19 | Assertions.assertEquals(expectedKeyPassword, keyPassword.toString()); 20 | } 21 | 22 | @Test 23 | public void testLegacyHttpKeystorePassword() { 24 | final var settings = Settings 25 | .builder() 26 | .put("plugins.security.ssl.http.keystore_password", "legacy-password") 27 | .put("plugins.security.ssl.http.keystore_keypassword", "legacy-keypassword") 28 | .build(); 29 | 30 | assertPasswords(settings, "legacy-password", "legacy-keypassword"); 31 | } 32 | 33 | @Test 34 | public void testSecureHttpKeystorePassword() { 35 | final var mockSecureSettings = new MockSecureSettings(); 36 | // deliberately not using constants here to verify correct concatenation of legacy + _secure suffix 37 | mockSecureSettings.setString("plugins.security.ssl.http.keystore_password_secure", "password"); 38 | mockSecureSettings.setString("plugins.security.ssl.http.keystore_keypassword_secure", "keypassword"); 39 | 40 | final var settings = Settings 41 | .builder() 42 | // check priority that secure variants are taken over the legacy ones 43 | .put("plugins.security.ssl.http.keystore_password", "legacy-password") 44 | .put("plugins.security.ssl.http.keystore_keypassword", "legacy-keypassword") 45 | .setSecureSettings(mockSecureSettings) 46 | .build(); 47 | 48 | assertPasswords(settings, "password", "keypassword"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/opensearch/commons/destination/response/LegacyDestinationResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.destination.response; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.fail; 10 | 11 | import java.io.IOException; 12 | 13 | import org.junit.jupiter.api.Test; 14 | import org.opensearch.common.io.stream.BytesStreamOutput; 15 | import org.opensearch.core.common.io.stream.StreamInput; 16 | 17 | public class LegacyDestinationResponseTest { 18 | 19 | @Test 20 | public void testBuildingLegacyDestinationResponse() { 21 | LegacyDestinationResponse res = new LegacyDestinationResponse.Builder() 22 | .withStatusCode(200) 23 | .withResponseContent("Hello world") 24 | .build(); 25 | 26 | assertEquals(200, res.statusCode); 27 | assertEquals("Hello world", res.getResponseContent()); 28 | } 29 | 30 | @Test 31 | public void testRoundTrippingLegacyDestinationResponse() throws IOException { 32 | LegacyDestinationResponse res = new LegacyDestinationResponse.Builder() 33 | .withStatusCode(200) 34 | .withResponseContent("Hello world") 35 | .build(); 36 | BytesStreamOutput out = new BytesStreamOutput(); 37 | res.writeTo(out); 38 | 39 | StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes); 40 | LegacyDestinationResponse newRes = new LegacyDestinationResponse(in); 41 | 42 | assertEquals(res.statusCode, newRes.statusCode, "Round tripping doesn't work"); 43 | assertEquals(res.getResponseContent(), newRes.getResponseContent(), "Round tripping doesn't work"); 44 | } 45 | 46 | @Test 47 | public void testMissingLegacyDestinationResponse() { 48 | try { 49 | new LegacyDestinationResponse.Builder().withStatusCode(200).build(); 50 | fail("Creating LegacyDestinationResponse without response content should fail"); 51 | } catch (IllegalArgumentException ignored) {} 52 | } 53 | 54 | @Test 55 | public void testMissingLegacyDestinationStatusCode() { 56 | try { 57 | new LegacyDestinationResponse.Builder().withResponseContent("Hello world").build(); 58 | fail("Creating LegacyDestinationResponse without status code should fail"); 59 | } catch (IllegalArgumentException ignored) {} 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/opensearch/commons/rest/TrustStoreTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.rest; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.assertNotNull; 10 | import static org.junit.jupiter.api.Assertions.assertTrue; 11 | 12 | import java.io.File; 13 | import java.security.KeyStore; 14 | 15 | import org.junit.jupiter.api.Test; 16 | 17 | public class TrustStoreTest { 18 | 19 | @Test 20 | public void testCreate() throws Exception { 21 | String resourceName = "sample.pem"; 22 | String absolutePath = new File(getClass().getClassLoader().getResource(resourceName).getFile()).getAbsolutePath(); 23 | assertTrue(absolutePath.endsWith(File.separator + "sample.pem")); 24 | 25 | KeyStore store = new TrustStore(absolutePath).create(); 26 | assertNotNull(store); 27 | assertEquals("JKS", store.getType()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/MonitorTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.opensearch.commons.alerting.model.Trigger 5 | import org.opensearch.test.OpenSearchTestCase 6 | import java.lang.IllegalArgumentException 7 | import java.time.Instant 8 | 9 | internal class MonitorTests { 10 | @Test 11 | fun `test enabled time`() { 12 | val monitor = randomQueryLevelMonitor() 13 | val enabledMonitor = monitor.copy(enabled = true, enabledTime = Instant.now()) 14 | try { 15 | enabledMonitor.copy(enabled = false) 16 | OpenSearchTestCase.fail("Disabling monitor with enabled time set should fail.") 17 | } catch (e: IllegalArgumentException) { 18 | } 19 | 20 | val disabledMonitor = monitor.copy(enabled = false, enabledTime = null) 21 | 22 | try { 23 | disabledMonitor.copy(enabled = true) 24 | OpenSearchTestCase.fail("Enabling monitor without enabled time should fail") 25 | } catch (e: IllegalArgumentException) { 26 | } 27 | } 28 | 29 | @Test 30 | fun `test max triggers`() { 31 | val monitor = randomQueryLevelMonitor() 32 | 33 | val tooManyTriggers = mutableListOf() 34 | var i = 0 35 | while (i <= 10) { 36 | tooManyTriggers.add(randomQueryLevelTrigger()) 37 | ++i 38 | } 39 | 40 | try { 41 | monitor.copy(triggers = tooManyTriggers) 42 | OpenSearchTestCase.fail("Monitor with too many triggers should be rejected.") 43 | } catch (e: IllegalArgumentException) { 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/AcknowledgeAlertRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.junit.jupiter.api.Assertions.assertEquals 9 | import org.junit.jupiter.api.Assertions.assertNotNull 10 | import org.junit.jupiter.api.Test 11 | import org.opensearch.action.support.WriteRequest 12 | import org.opensearch.common.io.stream.BytesStreamOutput 13 | import org.opensearch.core.common.io.stream.StreamInput 14 | 15 | class AcknowledgeAlertRequestTests { 16 | 17 | @Test 18 | fun `test acknowledge alert request`() { 19 | val req = AcknowledgeAlertRequest("1234", mutableListOf("1", "2", "3", "4"), WriteRequest.RefreshPolicy.IMMEDIATE) 20 | assertNotNull(req) 21 | val out = BytesStreamOutput() 22 | req.writeTo(out) 23 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 24 | val newReq = AcknowledgeAlertRequest(sin) 25 | assertEquals("1234", newReq.monitorId) 26 | assertEquals(4, newReq.alertIds.size) 27 | assertEquals(WriteRequest.RefreshPolicy.IMMEDIATE, newReq.refreshPolicy) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.junit.jupiter.api.Assertions.assertEquals 9 | import org.junit.jupiter.api.Assertions.assertNotNull 10 | import org.junit.jupiter.api.Assertions.assertNull 11 | import org.junit.jupiter.api.Test 12 | import org.opensearch.common.io.stream.BytesStreamOutput 13 | import org.opensearch.core.common.io.stream.StreamInput 14 | 15 | class AcknowledgeChainedAlertRequestTests { 16 | 17 | @Test 18 | fun `test acknowledge chained alert request`() { 19 | val req = AcknowledgeChainedAlertRequest("1234", mutableListOf("1", "2", "3", "4")) 20 | assertNotNull(req) 21 | val out = BytesStreamOutput() 22 | req.writeTo(out) 23 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 24 | val newReq = AcknowledgeChainedAlertRequest(sin) 25 | assertEquals("1234", newReq.workflowId) 26 | assertEquals(4, newReq.alertIds.size) 27 | assertNull(newReq.validate()) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/DeleteCommentRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Assertions.assertNotNull 5 | import org.junit.jupiter.api.Test 6 | import org.opensearch.common.io.stream.BytesStreamOutput 7 | import org.opensearch.core.common.io.stream.StreamInput 8 | 9 | class DeleteCommentRequestTests { 10 | @Test 11 | fun `test delete comment request writing and parsing`() { 12 | val req = DeleteCommentRequest("1234") 13 | assertNotNull(req) 14 | assertEquals("1234", req.commentId) 15 | 16 | val out = BytesStreamOutput() 17 | req.writeTo(out) 18 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 19 | val newReq = DeleteCommentRequest(sin) 20 | assertEquals("1234", newReq.commentId) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/DeleteCommentResponseTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Assertions.assertNotNull 5 | import org.junit.jupiter.api.Test 6 | import org.opensearch.common.io.stream.BytesStreamOutput 7 | import org.opensearch.core.common.io.stream.StreamInput 8 | 9 | class DeleteCommentResponseTests { 10 | @Test 11 | fun `test delete comment response writing and parsing`() { 12 | val res = DeleteCommentResponse(id = "123") 13 | assertNotNull(res) 14 | assertEquals("123", res.commentId) 15 | 16 | val out = BytesStreamOutput() 17 | res.writeTo(out) 18 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 19 | val newRes = DeleteCommentResponse(sin) 20 | assertEquals("123", newRes.commentId) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/DeleteMonitorRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Assertions.assertNotNull 5 | import org.junit.jupiter.api.Test 6 | import org.opensearch.action.support.WriteRequest 7 | import org.opensearch.common.io.stream.BytesStreamOutput 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | 10 | class DeleteMonitorRequestTests { 11 | 12 | @Test 13 | fun `test delete monitor request`() { 14 | val req = DeleteMonitorRequest("1234", WriteRequest.RefreshPolicy.IMMEDIATE) 15 | assertNotNull(req) 16 | assertEquals("1234", req.monitorId) 17 | assertEquals("true", req.refreshPolicy.value) 18 | 19 | val out = BytesStreamOutput() 20 | req.writeTo(out) 21 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 22 | val newReq = DeleteMonitorRequest(sin) 23 | assertEquals("1234", newReq.monitorId) 24 | assertEquals("true", newReq.refreshPolicy.value) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/DeleteWorkflowRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.Assert 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.common.io.stream.BytesStreamOutput 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | 8 | class DeleteWorkflowRequestTests { 9 | 10 | @Test 11 | fun `test delete workflow request`() { 12 | val req = DeleteWorkflowRequest("1234", true) 13 | Assert.assertNotNull(req) 14 | Assert.assertEquals("1234", req.workflowId) 15 | 16 | val out = BytesStreamOutput() 17 | req.writeTo(out) 18 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 19 | val newReq = DeleteWorkflowRequest(sin) 20 | Assert.assertEquals("1234", newReq.workflowId) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/DeleteWorkflowResponseTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.Assert 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.common.io.stream.BytesStreamOutput 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | 8 | class DeleteWorkflowResponseTests { 9 | 10 | @Test 11 | fun `test delete workflow response`() { 12 | val res = DeleteWorkflowResponse(id = "w1", version = 1, nonDeletedMonitors = listOf("m1")) 13 | Assert.assertNotNull(res) 14 | Assert.assertEquals("w1", res.id) 15 | 16 | val out = BytesStreamOutput() 17 | res.writeTo(out) 18 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 19 | val newRes = DeleteWorkflowResponse(sin) 20 | Assert.assertEquals("w1", newRes.id) 21 | Assert.assertEquals("m1", newRes.nonDeletedMonitors!!.get(0)) 22 | Assert.assertEquals(1, newRes.version) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Assertions.assertNotNull 5 | import org.junit.jupiter.api.Assertions.assertNull 6 | import org.junit.jupiter.api.Assertions.assertTrue 7 | import org.junit.jupiter.api.Test 8 | import org.opensearch.common.io.stream.BytesStreamOutput 9 | import org.opensearch.commons.alerting.model.Table 10 | import org.opensearch.core.common.io.stream.StreamInput 11 | import org.opensearch.index.query.QueryBuilders 12 | 13 | internal class GetFindingsRequestTests { 14 | 15 | @Test 16 | fun `test get findings request`() { 17 | val table = Table("asc", "sortString", null, 1, 0, "") 18 | val boolQueryBuilder = QueryBuilders.boolQuery() 19 | val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), boolQueryBuilder) 20 | assertNotNull(req) 21 | 22 | val out = BytesStreamOutput() 23 | req.writeTo(out) 24 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 25 | val newReq = GetFindingsRequest(sin) 26 | 27 | assertEquals("1", newReq.monitorId) 28 | assertEquals("2121", newReq.findingId) 29 | assertEquals("finding_index_name", newReq.findingIndex) 30 | assertEquals(table, newReq.table) 31 | assertTrue(newReq.monitorIds!!.contains("1")) 32 | assertTrue(newReq.monitorIds!!.contains("2")) 33 | } 34 | 35 | @Test 36 | fun `test validate returns null`() { 37 | val table = Table("asc", "sortString", null, 1, 0, "") 38 | val boolQueryBuilder = QueryBuilders.boolQuery() 39 | val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), boolQueryBuilder) 40 | assertNotNull(req) 41 | assertNull(req.validate()) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/GetMonitorRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.common.io.stream.BytesStreamOutput 9 | import org.opensearch.core.common.io.stream.StreamInput 10 | import org.opensearch.rest.RestRequest 11 | import org.opensearch.search.fetch.subphase.FetchSourceContext 12 | import org.opensearch.test.OpenSearchTestCase 13 | 14 | class GetMonitorRequestTests : OpenSearchTestCase() { 15 | 16 | fun `test get monitor request`() { 17 | val req = GetMonitorRequest("1234", 1L, RestRequest.Method.GET, FetchSourceContext.FETCH_SOURCE) 18 | assertNotNull(req) 19 | 20 | val out = BytesStreamOutput() 21 | req.writeTo(out) 22 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 23 | val newReq = GetMonitorRequest(sin) 24 | assertEquals("1234", newReq.monitorId) 25 | assertEquals(1L, newReq.version) 26 | assertEquals(RestRequest.Method.GET, newReq.method) 27 | assertEquals(FetchSourceContext.FETCH_SOURCE, newReq.srcContext) 28 | } 29 | 30 | fun `test get monitor request without src context`() { 31 | val req = GetMonitorRequest("1234", 1L, RestRequest.Method.GET, null) 32 | assertNotNull(req) 33 | 34 | val out = BytesStreamOutput() 35 | req.writeTo(out) 36 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 37 | val newReq = GetMonitorRequest(sin) 38 | assertEquals("1234", newReq.monitorId) 39 | assertEquals(1L, newReq.version) 40 | assertEquals(RestRequest.Method.GET, newReq.method) 41 | assertEquals(null, newReq.srcContext) 42 | } 43 | 44 | fun `test head monitor request`() { 45 | val req = GetMonitorRequest("1234", 2L, RestRequest.Method.HEAD, FetchSourceContext.FETCH_SOURCE) 46 | assertNotNull(req) 47 | 48 | val out = BytesStreamOutput() 49 | req.writeTo(out) 50 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 51 | val newReq = GetMonitorRequest(sin) 52 | assertEquals("1234", newReq.monitorId) 53 | assertEquals(2L, newReq.version) 54 | assertEquals(RestRequest.Method.HEAD, newReq.method) 55 | assertEquals(FetchSourceContext.FETCH_SOURCE, newReq.srcContext) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponseTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.common.io.stream.BytesStreamOutput 9 | import org.opensearch.commons.alerting.model.CronSchedule 10 | import org.opensearch.commons.alerting.model.Monitor 11 | import org.opensearch.commons.alerting.randomUser 12 | import org.opensearch.core.common.io.stream.StreamInput 13 | import org.opensearch.test.OpenSearchTestCase 14 | import java.time.Instant 15 | import java.time.ZoneId 16 | 17 | class GetMonitorResponseTests : OpenSearchTestCase() { 18 | 19 | fun `test get monitor response`() { 20 | val req = GetMonitorResponse("1234", 1L, 2L, 0L, null, null) 21 | assertNotNull(req) 22 | 23 | val out = BytesStreamOutput() 24 | req.writeTo(out) 25 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 26 | val newReq = GetMonitorResponse(sin) 27 | assertEquals("1234", newReq.id) 28 | assertEquals(1L, newReq.version) 29 | assertEquals(null, newReq.monitor) 30 | } 31 | 32 | fun `test get monitor response with monitor`() { 33 | val cronExpression = "31 * * * *" // Run at minute 31. 34 | val testInstance = Instant.ofEpochSecond(1538164858L) 35 | 36 | val cronSchedule = CronSchedule(cronExpression, ZoneId.of("Asia/Kolkata"), testInstance) 37 | val monitor = Monitor( 38 | id = "123", 39 | version = 0L, 40 | name = "test-monitor", 41 | enabled = true, 42 | schedule = cronSchedule, 43 | lastUpdateTime = Instant.now(), 44 | enabledTime = Instant.now(), 45 | monitorType = Monitor.MonitorType.QUERY_LEVEL_MONITOR.value, 46 | user = randomUser(), 47 | schemaVersion = 0, 48 | inputs = mutableListOf(), 49 | triggers = mutableListOf(), 50 | uiMetadata = mutableMapOf() 51 | ) 52 | val req = GetMonitorResponse("1234", 1L, 2L, 0L, monitor, null) 53 | assertNotNull(req) 54 | 55 | val out = BytesStreamOutput() 56 | req.writeTo(out) 57 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 58 | val newReq = GetMonitorResponse(sin) 59 | assertEquals("1234", newReq.id) 60 | assertEquals(1L, newReq.version) 61 | assertNotNull(newReq.monitor) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/GetWorkflowRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.common.io.stream.BytesStreamOutput 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | import org.opensearch.rest.RestRequest 8 | 9 | class GetWorkflowRequestTests { 10 | 11 | @Test 12 | fun testGetWorkflowRequest() { 13 | val request = GetWorkflowRequest("w1", RestRequest.Method.GET) 14 | Assertions.assertNull(request.validate()) 15 | 16 | val out = BytesStreamOutput() 17 | request.writeTo(out) 18 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 19 | val newReq = GetWorkflowRequest(sin) 20 | Assertions.assertEquals("w1", newReq.workflowId) 21 | Assertions.assertEquals(RestRequest.Method.GET, newReq.method) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/IndexCommentRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Assertions.assertNotNull 5 | import org.junit.jupiter.api.Test 6 | import org.opensearch.common.io.stream.BytesStreamOutput 7 | import org.opensearch.core.common.io.stream.StreamInput 8 | import org.opensearch.rest.RestRequest 9 | 10 | class IndexCommentRequestTests { 11 | @Test 12 | fun `test index comment post request`() { 13 | val req = IndexCommentRequest("123", "alert", "456", 1L, 2L, RestRequest.Method.POST, "comment") 14 | assertNotNull(req) 15 | val out = BytesStreamOutput() 16 | req.writeTo(out) 17 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 18 | val newReq = IndexCommentRequest(sin) 19 | assertEquals("123", newReq.entityId) 20 | assertEquals("alert", newReq.entityType) 21 | assertEquals("456", newReq.commentId) 22 | assertEquals(1L, newReq.seqNo) 23 | assertEquals(2L, newReq.primaryTerm) 24 | assertEquals(RestRequest.Method.POST, newReq.method) 25 | assertEquals("comment", newReq.content) 26 | } 27 | 28 | @Test 29 | fun `test index comment put request`() { 30 | val req = IndexCommentRequest("123", "alert", "456", 1L, 2L, RestRequest.Method.PUT, "comment") 31 | assertNotNull(req) 32 | val out = BytesStreamOutput() 33 | req.writeTo(out) 34 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 35 | val newReq = IndexCommentRequest(sin) 36 | assertEquals("123", newReq.entityId) 37 | assertEquals("alert", newReq.entityType) 38 | assertEquals("456", newReq.commentId) 39 | assertEquals(1L, newReq.seqNo) 40 | assertEquals(2L, newReq.primaryTerm) 41 | assertEquals(RestRequest.Method.PUT, newReq.method) 42 | assertEquals("comment", newReq.content) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/IndexCommentResponseTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.common.io.stream.BytesStreamOutput 6 | import org.opensearch.commons.alerting.model.Comment 7 | import org.opensearch.commons.alerting.randomUser 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | import java.time.Instant 10 | 11 | class IndexCommentResponseTests { 12 | @Test 13 | fun `test index comment response with comment`() { 14 | val comment = Comment( 15 | "123", 16 | "alert", 17 | "456", 18 | "comment", 19 | Instant.now(), 20 | Instant.now(), 21 | randomUser() 22 | ) 23 | val req = IndexCommentResponse("1234", 1L, 2L, comment) 24 | Assertions.assertNotNull(req) 25 | 26 | val out = BytesStreamOutput() 27 | req.writeTo(out) 28 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 29 | val newReq = IndexCommentResponse(sin) 30 | Assertions.assertEquals("1234", newReq.id) 31 | Assertions.assertEquals(1L, newReq.seqNo) 32 | Assertions.assertEquals(2L, newReq.primaryTerm) 33 | Assertions.assertNotNull(newReq.comment) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/IndexMonitorResponseTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.common.io.stream.BytesStreamOutput 6 | import org.opensearch.commons.alerting.model.CronSchedule 7 | import org.opensearch.commons.alerting.model.Monitor 8 | import org.opensearch.commons.alerting.randomUser 9 | import org.opensearch.core.common.io.stream.StreamInput 10 | import java.time.Instant 11 | import java.time.ZoneId 12 | 13 | class IndexMonitorResponseTests { 14 | 15 | @Test 16 | fun `test index monitor response with monitor`() { 17 | val cronExpression = "31 * * * *" // Run at minute 31. 18 | val testInstance = Instant.ofEpochSecond(1538164858L) 19 | 20 | val cronSchedule = CronSchedule(cronExpression, ZoneId.of("Asia/Kolkata"), testInstance) 21 | val monitor = Monitor( 22 | id = "123", 23 | version = 0L, 24 | name = "test-monitor", 25 | enabled = true, 26 | schedule = cronSchedule, 27 | lastUpdateTime = Instant.now(), 28 | enabledTime = Instant.now(), 29 | monitorType = Monitor.MonitorType.QUERY_LEVEL_MONITOR.value, 30 | user = randomUser(), 31 | schemaVersion = 0, 32 | inputs = mutableListOf(), 33 | triggers = mutableListOf(), 34 | uiMetadata = mutableMapOf() 35 | ) 36 | val req = IndexMonitorResponse("1234", 1L, 2L, 0L, monitor) 37 | Assertions.assertNotNull(req) 38 | 39 | val out = BytesStreamOutput() 40 | req.writeTo(out) 41 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 42 | val newReq = IndexMonitorResponse(sin) 43 | Assertions.assertEquals("1234", newReq.id) 44 | Assertions.assertEquals(1L, newReq.version) 45 | Assertions.assertNotNull(newReq.monitor) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/PublishFindingsRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Assertions.assertNotNull 5 | import org.junit.jupiter.api.Test 6 | import org.opensearch.common.io.stream.BytesStreamOutput 7 | import org.opensearch.commons.alerting.randomFinding 8 | import org.opensearch.core.common.io.stream.StreamInput 9 | 10 | class PublishFindingsRequestTests { 11 | 12 | @Test 13 | fun `test delete monitor request`() { 14 | val finding = randomFinding() 15 | val monitorId = "mid" 16 | val req = PublishFindingsRequest(monitorId, finding) 17 | assertNotNull(req) 18 | assertEquals(monitorId, req.monitorId) 19 | assertEquals(finding, req.finding) 20 | 21 | val out = BytesStreamOutput() 22 | req.writeTo(out) 23 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 24 | val newReq = PublishFindingsRequest(sin) 25 | assertEquals(monitorId, newReq.monitorId) 26 | assertEquals(finding.id, newReq.finding.id) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/SearchCommentRequestTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.action 2 | 3 | import org.opensearch.action.search.SearchRequest 4 | import org.opensearch.common.io.stream.BytesStreamOutput 5 | import org.opensearch.common.unit.TimeValue 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | import org.opensearch.search.builder.SearchSourceBuilder 8 | import org.opensearch.test.OpenSearchTestCase 9 | import org.opensearch.test.rest.OpenSearchRestTestCase 10 | import java.util.concurrent.TimeUnit 11 | 12 | class SearchCommentRequestTests : OpenSearchTestCase() { 13 | fun `test search comments request`() { 14 | val searchSourceBuilder = SearchSourceBuilder().from(0).size(100).timeout(TimeValue(60, TimeUnit.SECONDS)) 15 | val searchRequest = SearchRequest().indices(OpenSearchRestTestCase.randomAlphaOfLength(10)).source(searchSourceBuilder) 16 | val searchCommentRequest = SearchCommentRequest(searchRequest) 17 | assertNotNull(searchCommentRequest) 18 | 19 | val out = BytesStreamOutput() 20 | searchCommentRequest.writeTo(out) 21 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 22 | val newReq = SearchCommentRequest(sin) 23 | 24 | assertNotNull(newReq.searchRequest) 25 | assertEquals(1, newReq.searchRequest.indices().size) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.alerting.action 7 | 8 | import org.opensearch.action.search.SearchRequest 9 | import org.opensearch.common.io.stream.BytesStreamOutput 10 | import org.opensearch.common.unit.TimeValue 11 | import org.opensearch.core.common.io.stream.StreamInput 12 | import org.opensearch.search.builder.SearchSourceBuilder 13 | import org.opensearch.test.OpenSearchTestCase 14 | import org.opensearch.test.rest.OpenSearchRestTestCase 15 | import java.util.concurrent.TimeUnit 16 | 17 | class SearchMonitorRequestTests : OpenSearchTestCase() { 18 | 19 | fun `test search monitors request`() { 20 | val searchSourceBuilder = SearchSourceBuilder().from(0).size(100).timeout(TimeValue(60, TimeUnit.SECONDS)) 21 | val searchRequest = SearchRequest().indices(OpenSearchRestTestCase.randomAlphaOfLength(10)).source(searchSourceBuilder) 22 | val searchMonitorRequest = SearchMonitorRequest(searchRequest) 23 | assertNotNull(searchMonitorRequest) 24 | 25 | val out = BytesStreamOutput() 26 | searchMonitorRequest.writeTo(out) 27 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 28 | val newReq = SearchMonitorRequest(sin) 29 | 30 | assertNotNull(newReq.searchRequest) 31 | assertEquals(1, newReq.searchRequest.indices().size) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/alerts/AlertErrorTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.alerts 2 | 3 | import org.junit.Assert 4 | import org.junit.jupiter.api.Test 5 | import java.time.Instant 6 | 7 | class AlertErrorTests { 8 | 9 | @Test 10 | fun `test alertError obfuscates IP addresses in message`() { 11 | val message = 12 | "AlertingException[[5f32db4e2a4fa94f6778cb895dae7a24][10.212.77.91:9300][indices:admin/create]]; " + 13 | "nested: Exception[org.opensearch.transport.RemoteTransportException: [5f32db4e2a4fa94f6778cb895dae7a24][10.212.77.91:9300]" + 14 | "[indices:admin/create]];; java.lang.Exception: org.opensearch.transport.RemoteTransportException: [5f32db4e2a4fa94f6778cb895" + 15 | "dae7a24][10.212.77.91:9300][indices:admin/create]" 16 | val alertError = AlertError(Instant.now(), message = message) 17 | Assert.assertEquals( 18 | alertError.message, 19 | "AlertingException[[5f32db4e2a4fa94f6778cb895dae7a24][x.x.x.x:9300][indices:admin/create]]; " + 20 | "nested: Exception[org.opensearch.transport.RemoteTransportException: [5f32db4e2a4fa94f6778cb895dae7a24][x.x.x.x:9300]" + 21 | "[indices:admin/create]];; java.lang.Exception: org.opensearch.transport.RemoteTransportException: " + 22 | "[5f32db4e2a4fa94f6778cb895dae7a24][x.x.x.x:9300][indices:admin/create]" 23 | ) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/DataSourcesTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.junit.jupiter.api.Assertions 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.common.io.stream.BytesStreamOutput 6 | import org.opensearch.core.common.io.stream.StreamInput 7 | 8 | class DataSourcesTests { 9 | @Test 10 | fun `Test DataSources construction with no comments indices`() { 11 | val dataSources = DataSources( 12 | ScheduledJob.DOC_LEVEL_QUERIES_INDEX, 13 | ".opensearch-alerting-finding-history-write", 14 | "<.opensearch-alerting-finding-history-{now/d}-1>", 15 | ".opendistro-alerting-alerts", 16 | ".opendistro-alerting-alert-history-write", 17 | "<.opendistro-alerting-alert-history-{now/d}-1>", 18 | mapOf(), 19 | false 20 | ) 21 | Assertions.assertNotNull(dataSources) 22 | 23 | val out = BytesStreamOutput() 24 | dataSources.writeTo(out) 25 | val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) 26 | val newDataSources = DataSources(sin) 27 | Assertions.assertEquals(ScheduledJob.DOC_LEVEL_QUERIES_INDEX, newDataSources.queryIndex) 28 | Assertions.assertEquals(".opensearch-alerting-finding-history-write", newDataSources.findingsIndex) 29 | Assertions.assertEquals("<.opensearch-alerting-finding-history-{now/d}-1>", newDataSources.findingsIndexPattern) 30 | Assertions.assertEquals(".opendistro-alerting-alerts", newDataSources.alertsIndex) 31 | Assertions.assertEquals(".opendistro-alerting-alert-history-write", newDataSources.alertsHistoryIndex) 32 | Assertions.assertEquals("<.opendistro-alerting-alert-history-{now/d}-1>", newDataSources.alertsHistoryIndexPattern) 33 | Assertions.assertEquals(mapOf>(), newDataSources.queryIndexMappingsByType) 34 | Assertions.assertEquals(false, newDataSources.findingsEnabled) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/DocumentLevelTriggerTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.CONDITION_FIELD 5 | import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.LANG_FIELD 6 | import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.SCRIPT_FIELD 7 | import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.SOURCE_FIELD 8 | import org.opensearch.commons.alerting.model.Trigger.Companion.ACTIONS_FIELD 9 | import org.opensearch.commons.alerting.model.Trigger.Companion.ID_FIELD 10 | import org.opensearch.commons.alerting.model.Trigger.Companion.NAME_FIELD 11 | import org.opensearch.commons.alerting.model.Trigger.Companion.SEVERITY_FIELD 12 | import org.opensearch.commons.alerting.randomDocumentLevelTrigger 13 | import kotlin.test.assertEquals 14 | import kotlin.test.assertNotNull 15 | 16 | class DocumentLevelTriggerTests { 17 | 18 | @Test 19 | fun `test DocumentLevelTrigger asTemplateArgs`() { 20 | val trigger = randomDocumentLevelTrigger() 21 | 22 | val templateArgs = trigger.asTemplateArg() 23 | 24 | assertEquals(trigger.id, templateArgs[ID_FIELD], "Template arg field 'id' doesn't match") 25 | assertEquals(trigger.name, templateArgs[NAME_FIELD], "Template arg field 'name' doesn't match") 26 | assertEquals(trigger.severity, templateArgs[SEVERITY_FIELD], "Template arg field 'severity' doesn't match") 27 | val actions = templateArgs[ACTIONS_FIELD] as List<*> 28 | assertEquals( 29 | trigger.actions.size, 30 | actions.size, 31 | "Template arg field 'actions' doesn't match" 32 | ) 33 | val condition = templateArgs[CONDITION_FIELD] as? Map<*, *> 34 | assertNotNull(condition, "Template arg field 'condition' is empty") 35 | val script = condition[SCRIPT_FIELD] as? Map<*, *> 36 | assertNotNull(script, "Template arg field 'condition.script' is empty") 37 | assertEquals( 38 | trigger.condition.idOrCode, 39 | script[SOURCE_FIELD], 40 | "Template arg field 'script.source' doesn't match" 41 | ) 42 | assertEquals( 43 | trigger.condition.lang, 44 | script[LANG_FIELD], 45 | "Template arg field 'script.lang' doesn't match" 46 | ) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/FindingTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.commons.alerting.randomFinding 6 | 7 | internal class FindingTests { 8 | @Test 9 | fun `test finding asTemplateArgs`() { 10 | // GIVEN 11 | val finding = randomFinding() 12 | 13 | // WHEN 14 | val templateArgs = finding.asTemplateArg() 15 | 16 | // THEN 17 | assertEquals(templateArgs[Finding.FINDING_ID_FIELD], finding.id, "Template args 'id' field does not match:") 18 | assertEquals( 19 | templateArgs[Finding.RELATED_DOC_IDS_FIELD], 20 | finding.relatedDocIds, 21 | "Template args 'relatedDocIds' field does not match:" 22 | ) 23 | assertEquals(templateArgs[Finding.MONITOR_ID_FIELD], finding.monitorId, "Template args 'monitorId' field does not match:") 24 | assertEquals( 25 | templateArgs[Finding.MONITOR_NAME_FIELD], 26 | finding.monitorName, 27 | "Template args 'monitorName' field does not match:" 28 | ) 29 | assertEquals( 30 | templateArgs[Finding.QUERIES_FIELD], 31 | finding.docLevelQueries, 32 | "Template args 'queries' field does not match:" 33 | ) 34 | assertEquals( 35 | templateArgs[Finding.TIMESTAMP_FIELD], 36 | finding.timestamp.toEpochMilli(), 37 | "Template args 'timestamp' field does not match:" 38 | ) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/MockScheduledJob.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.opensearch.core.common.io.stream.StreamOutput 4 | import org.opensearch.core.xcontent.ToXContent 5 | import org.opensearch.core.xcontent.XContentBuilder 6 | import java.io.IOException 7 | import java.time.Instant 8 | 9 | class MockScheduledJob( 10 | override val id: String, 11 | override val version: Long, 12 | override val name: String, 13 | override val type: String, 14 | override val enabled: Boolean, 15 | override val schedule: Schedule, 16 | override var lastUpdateTime: Instant, 17 | override val enabledTime: Instant? 18 | ) : ScheduledJob { 19 | override fun fromDocument(id: String, version: Long): ScheduledJob { 20 | TODO("not implemented") 21 | } 22 | 23 | override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder { 24 | TODO("not implemented") 25 | } 26 | 27 | @Throws(IOException::class) 28 | override fun writeTo(out: StreamOutput) { 29 | TODO("not implemented") 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/MonitorsTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.opensearch.commons.alerting.randomQueryLevelMonitor 5 | import org.opensearch.commons.alerting.util.IndexUtils 6 | import kotlin.test.assertEquals 7 | import kotlin.test.assertNotNull 8 | 9 | class MonitorsTests { 10 | 11 | @Test 12 | fun `test monitor asTemplateArgs`() { 13 | val monitor = randomQueryLevelMonitor(enabled = true) 14 | 15 | val templateArgs = monitor.asTemplateArg() 16 | 17 | assertEquals(monitor.id, templateArgs[IndexUtils._ID], "Template arg field 'id' doesn't match") 18 | assertEquals( 19 | monitor.version, 20 | templateArgs[IndexUtils._VERSION], 21 | "Template arg field 'version' doesn't match" 22 | ) 23 | assertEquals(monitor.name, templateArgs[Monitor.NAME_FIELD], "Template arg field 'name' doesn't match") 24 | assertEquals( 25 | monitor.enabled, 26 | templateArgs[Monitor.ENABLED_FIELD], 27 | "Template arg field 'enabled' doesn't match" 28 | ) 29 | assertEquals( 30 | monitor.monitorType.toString(), 31 | templateArgs[Monitor.MONITOR_TYPE_FIELD], 32 | "Template arg field 'monitoryType' doesn't match" 33 | ) 34 | assertEquals( 35 | monitor.enabledTime?.toEpochMilli(), 36 | templateArgs[Monitor.ENABLED_TIME_FIELD], 37 | "Template arg field 'enabledTime' doesn't match" 38 | ) 39 | assertEquals( 40 | monitor.lastUpdateTime.toEpochMilli(), 41 | templateArgs[Monitor.LAST_UPDATE_TIME_FIELD], 42 | "Template arg field 'lastUpdateTime' doesn't match" 43 | ) 44 | assertNotNull(templateArgs[Monitor.SCHEDULE_FIELD], "Template arg field 'schedule' not set") 45 | val inputs = templateArgs[Monitor.INPUTS_FIELD] as? List<*> 46 | assertNotNull(inputs, "Template arg field 'inputs' not set") 47 | assertEquals(1, inputs.size, "Template arg field 'inputs' is not populated") 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/QueryLevelTriggerTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.opensearch.commons.alerting.model.QueryLevelTrigger.Companion.CONDITION_FIELD 5 | import org.opensearch.commons.alerting.model.QueryLevelTrigger.Companion.LANG_FIELD 6 | import org.opensearch.commons.alerting.model.QueryLevelTrigger.Companion.SCRIPT_FIELD 7 | import org.opensearch.commons.alerting.model.QueryLevelTrigger.Companion.SOURCE_FIELD 8 | import org.opensearch.commons.alerting.model.Trigger.Companion.ACTIONS_FIELD 9 | import org.opensearch.commons.alerting.model.Trigger.Companion.ID_FIELD 10 | import org.opensearch.commons.alerting.model.Trigger.Companion.NAME_FIELD 11 | import org.opensearch.commons.alerting.model.Trigger.Companion.SEVERITY_FIELD 12 | import org.opensearch.commons.alerting.randomQueryLevelTrigger 13 | import kotlin.test.assertEquals 14 | import kotlin.test.assertNotNull 15 | 16 | class QueryLevelTriggerTests { 17 | 18 | @Test 19 | fun `test QueryLevelTrigger asTemplateArgs`() { 20 | val trigger = randomQueryLevelTrigger() 21 | 22 | val templateArgs = trigger.asTemplateArg() 23 | 24 | assertEquals(trigger.id, templateArgs[ID_FIELD], "Template arg field 'id' doesn't match") 25 | assertEquals(trigger.name, templateArgs[NAME_FIELD], "Template arg field 'name' doesn't match") 26 | assertEquals(trigger.severity, templateArgs[SEVERITY_FIELD], "Template arg field 'severity' doesn't match") 27 | val actions = templateArgs[ACTIONS_FIELD] as List<*> 28 | assertEquals( 29 | trigger.actions.size, 30 | actions.size, 31 | "Template arg field 'actions' doesn't match" 32 | ) 33 | val condition = templateArgs[CONDITION_FIELD] as? Map<*, *> 34 | assertNotNull(condition, "Template arg field 'condition' is empty") 35 | val script = condition[SCRIPT_FIELD] as? Map<*, *> 36 | assertNotNull(script, "Template arg field 'condition.script' is empty") 37 | assertEquals( 38 | trigger.condition.idOrCode, 39 | script[SOURCE_FIELD], 40 | "Template arg field 'script.source' doesn't match" 41 | ) 42 | assertEquals( 43 | trigger.condition.lang, 44 | script[LANG_FIELD], 45 | "Template arg field 'script.lang' doesn't match" 46 | ) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/SearchInputTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.opensearch.commons.alerting.model.SearchInput.Companion.INDICES_FIELD 5 | import org.opensearch.commons.alerting.model.SearchInput.Companion.QUERY_FIELD 6 | import org.opensearch.commons.alerting.model.SearchInput.Companion.SEARCH_FIELD 7 | import org.opensearch.commons.alerting.randomSearchInput 8 | import kotlin.test.assertEquals 9 | import kotlin.test.assertNotNull 10 | 11 | class SearchInputTests { 12 | 13 | @Test 14 | fun `test SearchInput asTemplateArgs`() { 15 | val searchInput = randomSearchInput() 16 | 17 | val templateArgs = searchInput.asTemplateArg() 18 | 19 | val search = templateArgs[SEARCH_FIELD] as? Map<*, *> 20 | assertNotNull(search, "Template arg field 'search' is empty") 21 | assertEquals( 22 | searchInput.indices, 23 | search[INDICES_FIELD], 24 | "Template arg field 'indices' doesn't match" 25 | ) 26 | assertEquals( 27 | searchInput.query.toString(), 28 | search[QUERY_FIELD], 29 | "Template arg field 'query' doesn't match" 30 | ) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/XContentTestBase.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model 2 | 3 | import org.opensearch.common.settings.Settings 4 | import org.opensearch.common.xcontent.LoggingDeprecationHandler 5 | import org.opensearch.common.xcontent.XContentType 6 | import org.opensearch.core.xcontent.NamedXContentRegistry 7 | import org.opensearch.core.xcontent.XContentBuilder 8 | import org.opensearch.core.xcontent.XContentParser 9 | import org.opensearch.search.SearchModule 10 | 11 | interface XContentTestBase { 12 | fun builder(): XContentBuilder { 13 | return XContentBuilder.builder(XContentType.JSON.xContent()) 14 | } 15 | 16 | fun parser(xc: String): XContentParser { 17 | val parser = XContentType.JSON.xContent().createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, xc) 18 | parser.nextToken() 19 | return parser 20 | } 21 | 22 | fun xContentRegistry(): NamedXContentRegistry { 23 | return NamedXContentRegistry( 24 | listOf(SearchInput.XCONTENT_REGISTRY) + SearchModule(Settings.EMPTY, emptyList()).namedXContents 25 | ) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/alerting/model/action/ActionTests.kt: -------------------------------------------------------------------------------- 1 | package org.opensearch.commons.alerting.model.action 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Test 5 | import org.opensearch.commons.alerting.model.action.Action.Companion.DESTINATION_ID_FIELD 6 | import org.opensearch.commons.alerting.model.action.Action.Companion.ID_FIELD 7 | import org.opensearch.commons.alerting.model.action.Action.Companion.NAME_FIELD 8 | import org.opensearch.commons.alerting.model.action.Action.Companion.THROTTLE_ENABLED_FIELD 9 | import org.opensearch.commons.alerting.randomAction 10 | 11 | class ActionTests { 12 | 13 | @Test 14 | fun `test action asTemplateArgs`() { 15 | val action = randomAction() 16 | 17 | val templateArgs = action.asTemplateArg() 18 | 19 | assertEquals( 20 | action.id, 21 | templateArgs[ID_FIELD], 22 | "Template arg field 'id' doesn't match" 23 | ) 24 | assertEquals( 25 | action.name, 26 | templateArgs[NAME_FIELD], 27 | "Template arg field 'name' doesn't match" 28 | ) 29 | assertEquals( 30 | action.destinationId, 31 | templateArgs[DESTINATION_ID_FIELD], 32 | "Template arg field 'destinationId' doesn't match" 33 | ) 34 | assertEquals( 35 | action.throttleEnabled, 36 | templateArgs[THROTTLE_ENABLED_FIELD], 37 | "Template arg field 'throttleEnabled' doesn't match" 38 | ) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/action/GetChannelListRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.action 6 | 7 | import com.fasterxml.jackson.core.JsonParseException 8 | import org.junit.jupiter.api.Assertions.assertEquals 9 | import org.junit.jupiter.api.Test 10 | import org.junit.jupiter.api.assertThrows 11 | import org.opensearch.commons.utils.createObjectFromJsonString 12 | import org.opensearch.commons.utils.getJsonString 13 | import org.opensearch.commons.utils.recreateObject 14 | 15 | internal class GetChannelListRequestTests { 16 | 17 | private fun assertGetRequestEquals( 18 | expected: GetChannelListRequest, 19 | actual: GetChannelListRequest 20 | ) { 21 | assertEquals(expected.compact, actual.compact) 22 | } 23 | 24 | @Test 25 | fun `Get request serialize and deserialize transport object should be equal`() { 26 | val configRequest = GetChannelListRequest() 27 | val recreatedObject = recreateObject(configRequest) { GetChannelListRequest(it) } 28 | assertGetRequestEquals(configRequest, recreatedObject) 29 | } 30 | 31 | @Test 32 | fun `Get request serialize and deserialize using json object should be equal`() { 33 | val configRequest = GetChannelListRequest() 34 | val jsonString = getJsonString(configRequest) 35 | val recreatedObject = createObjectFromJsonString(jsonString) { GetChannelListRequest.parse(it) } 36 | assertGetRequestEquals(configRequest, recreatedObject) 37 | } 38 | 39 | @Test 40 | fun `Get request should throw exception when invalid json object is passed`() { 41 | val jsonString = "sample message" 42 | assertThrows { 43 | createObjectFromJsonString(jsonString) { GetChannelListRequest.parse(it) } 44 | } 45 | } 46 | 47 | @Test 48 | fun `Get request should safely ignore extra field in json object`() { 49 | val configRequest = GetChannelListRequest() 50 | val jsonString = """ 51 | { 52 | "extra_field_1":["extra", "value"], 53 | "extra_field_2":{"extra":"value"}, 54 | "extra_field_3":"extra value 3" 55 | } 56 | """.trimIndent() 57 | val recreatedObject = createObjectFromJsonString(jsonString) { GetChannelListRequest.parse(it) } 58 | assertGetRequestEquals(configRequest, recreatedObject) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/action/GetPluginFeaturesRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.action 6 | 7 | import com.fasterxml.jackson.core.JsonParseException 8 | import org.junit.jupiter.api.Assertions.assertEquals 9 | import org.junit.jupiter.api.Test 10 | import org.junit.jupiter.api.assertThrows 11 | import org.opensearch.commons.utils.createObjectFromJsonString 12 | import org.opensearch.commons.utils.getJsonString 13 | import org.opensearch.commons.utils.recreateObject 14 | 15 | internal class GetPluginFeaturesRequestTests { 16 | 17 | private fun assertGetRequestEquals( 18 | expected: GetPluginFeaturesRequest, 19 | actual: GetPluginFeaturesRequest 20 | ) { 21 | assertEquals(expected.compact, actual.compact) 22 | } 23 | 24 | @Test 25 | fun `Get request serialize and deserialize transport object should be equal`() { 26 | val request = GetPluginFeaturesRequest() 27 | val recreatedObject = recreateObject(request) { GetPluginFeaturesRequest(it) } 28 | assertGetRequestEquals(request, recreatedObject) 29 | } 30 | 31 | @Test 32 | fun `Get request serialize and deserialize using json object should be equal`() { 33 | val request = GetPluginFeaturesRequest() 34 | val jsonString = getJsonString(request) 35 | val recreatedObject = createObjectFromJsonString(jsonString) { GetPluginFeaturesRequest.parse(it) } 36 | assertGetRequestEquals(request, recreatedObject) 37 | } 38 | 39 | @Test 40 | fun `Get request should throw exception when invalid json object is passed`() { 41 | val jsonString = "sample message" 42 | assertThrows { 43 | createObjectFromJsonString(jsonString) { GetPluginFeaturesRequest.parse(it) } 44 | } 45 | } 46 | 47 | @Test 48 | fun `Get request should safely ignore extra field in json object`() { 49 | val request = GetPluginFeaturesRequest() 50 | val jsonString = """ 51 | { 52 | "extra_field_1":["extra", "value"], 53 | "extra_field_2":{"extra":"value"}, 54 | "extra_field_3":"extra value 3" 55 | } 56 | """.trimIndent() 57 | val recreatedObject = createObjectFromJsonString(jsonString) { GetPluginFeaturesRequest.parse(it) } 58 | assertGetRequestEquals(request, recreatedObject) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/action/LegacyPublishNotificationRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.action 7 | 8 | import org.junit.jupiter.api.Assertions.assertEquals 9 | import org.junit.jupiter.api.Assertions.assertNull 10 | import org.junit.jupiter.api.Test 11 | import org.opensearch.commons.destination.message.LegacyChimeMessage 12 | import org.opensearch.commons.utils.recreateObject 13 | 14 | internal class LegacyPublishNotificationRequestTests { 15 | 16 | private fun assertRequestEquals( 17 | expected: LegacyPublishNotificationRequest, 18 | actual: LegacyPublishNotificationRequest 19 | ) { 20 | assertEquals(expected.baseMessage.channelName, actual.baseMessage.channelName) 21 | assertEquals(expected.baseMessage.channelType, actual.baseMessage.channelType) 22 | assertEquals(expected.baseMessage.messageContent, actual.baseMessage.messageContent) 23 | assertEquals(expected.baseMessage.url, actual.baseMessage.url) 24 | assertNull(actual.validate()) 25 | } 26 | 27 | @Test 28 | fun `publish request serialize and deserialize transport object should be equal`() { 29 | val baseMessage = LegacyChimeMessage.Builder("chime_message").withMessage("Hello world").withUrl("https://amazon.com").build() 30 | val request = LegacyPublishNotificationRequest(baseMessage) 31 | val recreatedObject = recreateObject(request) { LegacyPublishNotificationRequest(it) } 32 | assertRequestEquals(request, recreatedObject) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/action/LegacyPublishNotificationResponseTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.action 7 | 8 | import org.junit.jupiter.api.Assertions.assertEquals 9 | import org.junit.jupiter.api.Test 10 | import org.opensearch.commons.destination.response.LegacyDestinationResponse 11 | import org.opensearch.commons.utils.recreateObject 12 | 13 | internal class LegacyPublishNotificationResponseTests { 14 | 15 | @Test 16 | fun `Create response serialize and deserialize transport object should be equal`() { 17 | val res = LegacyDestinationResponse.Builder().withStatusCode(200).withResponseContent("Hello world").build() 18 | val configResponse = LegacyPublishNotificationResponse(res) 19 | val recreatedObject = recreateObject(configResponse) { LegacyPublishNotificationResponse(it) } 20 | assertEquals(configResponse.destinationResponse.statusCode, recreatedObject.destinationResponse.statusCode) 21 | assertEquals(configResponse.destinationResponse.responseContent, recreatedObject.destinationResponse.responseContent) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/model/ConfigTypeTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.model 6 | 7 | import org.junit.jupiter.api.Assertions.assertEquals 8 | import org.junit.jupiter.api.Test 9 | import org.opensearch.commons.notifications.model.ConfigType.Companion.enumParser 10 | import org.opensearch.commons.notifications.model.ConfigType.Companion.fromTagOrDefault 11 | 12 | internal class ConfigTypeTests { 13 | 14 | @Test 15 | fun `toString should return tag`() { 16 | ConfigType.values().forEach { 17 | assertEquals(it.tag, it.toString()) 18 | } 19 | } 20 | 21 | @Test 22 | fun `fromTagOrDefault should return corresponding enum`() { 23 | ConfigType.values().forEach { 24 | assertEquals(it, fromTagOrDefault(it.tag)) 25 | } 26 | } 27 | 28 | @Test 29 | fun `EnumParser fromTagOrDefault should return corresponding enum`() { 30 | ConfigType.values().forEach { 31 | assertEquals(it, enumParser.fromTagOrDefault(it.tag)) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/model/DeliveryStatusTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.notifications.model 7 | 8 | import com.fasterxml.jackson.core.JsonParseException 9 | import org.junit.jupiter.api.Assertions.assertEquals 10 | import org.junit.jupiter.api.Test 11 | import org.junit.jupiter.api.assertThrows 12 | import org.opensearch.commons.utils.createObjectFromJsonString 13 | import org.opensearch.commons.utils.getJsonString 14 | import org.opensearch.commons.utils.recreateObject 15 | 16 | internal class DeliveryStatusTests { 17 | @Test 18 | fun `DeliveryStatus serialize and deserialize should be equal`() { 19 | val sampleDeliveryStatus = DeliveryStatus( 20 | "404", 21 | "invalid recipient" 22 | ) 23 | val recreatedObject = recreateObject(sampleDeliveryStatus) { DeliveryStatus(it) } 24 | assertEquals(sampleDeliveryStatus, recreatedObject) 25 | } 26 | 27 | @Test 28 | fun `DeliveryStatus serialize and deserialize using json should be equal`() { 29 | val sampleDeliveryStatus = DeliveryStatus( 30 | "404", 31 | "invalid recipient" 32 | ) 33 | val jsonString = getJsonString(sampleDeliveryStatus) 34 | val recreatedObject = createObjectFromJsonString(jsonString) { DeliveryStatus.parse(it) } 35 | assertEquals(sampleDeliveryStatus, recreatedObject) 36 | } 37 | 38 | @Test 39 | fun `DeliveryStatus should throw exception when invalid json object is passed`() { 40 | val jsonString = "sample message" 41 | assertThrows { 42 | createObjectFromJsonString(jsonString) { DeliveryStatus.parse(it) } 43 | } 44 | } 45 | 46 | @Test 47 | fun `DeliveryStatus should safely ignore extra field in json object`() { 48 | val sampleDeliveryStatus = DeliveryStatus( 49 | "404", 50 | "invalid recipient" 51 | ) 52 | val jsonString = """ 53 | { 54 | "status_code": "404", 55 | "status_text": "invalid recipient", 56 | "extra": "field" 57 | } 58 | """.trimIndent() 59 | val recreatedObject = createObjectFromJsonString(jsonString) { DeliveryStatus.parse(it) } 60 | assertEquals(sampleDeliveryStatus, recreatedObject) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/model/MethodTypeTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.model 6 | 7 | import org.junit.jupiter.api.Assertions.assertEquals 8 | import org.junit.jupiter.api.Test 9 | import org.opensearch.commons.notifications.model.MethodType.Companion.enumParser 10 | import org.opensearch.commons.notifications.model.MethodType.Companion.fromTagOrDefault 11 | 12 | internal class MethodTypeTests { 13 | 14 | @Test 15 | fun `toString should return tag`() { 16 | MethodType.values().forEach { 17 | assertEquals(it.tag, it.toString()) 18 | } 19 | } 20 | 21 | @Test 22 | fun `fromTagOrDefault should return corresponding enum`() { 23 | MethodType.values().forEach { 24 | assertEquals(it, fromTagOrDefault(it.tag)) 25 | } 26 | } 27 | 28 | @Test 29 | fun `EnumParser fromTagOrDefault should return corresponding enum`() { 30 | MethodType.values().forEach { 31 | assertEquals(it, enumParser.fromTagOrDefault(it.tag)) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/notifications/model/SeverityTypeTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.notifications.model 6 | 7 | import org.junit.jupiter.api.Assertions.assertEquals 8 | import org.junit.jupiter.api.Test 9 | import org.opensearch.commons.notifications.model.SeverityType.Companion.enumParser 10 | import org.opensearch.commons.notifications.model.SeverityType.Companion.fromTagOrDefault 11 | 12 | internal class SeverityTypeTests { 13 | 14 | @Test 15 | fun `toString should return tag`() { 16 | SeverityType.values().forEach { 17 | assertEquals(it.tag, it.toString()) 18 | } 19 | } 20 | 21 | @Test 22 | fun `fromTagOrDefault should return corresponding enum`() { 23 | SeverityType.values().forEach { 24 | assertEquals(it, fromTagOrDefault(it.tag)) 25 | } 26 | } 27 | 28 | @Test 29 | fun `EnumParser fromTagOrDefault should return corresponding enum`() { 30 | SeverityType.values().forEach { 31 | assertEquals(it, enumParser.fromTagOrDefault(it.tag)) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/replication/action/StopIndexReplicationRequestTests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | package org.opensearch.commons.replication.action 6 | 7 | import org.junit.jupiter.api.Assertions.assertEquals 8 | import org.junit.jupiter.api.Assertions.assertNotNull 9 | import org.junit.jupiter.api.Assertions.assertNull 10 | import org.junit.jupiter.api.Test 11 | import org.opensearch.commons.utils.recreateObject 12 | 13 | internal class StopIndexReplicationRequestTests { 14 | @Test 15 | fun `Stop Replication request serialize and deserialize transport object should be equal`() { 16 | val index = "test-idx" 17 | val request = StopIndexReplicationRequest(index) 18 | val recreatedRequest = recreateObject(request) { StopIndexReplicationRequest(it) } 19 | assertNotNull(recreatedRequest) 20 | assertEquals(request.indexName, recreatedRequest.indexName) 21 | assertNull(recreatedRequest.validate()) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/kotlin/org/opensearch/commons/utils/TestHelpers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright OpenSearch Contributors 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.opensearch.commons.utils 7 | 8 | import org.opensearch.common.xcontent.XContentFactory 9 | import org.opensearch.common.xcontent.XContentType 10 | import org.opensearch.core.xcontent.DeprecationHandler 11 | import org.opensearch.core.xcontent.NamedXContentRegistry 12 | import org.opensearch.core.xcontent.ToXContent 13 | import org.opensearch.core.xcontent.XContentParser 14 | import java.io.ByteArrayOutputStream 15 | 16 | fun getJsonString(xContent: ToXContent): String { 17 | ByteArrayOutputStream().use { byteArrayOutputStream -> 18 | val builder = XContentFactory.jsonBuilder(byteArrayOutputStream) 19 | xContent.toXContent(builder, ToXContent.EMPTY_PARAMS) 20 | builder.close() 21 | return byteArrayOutputStream.toString("UTF8") 22 | } 23 | } 24 | 25 | inline fun createObjectFromJsonString( 26 | jsonString: String, 27 | block: (XContentParser) -> CreateType 28 | ): CreateType { 29 | val parser = XContentType.JSON.xContent() 30 | .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.IGNORE_DEPRECATIONS, jsonString) 31 | parser.nextToken() 32 | return block(parser) 33 | } 34 | -------------------------------------------------------------------------------- /src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker: -------------------------------------------------------------------------------- 1 | mock-maker-inline -------------------------------------------------------------------------------- /src/test/resources/sample.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEPDCCAySgAwIBAgIUaYSlET3nzsotWTrWueVPPh10yLYwDQYJKoZIhvcNAQEL 3 | BQAwgY8xEzARBgoJkiaJk/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFt 4 | cGxlMRkwFwYDVQQKDBBFeGFtcGxlIENvbSBJbmMuMSEwHwYDVQQLDBhFeGFtcGxl 5 | IENvbSBJbmMuIFJvb3QgQ0ExITAfBgNVBAMMGEV4YW1wbGUgQ29tIEluYy4gUm9v 6 | dCBDQTAeFw0yNDAyMjAxNzAzMjVaFw0zNDAyMTcxNzAzMjVaMFcxCzAJBgNVBAYT 7 | AmRlMQ0wCwYDVQQHDAR0ZXN0MQ0wCwYDVQQKDARub2RlMQ0wCwYDVQQLDARub2Rl 8 | MRswGQYDVQQDDBJub2RlLTAuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUA 9 | A4IBDwAwggEKAoIBAQCm93kXteDQHMAvbUPNPW5pyRHKDD42XGWSgq0k1D29C/Ud 10 | yL21HLzTJa49ZU2ldIkSKs9JqbkHdyK0o8MO6L8dotLoYbxDWbJFW8bp1w6tDTU0 11 | HGkn47XVu3EwbfrTENg3jFu+Oem6a/501SzITzJWtS0cn2dIFOBimTVpT/4Zv5qr 12 | XA6Cp4biOmoTYWhi/qQl8d0IaADiqoZ1MvZbZ6x76qTrRAbg+UWkpTEXoH1xTc8n 13 | dibR7+HP6OTqCKvo1NhE8uP4pY+fWd6b6l+KLo3IKpfTbAIJXIO+M67FLtWKtttD 14 | ao94B069skzKk6FPgW/OZh6PRCD0oxOavV+ld2SjAgMBAAGjgcYwgcMwRwYDVR0R 15 | BEAwPogFKgMEBQWCEm5vZGUtMC5leGFtcGxlLmNvbYIJbG9jYWxob3N0hxAAAAAA 16 | AAAAAAAAAAAAAAABhwR/AAABMAsGA1UdDwQEAwIF4DAdBgNVHSUEFjAUBggrBgEF 17 | BQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQU0/qDQaY10jIo 18 | wCjLUpz/HfQXyt8wHwYDVR0jBBgwFoAUF4ffoFrrZhKn1dD4uhJFPLcrAJwwDQYJ 19 | KoZIhvcNAQELBQADggEBAGbij5WyF0dKhQodQfTiFDb73ygU6IyeJkFSnxF67gDz 20 | pQJZKFvXuVBa3cGP5e7Qp3TK50N+blXGH0xXeIV9lXeYUk4hVfBlp9LclZGX8tGi 21 | 7Xa2enMvIt5q/Yg3Hh755ZxnDYxCoGkNOXUmnMusKstE0YzvZ5Gv6fcRKFBUgZLh 22 | hUBqIEAYly1EqH/y45APiRt3Nor1yF6zEI4TnL0yNrHw6LyQkUNCHIGMJLfnJQ9L 23 | camMGIXOx60kXNMTigF9oXXwixWAnDM9y3QT8QXA7hej/4zkbO+vIeV/7lGUdkyg 24 | PAi92EvyxmsliEMyMR0VINl8emyobvfwa7oMeWMR+hg= 25 | -----END CERTIFICATE----- 26 | -------------------------------------------------------------------------------- /src/test/resources/test-kirk.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opensearch-project/common-utils/3e28c9218fb1229a49194a5850902b85697d770f/src/test/resources/test-kirk.jks --------------------------------------------------------------------------------