grafana / cog

Code Generation with a human touch
Apache License 2.0
48 stars 2 forks source link

Java: Fix release templates #510

Closed spinillos closed 4 months ago

spinillos commented 4 months ago

Missing actions/checkout@v4 step and gradle build should be a different step.

github-actions[bot] commented 4 months ago

Note: in addition to the changes introduced by this PR, the diff includes unreleased changes living in main.

### 🔎 Changes to `grafana-foundation-sdk@next+cog-v0.0.x` ```patch diff --git a/.github/workflows/java-ci.yaml b/.github/workflows/java-ci.yaml new file mode 100644 index 0000000..3d0a3fc --- /dev/null +++ b/.github/workflows/java-ci.yaml @@ -0,0 +1,36 @@ +# Code generated - EDITING IS FUTILE. DO NOT EDIT. + +name: Java CI +on: + pull_request: ~ + +env: + JAVA_VERSION: '17' + +jobs: + java: + name: Java + runs-on: ubuntu-latest + + defaults: + run: + shell: bash + working-directory: ./java + + steps: + - uses: actions/checkout@v4 + + - name: Use Java SDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'temurin' + check-latest: true + + - name: Java setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: '8.8' + + - name: Java build + run: gradle build diff --git a/.github/workflows/java-release.yaml b/.github/workflows/java-release.yaml new file mode 100644 index 0000000..766ded7 --- /dev/null +++ b/.github/workflows/java-release.yaml @@ -0,0 +1,51 @@ +# Code generated - EDITING IS FUTILE. DO NOT EDIT. + +name: Java Release +on: + pull_request_target: + types: [ closed ] + paths: + - 'java/src/**' + +env: + JAVA_VERSION: '17' + +jobs: + release: + if: github.event.pull_request.merged == true && github.base_ref == 'next+cog-v0.0.x' + + name: Build and release + runs-on: ubuntu-latest + + permissions: + contents: read + + defaults: + run: + shell: bash + working-directory: ./java + + steps: + - uses: actions/checkout@v4 + + - name: Uses Java SDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'temurin' + check-latest: true + + - name: Java setup gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: '8.8' + + - name: Publish package 📦 + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + run: + gradle publishToSonatype closeAndReleaseSonatypeStagingRepository + diff --git a/go/canvas/types_gen.go b/go/canvas/types_gen.go index ebfb670..eff09b3 100644 --- a/go/canvas/types_gen.go +++ b/go/canvas/types_gen.go @@ -101,12 +101,13 @@ type CanvasElementOptions struct { Name string `json:"name"` Type string `json:"type"` // TODO: figure out how to define this (element config(s)) - Config any `json:"config,omitempty"` - Constraint *Constraint `json:"constraint,omitempty"` - Placement *Placement `json:"placement,omitempty"` - Background *BackgroundConfig `json:"background,omitempty"` - Border *LineConfig `json:"border,omitempty"` - Connections []CanvasConnection `json:"connections,omitempty"` + Config any `json:"config,omitempty"` + Constraint *Constraint `json:"constraint,omitempty"` + Placement *Placement `json:"placement,omitempty"` + Background *BackgroundConfig `json:"background,omitempty"` + Border *LineConfig `json:"border,omitempty"` + Connections []CanvasConnection `json:"connections,omitempty"` + OneClickLinks *bool `json:"oneClickLinks,omitempty"` } type Options struct { diff --git a/go/cloudwatch/cloudwatchmetricsquery_builder_gen.go b/go/cloudwatch/cloudwatchmetricsquery_builder_gen.go index f31b854..6d679fb 100644 --- a/go/cloudwatch/cloudwatchmetricsquery_builder_gen.go +++ b/go/cloudwatch/cloudwatchmetricsquery_builder_gen.go @@ -48,7 +48,7 @@ func (builder *CloudWatchMetricsQueryBuilder) QueryMode(queryMode CloudWatchQuer return builder } -// Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console. +// Whether to use a metric search or metric insights query func (builder *CloudWatchMetricsQueryBuilder) MetricQueryType(metricQueryType MetricQueryType) *CloudWatchMetricsQueryBuilder { builder.internal.MetricQueryType = &metricQueryType @@ -91,7 +91,7 @@ func (builder *CloudWatchMetricsQueryBuilder) Expression(expression string) *Clo return builder } -// When the metric query type is `metricQueryType` is set to `Query`, this field is used to specify the query string. +// When the metric query type is set to `Insights`, this field is used to specify the query string. func (builder *CloudWatchMetricsQueryBuilder) SqlExpression(sqlExpression string) *CloudWatchMetricsQueryBuilder { builder.internal.SqlExpression = &sqlExpression @@ -178,7 +178,7 @@ func (builder *CloudWatchMetricsQueryBuilder) Statistic(statistic string) *Cloud return builder } -// When the metric query type is `metricQueryType` is set to `Query` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query. +// When the metric query type is set to `Insights` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query. func (builder *CloudWatchMetricsQueryBuilder) Sql(sql cog.Builder[SQLExpression]) *CloudWatchMetricsQueryBuilder { sqlResource, err := sql.Build() if err != nil { diff --git a/go/cloudwatch/types_gen.go b/go/cloudwatch/types_gen.go index 6f32fe2..9fdb9ad 100644 --- a/go/cloudwatch/types_gen.go +++ b/go/cloudwatch/types_gen.go @@ -38,7 +38,7 @@ type Dimensions map[string]StringOrArrayOfString type CloudWatchMetricsQuery struct { // Whether a query is a Metrics, Logs, or Annotations query QueryMode CloudWatchQueryMode `json:"queryMode"` - // Whether to use a metric search or metric query. Metric query is referred to as "Metrics Insights" in the AWS console. + // Whether to use a metric search or metric insights query MetricQueryType *MetricQueryType `json:"metricQueryType,omitempty"` // Whether to use the query builder or code editor to create the query MetricEditorMode *MetricEditorMode `json:"metricEditorMode,omitempty"` @@ -51,7 +51,7 @@ type CloudWatchMetricsQuery struct { Label *string `json:"label,omitempty"` // Math expression query Expression *string `json:"expression,omitempty"` - // When the metric query type is `metricQueryType` is set to `Query`, this field is used to specify the query string. + // When the metric query type is set to `Insights`, this field is used to specify the query string. SqlExpression *string `json:"sqlExpression,omitempty"` // A unique identifier for the query within the list of targets. // In server side expressions, the refId is used as a variable name to identify results. @@ -78,7 +78,7 @@ type CloudWatchMetricsQuery struct { AccountId *string `json:"accountId,omitempty"` // Metric data aggregations over specified periods of time. For detailed definitions of the statistics supported by CloudWatch, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Statistics-definitions.html. Statistic *string `json:"statistic,omitempty"` - // When the metric query type is `metricQueryType` is set to `Query` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query. + // When the metric query type is set to `Insights` and the `metricEditorMode` is set to `Builder`, this field is used to build up an object representation of a SQL query. Sql *SQLExpression `json:"sql,omitempty"` // For mixed data sources the selected datasource is on the query level. // For non mixed scenarios this is undefined. @@ -102,8 +102,8 @@ const ( type MetricQueryType int64 const ( - MetricQueryTypeSearch MetricQueryType = 0 - MetricQueryTypeQuery MetricQueryType = 1 + MetricQueryTypeSearch MetricQueryType = 0 + MetricQueryTypeInsights MetricQueryType = 1 ) type MetricEditorMode int64 diff --git a/go/common/datasourceref_builder_gen.go b/go/common/datasourceref_builder_gen.go index 17c5e45..fdf3f97 100644 --- a/go/common/datasourceref_builder_gen.go +++ b/go/common/datasourceref_builder_gen.go @@ -53,5 +53,12 @@ func (builder *DataSourceRefBuilder) Uid(uid string) *DataSourceRefBuilder { return builder } +// Datasource API version +func (builder *DataSourceRefBuilder) ApiVersion(apiVersion string) *DataSourceRefBuilder { + builder.internal.ApiVersion = &apiVersion + + return builder +} + func (builder *DataSourceRefBuilder) applyDefaults() { } diff --git a/go/common/tableimagecelloptions_builder_gen.go b/go/common/tableimagecelloptions_builder_gen.go new file mode 100644 index 0000000..2bfe851 --- /dev/null +++ b/go/common/tableimagecelloptions_builder_gen.go @@ -0,0 +1,57 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package common + +import ( + cog "github.com/grafana/grafana-foundation-sdk/go/cog" +) + +var _ cog.Builder[TableImageCellOptions] = (*TableImageCellOptionsBuilder)(nil) + +// Json view cell options +type TableImageCellOptionsBuilder struct { + internal *TableImageCellOptions + errors map[string]cog.BuildErrors +} + +func NewTableImageCellOptionsBuilder() *TableImageCellOptionsBuilder { + resource := &TableImageCellOptions{} + builder := &TableImageCellOptionsBuilder{ + internal: resource, + errors: make(map[string]cog.BuildErrors), + } + + builder.applyDefaults() + builder.internal.Type = "image" + + return builder +} + +func (builder *TableImageCellOptionsBuilder) Build() (TableImageCellOptions, error) { + var errs cog.BuildErrors + + for _, err := range builder.errors { + errs = append(errs, cog.MakeBuildErrors("TableImageCellOptions", err)...) + } + + if len(errs) != 0 { + return TableImageCellOptions{}, errs + } + + return *builder.internal, nil +} + +func (builder *TableImageCellOptionsBuilder) Alt(alt string) *TableImageCellOptionsBuilder { + builder.internal.Alt = &alt + + return builder +} + +func (builder *TableImageCellOptionsBuilder) Title(title string) *TableImageCellOptionsBuilder { + builder.internal.Title = &title + + return builder +} + +func (builder *TableImageCellOptionsBuilder) applyDefaults() { +} diff --git a/go/common/types_gen.go b/go/common/types_gen.go index 2a884e4..c089dee 100644 --- a/go/common/types_gen.go +++ b/go/common/types_gen.go @@ -714,7 +714,9 @@ type TableJsonViewCellOptions struct { // Json view cell options type TableImageCellOptions struct { - Type string `json:"type"` + Type string `json:"type"` + Alt *string `json:"alt,omitempty"` + Title *string `json:"title,omitempty"` } // Show data links in the cell @@ -827,6 +829,8 @@ type DataSourceRef struct { Type *string `json:"type,omitempty"` // Specific datasource instance Uid *string `json:"uid,omitempty"` + // Datasource API version + ApiVersion *string `json:"apiVersion,omitempty"` } // Links to a resource (image/svg path) diff --git a/go/dashboard/dashboard_builder_gen.go b/go/dashboard/dashboard_builder_gen.go index 284a7ae..b8a326e 100644 --- a/go/dashboard/dashboard_builder_gen.go +++ b/go/dashboard/dashboard_builder_gen.go @@ -381,6 +381,13 @@ func (builder *DashboardBuilder) Snapshot(snapshot cog.Builder[Snapshot]) *Dashb return builder } +// When set to true, the dashboard will load all panels in the dashboard when it's loaded. +func (builder *DashboardBuilder) Preload(preload bool) *DashboardBuilder { + builder.internal.Preload = &preload + + return builder +} + func (builder *DashboardBuilder) applyDefaults() { builder.Timezone("browser") builder.Tooltip(0) diff --git a/go/dashboard/types_gen.go b/go/dashboard/types_gen.go index 74ce0d0..a8f9657 100644 --- a/go/dashboard/types_gen.go +++ b/go/dashboard/types_gen.go @@ -75,6 +75,8 @@ type Dashboard struct { Links []DashboardLink `json:"links,omitempty"` // Snapshot options. They are present only if the dashboard is a snapshot. Snapshot *Snapshot `json:"snapshot,omitempty"` + // When set to true, the dashboard will load all panels in the dashboard when it's loaded. + Preload *bool `json:"preload,omitempty"` } // TODO: this should be a regular DataQuery that depends on the selected dashboard diff --git a/go/preferences/navbarpreference_builder_gen.go b/go/preferences/navbarpreference_builder_gen.go new file mode 100644 index 0000000..e3c6c3d --- /dev/null +++ b/go/preferences/navbarpreference_builder_gen.go @@ -0,0 +1,49 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package preferences + +import ( + cog "github.com/grafana/grafana-foundation-sdk/go/cog" +) + +var _ cog.Builder[NavbarPreference] = (*NavbarPreferenceBuilder)(nil) + +type NavbarPreferenceBuilder struct { + internal *NavbarPreference + errors map[string]cog.BuildErrors +} + +func NewNavbarPreferenceBuilder() *NavbarPreferenceBuilder { + resource := &NavbarPreference{} + builder := &NavbarPreferenceBuilder{ + internal: resource, + errors: make(map[string]cog.BuildErrors), + } + + builder.applyDefaults() + + return builder +} + +func (builder *NavbarPreferenceBuilder) Build() (NavbarPreference, error) { + var errs cog.BuildErrors + + for _, err := range builder.errors { + errs = append(errs, cog.MakeBuildErrors("NavbarPreference", err)...) + } + + if len(errs) != 0 { + return NavbarPreference{}, errs + } + + return *builder.internal, nil +} + +func (builder *NavbarPreferenceBuilder) SavedItemIds(savedItemIds []string) *NavbarPreferenceBuilder { + builder.internal.SavedItemIds = savedItemIds + + return builder +} + +func (builder *NavbarPreferenceBuilder) applyDefaults() { +} diff --git a/go/preferences/preferences_builder_gen.go b/go/preferences/preferences_builder_gen.go index 5e622be..2452c8c 100644 --- a/go/preferences/preferences_builder_gen.go +++ b/go/preferences/preferences_builder_gen.go @@ -101,5 +101,17 @@ func (builder *PreferencesBuilder) CookiePreferences(cookiePreferences cog.Build return builder } +// Navigation preferences +func (builder *PreferencesBuilder) Navbar(navbar cog.Builder[NavbarPreference]) *PreferencesBuilder { + navbarResource, err := navbar.Build() + if err != nil { + builder.errors["navbar"] = err.(cog.BuildErrors) + return builder + } + builder.internal.Navbar = &navbarResource + + return builder +} + func (builder *PreferencesBuilder) applyDefaults() { } diff --git a/go/preferences/types_gen.go b/go/preferences/types_gen.go index 19531a9..448b028 100644 --- a/go/preferences/types_gen.go +++ b/go/preferences/types_gen.go @@ -20,6 +20,8 @@ type Preferences struct { QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"` // Cookie preferences CookiePreferences *CookiePreferences `json:"cookiePreferences,omitempty"` + // Navigation preferences + Navbar *NavbarPreference `json:"navbar,omitempty"` } type QueryHistoryPreference struct { @@ -32,3 +34,7 @@ type CookiePreferences struct { Performance any `json:"performance,omitempty"` Functional any `json:"functional,omitempty"` } + +type NavbarPreference struct { + SavedItemIds []string `json:"savedItemIds"` +} diff --git a/java/LICENSE.md b/java/LICENSE.md new file mode 100644 index 0000000..c319da3 --- /dev/null +++ b/java/LICENSE.md @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/java/build.gradle b/java/build.gradle new file mode 100644 index 0000000..577265d --- /dev/null +++ b/java/build.gradle @@ -0,0 +1,114 @@ +plugins { + id 'java' + id 'maven-publish' + id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' + id 'signing' + id 'com.github.johnrengelman.shadow' version '8.1.1' +} + +group = "com.grafana" +version = project.properties['grafanaFoundationSDKVersion'] + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + + withJavadocJar() + withSourcesJar() +} + +shadowJar { + // allows maven to read the artifact (by default, it's "plain") + archiveClassifier.set('') +} + +allprojects { + version = rootProject.version + apply plugin: "java" + + repositories { + mavenCentral() + maven { + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") + mavenContent { + snapshotsOnly() + } + } + } + + test { + useJUnitPlatform() + } +} + +dependencies { + implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1' +} + +tasks.withType(Javadoc).configureEach { + options.addStringOption('Xdoclint:-missing', '-quiet') +} + +tasks.build.dependsOn shadowJar + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + + pom { + name = 'Grafana Foundation SDK' + description = 'A set of tools, types and libraries for building and manipulating Grafana objects.' + url = 'https://github.com/grafana/grafana-foundation-sdk' + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = "grafana" + name = "Grafana Labs" + email = "platform-cat@grafana.com" + } + } + scm { + connection = 'scm:git:git://github.com/grafana/grafana-foundation-sdk.git' + developerConnection = 'scm:git:ssh://github.com/grafana/grafana-foundation-sdk.git' + url = 'https://github.com/grafana/grafana-foundation-sdk' + } + } + } + } + repositories { + maven { + name = 'OSSRH' + url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/' + + credentials { + username = System.getenv('OSSRH_USERNAME') + password = System.getenv('OSSRH_PASSWORD') + } + } + } +} + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + + username = System.getenv("OSSRH_USERNAME") + password = System.getenv("OSSRH_PASSWORD") + } + } +} + +if (gradle.startParameter.taskNames.contains("publishToSonatype")) { + signing { + sign publishing.publications.mavenJava + useInMemoryPgpKeys(System.getenv("SIGNING_KEY"), System.getenv("SIGNING_PASSWORD")) + } +} diff --git a/java/gradle.properties b/java/gradle.properties new file mode 100644 index 0000000..39aad53 --- /dev/null +++ b/java/gradle.properties @@ -0,0 +1 @@ +grafanaFoundationSDKVersion=next-1721134277 diff --git a/java/settings.gradle b/java/settings.gradle new file mode 100644 index 0000000..b93e572 --- /dev/null +++ b/java/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'grafana-foundation-sdk' diff --git a/java/src/main/java/com/grafana/foundation/accesspolicy/AccessPolicy.java b/java/src/main/java/com/grafana/foundation/accesspolicy/AccessPolicy.java new file mode 100644 index 0000000..c387171 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/accesspolicy/AccessPolicy.java @@ -0,0 +1,57 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.accesspolicy; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import java.util.LinkedList; + +public class AccessPolicy { + // The scope where these policies should apply + @JsonProperty("scope") + public ResourceRef scope; + // The role that must apply this policy + @JsonProperty("role") + public RoleRef role; + // The set of rules to apply. Note that * is required to modify + // access policy rules, and that "none" will reject all actions + @JsonProperty("rules") + public List rules; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final AccessPolicy internal; + + public Builder() { + this.internal = new AccessPolicy(); + } + public Builder scope(com.grafana.foundation.cog.Builder scope) { + this.internal.scope = scope.build(); + return this; + } + + public Builder role(com.grafana.foundation.cog.Builder role) { + this.internal.role = role.build(); + return this; + } + + public Builder rules(com.grafana.foundation.cog.Builder rules) { + if (this.internal.rules == null) { + this.internal.rules = new LinkedList<>(); + } + this.internal.rules.add(rules.build()); + return this; + } + public AccessPolicy build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/accesspolicy/AccessRule.java b/java/src/main/java/com/grafana/foundation/accesspolicy/AccessRule.java new file mode 100644 index 0000000..2c0189b --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/accesspolicy/AccessRule.java @@ -0,0 +1,53 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.accesspolicy; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class AccessRule { + // The kind this rule applies to (dashboards, alert, etc) + @JsonProperty("kind") + public String kind; + // READ, WRITE, CREATE, DELETE, ... + // should move to k8s style verbs like: "get", "list", "watch", "create", "update", "patch", "delete" + @JsonProperty("verb") + public String verb; + // Specific sub-elements like "alert.rules" or "dashboard.permissions"???? + @JsonProperty("target") + public String target; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final AccessRule internal; + + public Builder() { + this.internal = new AccessRule(); + this.kind("*"); + } + public Builder kind(String kind) { + this.internal.kind = kind; + return this; + } + + public Builder verb(String verb) { + this.internal.verb = verb; + return this; + } + + public Builder target(String target) { + this.internal.target = target; + return this; + } + public AccessRule build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/accesspolicy/ResourceRef.java b/java/src/main/java/com/grafana/foundation/accesspolicy/ResourceRef.java new file mode 100644 index 0000000..1cbe771 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/accesspolicy/ResourceRef.java @@ -0,0 +1,41 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.accesspolicy; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class ResourceRef { + @JsonProperty("kind") + public String kind; + @JsonProperty("name") + public String name; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final ResourceRef internal; + + public Builder() { + this.internal = new ResourceRef(); + } + public Builder kind(String kind) { + this.internal.kind = kind; + return this; + } + + public Builder name(String name) { + this.internal.name = name; + return this; + } + public ResourceRef build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/accesspolicy/RoleRef.java b/java/src/main/java/com/grafana/foundation/accesspolicy/RoleRef.java new file mode 100644 index 0000000..70bc2cf --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/accesspolicy/RoleRef.java @@ -0,0 +1,50 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.accesspolicy; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class RoleRef { + // Policies can apply to roles, teams, or users + // Applying policies to individual users is supported, but discouraged + @JsonProperty("kind") + public RoleRefKind kind; + @JsonProperty("name") + public String name; + @JsonProperty("xname") + public String xname; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final RoleRef internal; + + public Builder() { + this.internal = new RoleRef(); + } + public Builder kind(RoleRefKind kind) { + this.internal.kind = kind; + return this; + } + + public Builder name(String name) { + this.internal.name = name; + return this; + } + + public Builder xname(String xname) { + this.internal.xname = xname; + return this; + } + public RoleRef build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/accesspolicy/RoleRefKind.java b/java/src/main/java/com/grafana/foundation/accesspolicy/RoleRefKind.java new file mode 100644 index 0000000..176a321 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/accesspolicy/RoleRefKind.java @@ -0,0 +1,27 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.accesspolicy; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonValue; + + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +public enum RoleRefKind { + ROLE("Role"), + BUILTIN_ROLE("BuiltinRole"), + TEAM("Team"), + USER("User"), + _EMPTY(""); + + private final String value; + + private RoleRefKind(String value) { + this.value = value; + } + + @JsonValue + public String Value() { + return value; + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/ContactPoint.java b/java/src/main/java/com/grafana/foundation/alerting/ContactPoint.java new file mode 100644 index 0000000..2a98635 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/ContactPoint.java @@ -0,0 +1,89 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +// EmbeddedContactPoint is the contact point type that is used +// by grafanas embedded alertmanager implementation. +public class ContactPoint { + // EmbeddedContactPoint is the contact point type that is used + // by grafanas embedded alertmanager implementation. + @JsonProperty("disableResolveMessage") + public Boolean disableResolveMessage; + // EmbeddedContactPoint is the contact point type that is used + // by grafanas embedded alertmanager implementation. + @JsonProperty("name") + public String name; + // EmbeddedContactPoint is the contact point type that is used + // by grafanas embedded alertmanager implementation. + @JsonProperty("provenance") + public String provenance; + // EmbeddedContactPoint is the contact point type that is used + // by grafanas embedded alertmanager implementation. + @JsonProperty("settings") + public Object settings; + // EmbeddedContactPoint is the contact point type that is used + // by grafanas embedded alertmanager implementation. + @JsonProperty("type") + public ContactPointType type; + // EmbeddedContactPoint is the contact point type that is used + // by grafanas embedded alertmanager implementation. + @JsonProperty("uid") + public String uid; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final ContactPoint internal; + + public Builder() { + this.internal = new ContactPoint(); + } + public Builder disableResolveMessage(Boolean disableResolveMessage) { + this.internal.disableResolveMessage = disableResolveMessage; + return this; + } + + public Builder name(String name) { + this.internal.name = name; + return this; + } + + public Builder provenance(String provenance) { + this.internal.provenance = provenance; + return this; + } + + public Builder settings(Object settings) { + this.internal.settings = settings; + return this; + } + + public Builder type(ContactPointType type) { + this.internal.type = type; + return this; + } + + public Builder uid(String uid) { + if (!(uid.length() >= 1)) { + throw new IllegalArgumentException("uid.length() must be >= 1"); + } + if (!(uid.length() <= 40)) { + throw new IllegalArgumentException("uid.length() must be <= 40"); + } + this.internal.uid = uid; + return this; + } + public ContactPoint build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/ContactPointType.java b/java/src/main/java/com/grafana/foundation/alerting/ContactPointType.java new file mode 100644 index 0000000..0563be5 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/ContactPointType.java @@ -0,0 +1,41 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonValue; + + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +public enum ContactPointType { + ALERTMANAGER("alertmanager"), + DINGDING(" dingding"), + DISCORD(" discord"), + EMAIL(" email"), + GOOGLECHAT(" googlechat"), + KAFKA(" kafka"), + LINE(" line"), + OPSGENIE(" opsgenie"), + PAGERDUTY(" pagerduty"), + PUSHOVER(" pushover"), + SENSUGO(" sensugo"), + SLACK(" slack"), + TEAMS(" teams"), + TELEGRAM(" telegram"), + THREEMA(" threema"), + VICTOROPS(" victorops"), + WEBHOOK(" webhook"), + WECOM(" wecom"), + _EMPTY(""); + + private final String value; + + private ContactPointType(String value) { + this.value = value; + } + + @JsonValue + public String Value() { + return value; + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/MatchType.java b/java/src/main/java/com/grafana/foundation/alerting/MatchType.java new file mode 100644 index 0000000..78b4a29 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/MatchType.java @@ -0,0 +1,27 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonValue; + + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +public enum MatchType { + EQUAL("="), + NOT_EQUAL("!="), + EQUAL_REGEX("=~"), + NOT_EQUAL_REGEX("!~"), + _EMPTY(""); + + private final String value; + + private MatchType(String value) { + this.value = value; + } + + @JsonValue + public String Value() { + return value; + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/Matcher.java b/java/src/main/java/com/grafana/foundation/alerting/Matcher.java new file mode 100644 index 0000000..3f25a2d --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/Matcher.java @@ -0,0 +1,48 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class Matcher { + @JsonProperty("Name") + public String name; + @JsonProperty("Type") + public MatchType type; + @JsonProperty("Value") + public String value; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final Matcher internal; + + public Builder() { + this.internal = new Matcher(); + } + public Builder name(String name) { + this.internal.name = name; + return this; + } + + public Builder type(MatchType type) { + this.internal.type = type; + return this; + } + + public Builder value(String value) { + this.internal.value = value; + return this; + } + public Matcher build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/MuteTiming.java b/java/src/main/java/com/grafana/foundation/alerting/MuteTiming.java new file mode 100644 index 0000000..7467f3a --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/MuteTiming.java @@ -0,0 +1,42 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class MuteTiming { + @JsonProperty("name") + public String name; + @JsonProperty("time_intervals") + public List timeIntervals; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final MuteTiming internal; + + public Builder() { + this.internal = new MuteTiming(); + } + public Builder name(String name) { + this.internal.name = name; + return this; + } + + public Builder timeIntervals(com.grafana.foundation.cog.Builder> timeIntervals) { + this.internal.timeIntervals = timeIntervals.build(); + return this; + } + public MuteTiming build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/NotificationPolicy.java b/java/src/main/java/com/grafana/foundation/alerting/NotificationPolicy.java new file mode 100644 index 0000000..2680962 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/NotificationPolicy.java @@ -0,0 +1,148 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +// A Route is a node that contains definitions of how to handle alerts. This is modified +// from the upstream alertmanager in that it adds the ObjectMatchers property. +public class NotificationPolicy { + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("continue") + public Boolean continueArg; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("group_by") + public List groupBy; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("group_interval") + public String groupInterval; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("group_wait") + public String groupWait; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("match") + public Map match; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("match_re") + public Map matchRe; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("matchers") + public List matchers; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("mute_time_intervals") + public List muteTimeIntervals; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("object_matchers") + public List> objectMatchers; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("provenance") + public String provenance; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("receiver") + public String receiver; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("repeat_interval") + public String repeatInterval; + // A Route is a node that contains definitions of how to handle alerts. This is modified + // from the upstream alertmanager in that it adds the ObjectMatchers property. + @JsonProperty("routes") + public List routes; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final NotificationPolicy internal; + + public Builder() { + this.internal = new NotificationPolicy(); + } + public Builder continueArg(Boolean continueArg) { + this.internal.continueArg = continueArg; + return this; + } + + public Builder groupBy(List groupBy) { + this.internal.groupBy = groupBy; + return this; + } + + public Builder groupInterval(String groupInterval) { + this.internal.groupInterval = groupInterval; + return this; + } + + public Builder groupWait(String groupWait) { + this.internal.groupWait = groupWait; + return this; + } + + public Builder match(Map match) { + this.internal.match = match; + return this; + } + + public Builder matchRe(Map matchRe) { + this.internal.matchRe = matchRe; + return this; + } + + public Builder matchers(List matchers) { + this.internal.matchers = matchers; + return this; + } + + public Builder muteTimeIntervals(List muteTimeIntervals) { + this.internal.muteTimeIntervals = muteTimeIntervals; + return this; + } + + public Builder objectMatchers(List> objectMatchers) { + this.internal.objectMatchers = objectMatchers; + return this; + } + + public Builder provenance(String provenance) { + this.internal.provenance = provenance; + return this; + } + + public Builder receiver(String receiver) { + this.internal.receiver = receiver; + return this; + } + + public Builder repeatInterval(String repeatInterval) { + this.internal.repeatInterval = repeatInterval; + return this; + } + + public Builder routes(com.grafana.foundation.cog.Builder> routes) { + this.internal.routes = routes.build(); + return this; + } + public NotificationPolicy build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/NotificationSettings.java b/java/src/main/java/com/grafana/foundation/alerting/NotificationSettings.java new file mode 100644 index 0000000..3df4c5a --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/NotificationSettings.java @@ -0,0 +1,71 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class NotificationSettings { + @JsonProperty("group_by") + public List groupBy; + @JsonProperty("group_interval") + public String groupInterval; + @JsonProperty("group_wait") + public String groupWait; + @JsonProperty("mute_time_intervals") + public List muteTimeIntervals; + @JsonProperty("receiver") + public String receiver; + @JsonProperty("repeat_interval") + public String repeatInterval; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final NotificationSettings internal; + + public Builder() { + this.internal = new NotificationSettings(); + this.groupBy(List.of("alertname", "grafana_folder")); + } + public Builder groupBy(List groupBy) { + this.internal.groupBy = groupBy; + return this; + } + + public Builder groupInterval(String groupInterval) { + this.internal.groupInterval = groupInterval; + return this; + } + + public Builder groupWait(String groupWait) { + this.internal.groupWait = groupWait; + return this; + } + + public Builder muteTimeIntervals(List muteTimeIntervals) { + this.internal.muteTimeIntervals = muteTimeIntervals; + return this; + } + + public Builder receiver(String receiver) { + this.internal.receiver = receiver; + return this; + } + + public Builder repeatInterval(String repeatInterval) { + this.internal.repeatInterval = repeatInterval; + return this; + } + public NotificationSettings build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/NotificationTemplate.java b/java/src/main/java/com/grafana/foundation/alerting/NotificationTemplate.java new file mode 100644 index 0000000..508f3a1 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/NotificationTemplate.java @@ -0,0 +1,48 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class NotificationTemplate { + @JsonProperty("name") + public String name; + @JsonProperty("provenance") + public String provenance; + @JsonProperty("template") + public String template; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final NotificationTemplate internal; + + public Builder() { + this.internal = new NotificationTemplate(); + } + public Builder name(String name) { + this.internal.name = name; + return this; + } + + public Builder provenance(String provenance) { + this.internal.provenance = provenance; + return this; + } + + public Builder template(String template) { + this.internal.template = template; + return this; + } + public NotificationTemplate build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/Query.java b/java/src/main/java/com/grafana/foundation/alerting/Query.java new file mode 100644 index 0000000..2a642a3 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/Query.java @@ -0,0 +1,66 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.grafana.foundation.cog.variants.Dataquery; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = QueryDeserializer.class) +public class Query { + @JsonProperty("datasourceUid") + public String datasourceUid; + @JsonProperty("model") + public Dataquery model; + @JsonProperty("queryType") + public String queryType; + @JsonProperty("refId") + public String refId; + @JsonProperty("relativeTimeRange") + public RelativeTimeRange relativeTimeRange; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final Query internal; + + public Builder(String refId) { + this.internal = new Query(); + this.internal.refId = refId; + } + public Builder datasourceUid(String datasourceUid) { + this.internal.datasourceUid = datasourceUid; + return this; + } + + public Builder model(com.grafana.foundation.cog.Builder model) { + this.internal.model = model.build(); + return this; + } + + public Builder queryType(String queryType) { + this.internal.queryType = queryType; + return this; + } + + public Builder refId(String refId) { + this.internal.refId = refId; + return this; + } + + public Builder relativeTimeRange(RelativeTimeRange relativeTimeRange) { + this.internal.relativeTimeRange = relativeTimeRange; + return this; + } + public Query build() { + return this.internal; + } + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/QueryDeserializer.java b/java/src/main/java/com/grafana/foundation/alerting/QueryDeserializer.java new file mode 100644 index 0000000..4b8c122 --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/QueryDeserializer.java @@ -0,0 +1,66 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.grafana.foundation.cog.variants.UnknownDataquery; +import com.grafana.foundation.cog.variants.Registry; +import com.grafana.foundation.cog.variants.Dataquery; +import com.grafana.foundation.cog.variants.Registry; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; +import java.util.Map; + +public class QueryDeserializer extends JsonDeserializer { + + @Override + public Query deserialize(JsonParser jp, DeserializationContext cxt) throws IOException, JsonProcessingException { + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + JsonNode root = mapper.readTree(jp); + + // Deserialise all the fields + Query query = new Query(); + if (root.has("datasourceUid")) { + query.datasourceUid = mapper.convertValue(root.get("datasourceUid"), new TypeReference<>() {}); + } + if (root.has("model")) { + query.model = mapper.convertValue(root.get("model"), new TypeReference<>() {}); + } + if (root.has("queryType")) { + query.queryType = mapper.convertValue(root.get("queryType"), new TypeReference<>() {}); + } + if (root.has("refId")) { + query.refId = mapper.convertValue(root.get("refId"), new TypeReference<>() {}); + } + if (root.has("relativeTimeRange")) { + query.relativeTimeRange = mapper.convertValue(root.get("relativeTimeRange"), new TypeReference<>() {}); + } + + + // Dataquery stuff + String datasourceType = ""; + Class clazz = Registry.getDataquery(datasourceType); + if (clazz != null) { + query.model = mapper.treeToValue(root.get("model"), clazz); + } else { + UnknownDataquery unknownDataquery = new UnknownDataquery(); + Iterator> fieldsIterator = root.get("model").fields(); + while (fieldsIterator.hasNext()) { + Map.Entry field = fieldsIterator.next(); + unknownDataquery.genericFields.put(field.getKey(), mapper.treeToValue(field.getValue(), Object.class)); + } + query.model = unknownDataquery; + } + + return query; + } +} diff --git a/java/src/main/java/com/grafana/foundation/alerting/RecordRule.java b/java/src/main/java/com/grafana/foundation/alerting/RecordRule.java new file mode 100644 index 0000000..d688b1d --- /dev/null +++ b/java/src/main/java/com/grafana/foundation/alerting/RecordRule.java @@ -0,0 +1,41 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. + +package com.grafana.foundation.alerting; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class RecordRule { + @JsonProperty("from") + public String from; + @JsonProperty("metric") + public String metric; + + public String toJSON() throws JsonProcessingException { + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + return ow.writeValueAsString(this); + } + + + public static class Builder implements com.grafana.foundation.cog.Builder { + private final RecordRule internal; + + public Builder() { + this.internal = new RecordRule(); + } + public Builder from(String from) { + this.internal.from = from; + return this; + } ...*[Comment body truncated]*