├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── domain-generator-maven-plugin ├── LICENSE.txt ├── pom.xml └── src │ └── main │ ├── java │ └── uk │ │ └── co │ │ └── szmg │ │ └── jsonbuildergenerator │ │ ├── CodeGenerator.java │ │ ├── DomainDescription.java │ │ ├── FieldDescription.java │ │ └── JsonBuilderGenerator.java │ └── resources │ └── templates │ ├── class.ftl │ └── factories.ftl ├── domain ├── LICENSE.txt ├── pom.xml └── src │ └── main │ ├── domainconfig │ ├── dashboard.yaml │ ├── graph.yaml │ ├── link.yaml │ ├── panels.yaml │ └── templating.yaml │ └── java │ └── uk │ └── co │ └── szmg │ └── grafana │ └── domain │ ├── BaseJsonObject.java │ ├── Colors.java │ ├── FromTo.java │ └── SelectedTemplate.java ├── grafana-dashboard-generator-cli ├── LICENSE.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── uk │ │ └── co │ │ └── szmg │ │ └── grafana │ │ └── cli │ │ ├── DashboardGeneratorApplication.java │ │ └── internal │ │ ├── CommandLineArgs.java │ │ ├── ExitPlease.java │ │ ├── Interaction.java │ │ └── UploaderConfig.java │ └── test │ ├── java │ └── uk │ │ └── co │ │ └── szmg │ │ └── grafana │ │ └── cli │ │ ├── DashboardStoreTest.java │ │ └── example │ │ └── OverviewDashboards.java │ └── resources │ └── test-endpoints.yaml ├── grafana-dashboard-generator-example ├── LICENSE.txt ├── dependency-reduced-pom.xml ├── pom.xml └── src │ └── main │ ├── java │ └── uk │ │ └── co │ │ └── szmg │ │ └── grafana │ │ └── example │ │ ├── Main.java │ │ └── dashboards │ │ ├── FirstDashboard.java │ │ ├── ManyDashboards.java │ │ ├── MyDashboardFactory.java │ │ ├── Utils.java │ │ └── complex │ │ ├── MultiEnvExampleDashboards.java │ │ ├── Resource.java │ │ ├── SampleAppEnvironment.java │ │ └── XYComponentFactory.java │ └── resources │ └── endpoints.yaml ├── grafana-dashboard-generator ├── LICENSE.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── uk │ │ └── co │ │ └── szmg │ │ └── grafana │ │ ├── DashboardFactory.java │ │ ├── DashboardSerializer.java │ │ ├── DashboardUploader.java │ │ ├── GrafanaClient.java │ │ ├── GrafanaEndpoint.java │ │ ├── dashboard │ │ ├── BasicFactories.java │ │ ├── ColorTheme.java │ │ ├── Environment.java │ │ ├── SimpleEnvironment.java │ │ └── StaticFactories.java │ │ └── stores │ │ ├── ClasspathGrafanaEndpointStore.java │ │ ├── DashboardFilter.java │ │ ├── DashboardStore.java │ │ ├── FileBasedGrafanaEndpointStore.java │ │ ├── GrafanaEndpointParser.java │ │ └── GrafanaEndpointStore.java │ └── test │ └── java │ └── uk │ └── co │ └── szmg │ └── grafana │ └── DashboardSerializerTest.java ├── grafana-dashboard-maven-plugin ├── LICENSE.txt ├── pom.xml └── src │ └── main │ └── java │ └── uk │ └── co │ └── szmg │ └── grafana │ └── maven │ ├── AbstractMojoWithClasspath.java │ ├── AbstractMojoWithDashboards.java │ ├── Generate.java │ ├── GenerateAndUpload.java │ └── Upload.java ├── pom.xml └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | output 5 | 6 | # I know... 7 | node_modules 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /domain-generator-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | grafana-dashboard-generator-parent 5 | uk.co.szmg.grafana 6 | 2.1.0-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | domain-generator-maven-plugin 11 | maven-plugin 12 | 13 | 14 | 15 | org.apache.maven 16 | maven-plugin-api 17 | 18 | 19 | org.apache.maven.plugin-tools 20 | maven-plugin-annotations 21 | provided 22 | 23 | 24 | org.apache.maven 25 | maven-project 26 | 27 | 28 | org.freemarker 29 | freemarker 30 | 31 | 32 | com.google.googlejavaformat 33 | google-java-format 34 | 35 | 36 | com.fasterxml.jackson.core 37 | jackson-databind 38 | 39 | 40 | com.fasterxml.jackson.dataformat 41 | jackson-dataformat-yaml 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-plugin-plugin 50 | 3.3 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /domain-generator-maven-plugin/src/main/java/uk/co/szmg/jsonbuildergenerator/CodeGenerator.java: -------------------------------------------------------------------------------- 1 | package uk.co.szmg.jsonbuildergenerator; 2 | 3 | /*- 4 | * #%L 5 | * domain-generator-maven-plugin 6 | * %% 7 | * Copyright (C) 2017 Mate Gabor Szvoboda 8 | * %% 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * #L% 21 | */ 22 | 23 | import com.google.googlejavaformat.java.Formatter; 24 | import com.google.googlejavaformat.java.FormatterException; 25 | import freemarker.template.Configuration; 26 | import freemarker.template.Template; 27 | import freemarker.template.TemplateException; 28 | import freemarker.template.TemplateExceptionHandler; 29 | import org.apache.maven.plugin.MojoFailureException; 30 | 31 | import java.io.IOException; 32 | import java.io.StringWriter; 33 | import java.util.HashMap; 34 | import java.util.List; 35 | import java.util.Map; 36 | 37 | public class CodeGenerator { 38 | 39 | private static final String CLASS_TEMPLATE = "class.ftl"; 40 | private static final String FACTORIES_TEMPLATE = "factories.ftl"; 41 | private static final String TEMPLATE_PATH = "templates"; 42 | 43 | private final Configuration templateCfg; 44 | private final Formatter codeFormatter; 45 | 46 | public CodeGenerator() { 47 | templateCfg = new Configuration(Configuration.VERSION_2_3_23); 48 | templateCfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), TEMPLATE_PATH); 49 | templateCfg.setDefaultEncoding("UTF-8"); 50 | templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); 51 | templateCfg.setLogTemplateExceptions(false); 52 | 53 | codeFormatter = new Formatter(); 54 | } 55 | 56 | public String generateJavaCodeFor(DomainDescription domain, String packageName) throws MojoFailureException { 57 | Map model = new HashMap<>(); 58 | model.put("domain", domain); 59 | model.put("packageName", packageName); 60 | 61 | Template temp = getTemplate(CLASS_TEMPLATE); 62 | String code = generateCode(model, temp); 63 | return formatCode(code); 64 | } 65 | 66 | public String generateFactories(List domains, String packageName) throws MojoFailureException { 67 | Map model = new HashMap<>(); 68 | model.put("domains", domains); 69 | model.put("packageName", packageName); 70 | 71 | Template temp = getTemplate(FACTORIES_TEMPLATE); 72 | String code = generateCode(model, temp); 73 | return formatCode(code); 74 | } 75 | 76 | private String formatCode(String code) throws MojoFailureException { 77 | try { 78 | return codeFormatter.formatSource(code); 79 | } catch (FormatterException e) { 80 | throw new MojoFailureException("Cannot format source code", e); 81 | } 82 | } 83 | 84 | private String generateCode(Map model, Template temp) throws MojoFailureException { 85 | StringWriter stringWriter = new StringWriter(); 86 | try { 87 | temp.process(model, stringWriter); 88 | } catch (TemplateException e) { 89 | throw new MojoFailureException("Error during source generation", e); 90 | } catch (IOException e) { 91 | throw new MojoFailureException("This just cannot happen... can it?", e); 92 | } 93 | return stringWriter.toString(); 94 | } 95 | 96 | private Template getTemplate(String name) throws MojoFailureException { 97 | try { 98 | return templateCfg.getTemplate(name); 99 | } catch (IOException e) { 100 | throw new MojoFailureException("Could not load template", e); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /domain-generator-maven-plugin/src/main/java/uk/co/szmg/jsonbuildergenerator/DomainDescription.java: -------------------------------------------------------------------------------- 1 | package uk.co.szmg.jsonbuildergenerator; 2 | 3 | /*- 4 | * #%L 5 | * domain-generator-maven-plugin 6 | * %% 7 | * Copyright (C) 2017 Mate Gabor Szvoboda 8 | * %% 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * #L% 21 | */ 22 | 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | public class DomainDescription { 29 | 30 | private String name; 31 | 32 | private List fields; 33 | 34 | private Map defaultValues; 35 | 36 | @JsonProperty("abstract") 37 | private boolean isAbstract; 38 | 39 | @JsonProperty("extends") 40 | private String extendedClass; 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public List getFields() { 47 | return fields; 48 | } 49 | 50 | public Map getDefaultValues() { 51 | return defaultValues; 52 | } 53 | 54 | public boolean isAbstract() { 55 | return isAbstract; 56 | } 57 | 58 | public String getExtendedClass() { 59 | return extendedClass; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /domain-generator-maven-plugin/src/main/java/uk/co/szmg/jsonbuildergenerator/FieldDescription.java: -------------------------------------------------------------------------------- 1 | package uk.co.szmg.jsonbuildergenerator; 2 | 3 | /*- 4 | * #%L 5 | * domain-generator-maven-plugin 6 | * %% 7 | * Copyright (C) 2017 Mate Gabor Szvoboda 8 | * %% 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * #L% 21 | */ 22 | 23 | public class FieldDescription { 24 | 25 | private String name; 26 | private String type; 27 | private String description; 28 | private boolean readonly; 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public String getType() { 35 | return type; 36 | } 37 | 38 | public String getDescription() { 39 | return description; 40 | } 41 | 42 | public boolean isReadonly() { 43 | return readonly; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /domain-generator-maven-plugin/src/main/java/uk/co/szmg/jsonbuildergenerator/JsonBuilderGenerator.java: -------------------------------------------------------------------------------- 1 | package uk.co.szmg.jsonbuildergenerator; 2 | 3 | /*- 4 | * #%L 5 | * domain-generator-maven-plugin 6 | * %% 7 | * Copyright (C) 2017 Mate Gabor Szvoboda 8 | * %% 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * #L% 21 | */ 22 | 23 | 24 | import com.fasterxml.jackson.databind.MappingIterator; 25 | import com.fasterxml.jackson.databind.ObjectMapper; 26 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 27 | import org.apache.maven.model.FileSet; 28 | import org.apache.maven.plugin.AbstractMojo; 29 | import org.apache.maven.plugin.MojoExecutionException; 30 | import org.apache.maven.plugin.MojoFailureException; 31 | import org.apache.maven.plugins.annotations.LifecyclePhase; 32 | import org.apache.maven.plugins.annotations.Mojo; 33 | import org.apache.maven.plugins.annotations.Parameter; 34 | import org.apache.maven.project.MavenProject; 35 | import org.codehaus.plexus.util.DirectoryScanner; 36 | import org.codehaus.plexus.util.StringUtils; 37 | 38 | import java.io.File; 39 | import java.io.FileWriter; 40 | import java.io.IOException; 41 | import java.util.ArrayList; 42 | import java.util.List; 43 | 44 | /** 45 | * In fact it doesn't build anything like Json. It's a bad name. 46 | * 47 | * Not thread-safe. 48 | */ 49 | @Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES) 50 | public class JsonBuilderGenerator extends AbstractMojo { 51 | 52 | @Parameter(defaultValue = "${project}", required = true) 53 | protected MavenProject project; 54 | 55 | @Parameter(defaultValue = "${project.build.directory}/generated-sources/jsonbuilder", required = true) 56 | protected File outputJavaDirectory; 57 | 58 | @Parameter(required = true) 59 | protected List descriptors; 60 | 61 | @Parameter 62 | protected String packageName; 63 | 64 | private CodeGenerator codeGenerator = new CodeGenerator(); 65 | 66 | private List generatedDomains = new ArrayList<>(); 67 | 68 | @Override 69 | public void execute() throws MojoExecutionException, MojoFailureException { 70 | if (this.project != null) { 71 | this.project.addCompileSourceRoot(this.outputJavaDirectory.getAbsolutePath()); 72 | } 73 | if (!this.outputJavaDirectory.mkdirs()) { 74 | getLog().error("Could not create source directory! (it might already exist)"); 75 | } else { 76 | try { 77 | generateDomains(); 78 | generateFactories(); 79 | } catch (IOException e) { 80 | throw new MojoExecutionException("Could not generate Java source code!", e); 81 | } 82 | } 83 | } 84 | 85 | private void generateFactories() throws MojoFailureException { 86 | String code = codeGenerator.generateFactories(generatedDomains, packageName); 87 | File f = createPackageDirsAndGetJavaFile("DomainFactories"); 88 | writeToFile(f, code); 89 | } 90 | 91 | private void generateDomains() throws IOException, MojoExecutionException, MojoFailureException { 92 | 93 | for (FileSet descriptor : descriptors) { 94 | DirectoryScanner scanner = new DirectoryScanner(); 95 | scanner.setBasedir(descriptor.getDirectory()); 96 | scanner.setIncludes(toArrayOrNull(descriptor.getIncludes())); 97 | scanner.setExcludes(toArrayOrNull(descriptor.getExcludes())); 98 | scanner.scan(); 99 | for (String yamlPath : scanner.getIncludedFiles()) { 100 | generateJavaCodeFor(new File(scanner.getBasedir(), yamlPath)); 101 | } 102 | } 103 | } 104 | 105 | private void generateJavaCodeFor(File yamlPath) throws MojoExecutionException, MojoFailureException { 106 | ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); 107 | try { 108 | MappingIterator iterator = mapper.readerFor(DomainDescription.class).readValues(yamlPath); 109 | while (iterator.hasNextValue()) { 110 | generateJavaCodeFor(iterator.next()); 111 | } 112 | } catch (IOException e) { 113 | getLog().error(String.format("Cannot parse descriptor [%s]", yamlPath), e); 114 | throw new MojoExecutionException(String.format("Cannot parse descriptor [%s]", yamlPath), e); 115 | } 116 | } 117 | 118 | private void generateJavaCodeFor(DomainDescription domain) throws MojoFailureException { 119 | getLog().info(String.format("Generating %s", domain.getName())); 120 | generatedDomains.add(domain); // :( 121 | 122 | String code = codeGenerator.generateJavaCodeFor(domain, packageName); 123 | File javaFile = createPackageDirsAndGetJavaFile(domain.getName()); 124 | writeToFile(javaFile, code); 125 | } 126 | 127 | private void writeToFile(File file, String content) throws MojoFailureException { 128 | try (FileWriter writer = new FileWriter(file)) { 129 | writer.write(content); 130 | } catch (IOException e) { 131 | throw new MojoFailureException("Could not write source file", e); 132 | } 133 | } 134 | 135 | private File createPackageDirsAndGetJavaFile(String name) { 136 | File dir = new File(outputJavaDirectory.getAbsolutePath()); 137 | if (StringUtils.isNotBlank(packageName)) { 138 | dir = new File(dir, packageName.replaceAll("\\.", File.separator)); 139 | } 140 | dir.mkdirs(); 141 | 142 | return new File(dir, name + ".java"); 143 | } 144 | 145 | private static String[] toArrayOrNull(List list) { 146 | String[] result = null; 147 | if (list != null && !list.isEmpty()) { 148 | result = list.toArray(new String[list.size()]); 149 | } 150 | return result; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /domain-generator-maven-plugin/src/main/resources/templates/class.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | #%L 3 | domain-generator-maven-plugin 4 | %% 5 | Copyright (C) 2017 Mate Gabor Szvoboda 6 | %% 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | #L% 19 | --> 20 | <#if packageName??>package ${packageName}; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | <#assign className = domain.name?cap_first> 27 | <#assign withReturnType = className> 28 | <#assign parent = domain.extendedClass!"BaseJsonObject"> 29 | <#if domain.abstract> 30 | <#assign withReturnType = "C"> 31 | public abstract class ${className}> extends ${parent} { 32 | <#else> 33 | public class ${className} extends ${parent}<${className}> { 34 | 35 | 36 | 37 | <#list domain.fields as field> 38 | protected static final String ${toConstName(field.name)} = "${field.name?j_string}"; 39 | 40 | 41 | 42 | public ${className}() { 43 | super(); 44 | <#if domain.defaultValues??> 45 | <#list domain.defaultValues?keys as field> 46 | setValue("${field?j_string}", ${domain.defaultValues[field]}); 47 | 48 | 49 | } 50 | 51 | 52 | <#list domain.fields as field> 53 | <#assign fieldNameConst = toConstName(field.name)> 54 | <#assign fieldNameCap = field.name?cap_first> 55 | 56 | /** 57 | * Gets ${field.name}. 58 | * ${field.description!?html} 59 | * 60 | * @return ${field.name} 61 | */ 62 | public ${field.type} get${fieldNameCap}() { 63 | return getValue(${fieldNameConst}); 64 | } 65 | 66 | /** 67 | * Sets ${field.name}. 68 | * ${field.description!?html} 69 | * 70 | * @param ${field.name} the ${field.name} 71 | */ 72 | public void set${fieldNameCap}(${field.type} ${field.name}) { 73 | setValue(${fieldNameConst}, ${field.name}); 74 | } 75 | 76 | /** 77 | * Sets ${field.name}. 78 | * ${field.description!?html} 79 | * 80 | * @param ${field.name} the ${field.name} 81 | * @return itself 82 | */ 83 | public ${withReturnType} with${fieldNameCap}(${field.type} ${field.name}) { 84 | return withValue(${fieldNameConst}, ${field.name}); 85 | } 86 | 87 | <#if field.type?starts_with("List<")> 88 | <#assign innerType = field.type?keep_after("<")?keep_before_last(">")> 89 | <#assign singularName = fieldNameCap?remove_ending("s")> 90 | <#assign paramName = singularName?uncap_first> 91 | 92 | /** 93 | * Adds a(n) ${field.name?remove_ending("s")}. 94 | * ${field.description!?html} 95 | * 96 | * @param ${paramName} the ${paramName} 97 | * @return itself 98 | */ 99 | public ${withReturnType} add${singularName}(${innerType} ${paramName}) { 100 | ${field.type} _list = get${fieldNameCap}(); 101 | if (_list == null) { 102 | _list = new java.util.ArrayList<>(); 103 | } 104 | _list.add(${paramName}); 105 | return with${fieldNameCap}(_list); 106 | } 107 | 108 | 109 | 110 | <#if domain.abstract> 111 | /** Generic implementation of ${className}. It's easier to to use sometimes. */ 112 | public static class Generic extends ${className} { } 113 | 114 | 115 | } 116 | 117 | 118 | <#function toConstName name> 119 | <#return "FIELD_" + name?replace("[A-Z]", "_$0", "r")?upper_case> 120 | 121 | -------------------------------------------------------------------------------- /domain-generator-maven-plugin/src/main/resources/templates/factories.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | #%L 3 | domain-generator-maven-plugin 4 | %% 5 | Copyright (C) 2017 Mate Gabor Szvoboda 6 | %% 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | #L% 19 | --> 20 | <#if packageName??>package ${packageName}; 21 | 22 | public class DomainFactories { 23 | 24 | protected DomainFactories() { } 25 | 26 | <#list domains as domain> 27 | <#if !domain.abstract> 28 | <#assign className = domain.name?cap_first> 29 | 30 | /** 31 | * Creates a new ${domain.name}. 32 | * @return a new instance of ${className} 33 | */ 34 | public static ${className} new${className}() { 35 | return new ${className}(); 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /domain/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | grafana-dashboard-generator-parent 5 | uk.co.szmg.grafana 6 | 2.1.0-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | domain 11 | 12 | 13 | 14 | com.fasterxml.jackson.core 15 | jackson-databind 16 | 17 | 18 | 19 | 20 | 21 | 22 | uk.co.szmg.grafana 23 | domain-generator-maven-plugin 24 | ${parent.version} 25 | 26 | 27 | 28 | generate 29 | 30 | 31 | uk.co.szmg.grafana.domain 32 | 33 | 34 | ${project.basedir}/src/main/domainconfig 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /domain/src/main/domainconfig/dashboard.yaml: -------------------------------------------------------------------------------- 1 | name: Dashboard 2 | fields: 3 | - name: id 4 | type: Integer 5 | - name: title 6 | type: String 7 | - name: style 8 | type: String 9 | description: "Style, e.g., 'dark'" 10 | - name: timezone 11 | type: String 12 | description: "E.g., 'browser'" 13 | - name: editable 14 | type: Boolean 15 | - name: hideControls 16 | type: Boolean 17 | - name: graphTooltip 18 | type: Integer 19 | - name: rows 20 | type: List 21 | - name: time 22 | type: FromTo 23 | - name: tags 24 | type: List 25 | description: "List of tags, which can be used for e.g., link generation" 26 | - name: links 27 | type: List 28 | description: "Links to be shown on the top of the dashboard." 29 | - name: annotations 30 | type: AnnotationList 31 | - name: templating 32 | type: TemplateList 33 | 34 | --- 35 | name: Row 36 | fields: 37 | - name: collapse 38 | type: Boolean 39 | - name: editable 40 | type: Boolean 41 | - name: height 42 | type: String 43 | description: "E.g., '200px'" 44 | - name: panels 45 | type: List 46 | - name: title 47 | type: String 48 | 49 | --- 50 | name: DashboardLevelLink 51 | abstract: true 52 | fields: 53 | - name: type 54 | type: String 55 | readonly: true 56 | 57 | --- 58 | name: ExternalDashboardLevelLink 59 | extends: DashboardLevelLink 60 | defaultValues: 61 | type: '"link"' 62 | fields: 63 | - name: icon 64 | type: String 65 | - name: includeVars 66 | type: Boolean 67 | - name: keepTime 68 | type: Boolean 69 | - name: targetBlank 70 | type: Boolean 71 | - name: title 72 | type: String 73 | - name: tooltip 74 | type: String 75 | - name: url 76 | type: String 77 | 78 | --- 79 | name: LinksToDashboards 80 | extends: DashboardLevelLink 81 | defaultValues: 82 | type: '"dashboards"' 83 | tags: 'new java.util.ArrayList()' 84 | fields: 85 | - name: includeVars 86 | type: Boolean 87 | - name: keepTime 88 | type: Boolean 89 | - name: targetBlank 90 | type: Boolean 91 | - name: tags 92 | type: List 93 | 94 | --- 95 | name: DropdownToDashboards 96 | extends: DashboardLevelLink 97 | defaultValues: 98 | type: '"dashboards"' 99 | asDropdown: 'true' 100 | tags: 'new java.util.ArrayList()' 101 | fields: 102 | - name: asDropdown 103 | type: Boolean 104 | readonly: true 105 | - name: includeVars 106 | type: Boolean 107 | - name: keepTime 108 | type: Boolean 109 | - name: targetBlank 110 | type: Boolean 111 | - name: tags 112 | type: List 113 | - name: title 114 | type: String 115 | 116 | --- 117 | name: AnnotationList 118 | fields: 119 | - name: list 120 | type: List 121 | 122 | --- 123 | name: Annotation 124 | abstract: true 125 | fields: 126 | - name: datasource 127 | type: String 128 | - name: enable 129 | type: Boolean 130 | - name: iconColor 131 | type: String 132 | - name: name 133 | type: String 134 | 135 | --- 136 | name: AlertAnnotation 137 | extends: Annotation 138 | defaultValues: 139 | datasource: '"-- Grafana --"' 140 | type: '"alert"' 141 | fields: 142 | - name: limit 143 | type: Integer 144 | description: "Watch out, it can't be anything in the UI. 10, 50, 100, 200, 300, 500, 1000, 2000." 145 | - name: type 146 | type: String 147 | 148 | --- 149 | name: GraphiteAnnotation 150 | extends: Annotation 151 | fields: 152 | - name: tags 153 | type: String 154 | description: "Graphite events query" 155 | - name: target 156 | type: String 157 | description: "Graphite metrics query" 158 | -------------------------------------------------------------------------------- /domain/src/main/domainconfig/graph.yaml: -------------------------------------------------------------------------------- 1 | name: Graph 2 | extends: Panel 3 | defaultValues: 4 | type: '"graph"' 5 | fields: 6 | - name: aliasColors 7 | type: Object 8 | description: "TODO" 9 | - name: bars 10 | type: Boolean 11 | - name: datasource 12 | type: String 13 | - name: fill 14 | type: Integer 15 | - name: legend 16 | type: Legend 17 | - name: lines 18 | type: Boolean 19 | - name: linewidth 20 | type: Integer 21 | - name: links 22 | type: List 23 | - name: nullPointMode 24 | type: String 25 | description: "Possible values: 'null', 'null as zero', 'connected'" 26 | - name: percentage 27 | type: Boolean 28 | - name: pointradius 29 | type: Integer 30 | - name: points 31 | type: Boolean 32 | - name: renderer 33 | type: String 34 | description: "TODO what is this? it's flot by default" 35 | - name: seriesOverrides 36 | type: List 37 | - name: stack 38 | type: Boolean 39 | - name: steppedLine 40 | type: Boolean 41 | description: "It's called 'Staircase' on UI (belongs to lines draw mode)" 42 | - name: targets 43 | type: List 44 | - name: thresholds 45 | type: List 46 | - name: timeFrom 47 | type: String 48 | description: "Override relative time, e.g., 1h" 49 | - name: timeShift 50 | type: String 51 | description: "Add time shift, e.g., 1h" 52 | - name: tooltip 53 | type: Tooltip 54 | - name: xaxis 55 | type: XAxis 56 | - name: yaxes 57 | type: List 58 | description: "Length should be 2: left, right. TODO" 59 | 60 | --- 61 | name: Legend 62 | fields: 63 | - name: alignAsTable 64 | type: Boolean 65 | - name: avg 66 | type: Boolean 67 | - name: current 68 | type: Boolean 69 | - name: hideEmpty 70 | type: Boolean 71 | - name: hideZero 72 | type: Boolean 73 | - name: max 74 | type: Boolean 75 | - name: min 76 | type: Boolean 77 | - name: rightSide 78 | type: Boolean 79 | - name: show 80 | type: Boolean 81 | - name: total 82 | type: Boolean 83 | - name: values 84 | type: Boolean 85 | 86 | --- 87 | name: Tooltip 88 | fields: 89 | - name: shared 90 | type: Boolean 91 | description: "True if all series is in one tooltip." 92 | - name: sort 93 | type: Integer 94 | description: "Sort order; 0=None, 1=Increasing, 2=Decreasing" 95 | - name: value_type 96 | type: String 97 | description: "Stacked value; 'individual' or 'cumulative'" 98 | 99 | --- 100 | name: XAxis 101 | fields: 102 | - name: mode 103 | type: String 104 | description: "time or series" 105 | - name: name 106 | type: String 107 | - name: show 108 | type: Boolean 109 | - name: values 110 | type: List 111 | description: "Use when mode is 'series'. Add one of 'avg', 'max', 'min', 'total', 'count', 'current'." 112 | 113 | --- 114 | name: YAxis 115 | fields: 116 | - name: format 117 | type: String 118 | description: "Format, e.g., 'short', 'ms'" 119 | - name: label 120 | type: String 121 | description: "Label on axis" 122 | - name: logBase 123 | type: Integer 124 | description: "1: linear, 2: log2, 10: log10, ..." 125 | - name: max 126 | type: String 127 | description: "Forced max value" 128 | - name: min 129 | type: String 130 | description: "Forced min value" 131 | - name: show 132 | type: Boolean 133 | 134 | --- 135 | name: Threshold 136 | fields: 137 | - name: colorMode 138 | type: String 139 | description: "'critical', 'warning', 'ok' or 'custom'" 140 | - name: op 141 | type: String 142 | description: "'gt' or 'lt'" 143 | - name: value 144 | type: Integer 145 | - name: fill 146 | type: Boolean 147 | description: 148 | - name: fillColor 149 | type: String 150 | description: "Only is colorMode is custom, e.g., rgb(222, 21, 21)" 151 | - name: line 152 | type: Boolean 153 | description: 154 | - name: lineColor 155 | type: String 156 | description: "Only is colorMode is custom, e.g., rgb(222, 21, 21)" 157 | 158 | --- 159 | name: SeriesOverride 160 | fields: 161 | - name: alias 162 | type: String 163 | description: "Alias or regex. Add fields to override with the addField method." 164 | -------------------------------------------------------------------------------- /domain/src/main/domainconfig/link.yaml: -------------------------------------------------------------------------------- 1 | name: Link 2 | abstract: true 3 | fields: 4 | - name: type 5 | type: String 6 | readonly: true 7 | - name: title 8 | type: String 9 | - name: includeVars 10 | type: Boolean 11 | - name: keepTime 12 | type: Boolean 13 | - name: targetBlank 14 | type: Boolean 15 | - name: params 16 | type: String 17 | 18 | --- 19 | name: DashboardLink 20 | extends: Link 21 | defaultValues: 22 | type: '"dashboard"' 23 | fields: 24 | - name: dashboard 25 | type: String 26 | 27 | --- 28 | name: AbsoluteLink 29 | extends: Link 30 | defaultValues: 31 | type: '"absolute"' 32 | fields: 33 | - name: url 34 | type: String 35 | 36 | -------------------------------------------------------------------------------- /domain/src/main/domainconfig/panels.yaml: -------------------------------------------------------------------------------- 1 | name: Panel 2 | abstract: true 3 | fields: 4 | - name: id 5 | type: Integer 6 | - name: title 7 | type: String 8 | - name: description 9 | type: String 10 | - name: span 11 | type: Integer 12 | - name: height 13 | type: String 14 | - name: transparent 15 | type: Boolean 16 | - name: minSpan 17 | type: Integer 18 | - name: type 19 | type: String 20 | readonly: true 21 | 22 | 23 | --- 24 | name: Text 25 | extends: Panel 26 | defaultValues: 27 | type: '"text"' 28 | fields: 29 | - name: mode 30 | type: String 31 | description: "Render mode, valid values are 'html', 'markdown', 'text'" 32 | - name: content 33 | type: String 34 | 35 | --- 36 | name: SingleStat 37 | extends: Panel 38 | defaultValues: 39 | type: '"singlestat"' 40 | fields: 41 | - name: cacheTimeout 42 | type: Integer 43 | - name: colorBackground 44 | type: Boolean 45 | - name: colorValue 46 | type: Boolean 47 | - name: colors 48 | type: Colors 49 | - name: datasource 50 | type: String 51 | - name: format 52 | type: String 53 | description: "E.g., 'short', 'ms'" 54 | - name: gauge 55 | type: Gauge 56 | - name: interval 57 | type: String 58 | description: "TODO what is this?" 59 | - name: links 60 | type: List 61 | - name: mappingType 62 | type: Integer 63 | description: "1 --> value to text; 2 --> range to text" 64 | - name: mappingTypes 65 | type: Object 66 | description: "TODO 'value to text' = 1; 'range to text' = 2" 67 | - name: maxDataPoints 68 | type: Integer 69 | - name: nullPointMode 70 | type: String 71 | description: "Default value: 'connected'" 72 | - name: nullText 73 | type: String 74 | - name: postfix 75 | type: String 76 | - name: postfixFontSize 77 | type: String 78 | description: "Default value: '50%'" 79 | - name: prefix 80 | type: String 81 | - name: prefixFontSize 82 | type: String 83 | description: "Default value: '50%'" 84 | - name: rangeMaps 85 | type: List 86 | description: "mappingType should be 2" 87 | - name: sparkline 88 | type: Sparkline 89 | - name: targets 90 | type: List 91 | - name: thresholds 92 | type: String 93 | - name: valueFontSize 94 | type: String 95 | description: "Default value: '80%'" 96 | - name: valueMaps 97 | type: List 98 | description: "mappingType should be 1" 99 | - name: valueName 100 | type: String 101 | description: "Default value: 'avg'. Possible names: 'min', 'max', 'avg', 'current', 'total', 'name', 'first', 'delta', 'diff', 'range'." 102 | 103 | --- 104 | name: Gauge 105 | defaultValues: 106 | show: 'true' # If a gauge is not null, user wants it to show. 107 | fields: 108 | - name: maxValue 109 | type: Integer 110 | - name: minValue 111 | type: Integer 112 | - name: show 113 | type: Boolean 114 | - name: thresholdLabels 115 | type: Boolean 116 | - name: thresholdMarkers 117 | type: Boolean 118 | 119 | --- 120 | name: Sparkline 121 | defaultValues: 122 | show: 'true' # If a gauge is not null, user wants it to show. 123 | fields: 124 | - name: fillColor 125 | type: String 126 | - name: full 127 | type: Boolean 128 | - name: show 129 | type: Boolean 130 | - name: lineColor 131 | type: String 132 | 133 | --- 134 | name: Target #TODO move to normal object and create a very nice builder (with functions maybe) 135 | fields: 136 | - name: refId 137 | type: String 138 | - name: target 139 | type: String 140 | 141 | --- 142 | name: RangeMapping 143 | fields: 144 | - name: from 145 | type: String 146 | - name: to 147 | type: String 148 | - name: text 149 | type: String 150 | 151 | --- 152 | name: ValueMapping 153 | fields: 154 | - name: value 155 | type: String 156 | - name: op 157 | type: String 158 | description: 'E.g., "="' 159 | - name: text 160 | type: String 161 | -------------------------------------------------------------------------------- /domain/src/main/domainconfig/templating.yaml: -------------------------------------------------------------------------------- 1 | name: TemplateList 2 | fields: 3 | - name: list 4 | type: List