├── .classpath ├── .gitignore ├── .project ├── .settings └── org.eclipse.buildship.core.prefs ├── LICENSE ├── README.md ├── bin ├── albums.json ├── log4j.properties └── messages.properties ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── iac ├── CICD-Flow.PNG ├── ansible │ ├── roles │ │ ├── selinux │ │ │ └── tasks │ │ │ │ └── main.yml │ │ └── tomcat │ │ │ ├── files │ │ │ └── tomcat-initscript.sh │ │ │ ├── handlers │ │ │ └── main.yml │ │ │ ├── tasks │ │ │ └── main.yml │ │ │ └── templates │ │ │ ├── iptables-save │ │ │ ├── server.xml │ │ │ └── tomcat-users.xml │ └── site.yml └── terraform │ ├── apply.sh │ ├── azure │ ├── backend.tfvars │ ├── main.tf │ └── variables.tf │ ├── graph.sh │ └── init.sh ├── manifest.yml ├── src └── main │ ├── java │ └── org │ │ └── cloudfoundry │ │ └── samples │ │ └── music │ │ ├── config │ │ ├── AppInitializer.java │ │ ├── SpringApplicationContextInitializer.java │ │ ├── data │ │ │ ├── AbstractJpaRepositoryConfig.java │ │ │ ├── AbstractLocalDataSourceConfig.java │ │ │ ├── H2DataSourceConfig.java │ │ │ ├── LocalJpaRepositoryConfig.java │ │ │ ├── MongoCloudConfig.java │ │ │ ├── MongoConfig.java │ │ │ ├── MongoLocalConfig.java │ │ │ ├── MySqlLocalDataSourceConfig.java │ │ │ ├── MySqlRepositoryConfig.java │ │ │ ├── OracleRepositoryConfig.java │ │ │ ├── PostgresLocalDataSourceConfig.java │ │ │ ├── PostgresRepositoryConfig.java │ │ │ ├── RedisCloudConfig.java │ │ │ ├── RedisConfig.java │ │ │ ├── RedisLocalConfig.java │ │ │ └── RelationalCloudDataSourceConfig.java │ │ ├── root │ │ │ └── RepositoryConfig.java │ │ └── web │ │ │ └── WebMvcConfig.java │ │ ├── domain │ │ ├── Album.java │ │ ├── ApplicationInfo.java │ │ └── RandomIdGenerator.java │ │ ├── repositories │ │ ├── AlbumRepository.java │ │ ├── AlbumRepositoryPopulator.java │ │ ├── jpa │ │ │ └── JpaAlbumRepository.java │ │ ├── mongodb │ │ │ └── MongoAlbumRepository.java │ │ └── redis │ │ │ └── RedisAlbumRepository.java │ │ └── web │ │ └── controllers │ │ ├── AlbumController.java │ │ ├── ErrorController.java │ │ └── InfoController.java │ ├── resources │ ├── albums.json │ ├── log4j.properties │ └── messages.properties │ └── webapp │ ├── WEB-INF │ └── index.html │ └── assets │ ├── css │ ├── app.css │ └── multi-columns-row.css │ ├── img │ ├── glyphicons-halflings-white.png │ └── glyphicons-halflings.png │ ├── js │ ├── albums.js │ ├── app.js │ ├── errors.js │ ├── info.js │ └── status.js │ └── templates │ ├── albumForm.html │ ├── albums.html │ ├── errors.html │ ├── footer.html │ ├── grid.html │ ├── header.html │ ├── list.html │ └── status.html └── vsts ├── Build-Java-CI.json └── Java-Terraform-CD.json /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | .gradle/ 24 | build/ 25 | target/ 26 | .git/ 27 | .terraform/ 28 | .settings/ -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DemoJava 4 | Project DemoJava created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.buildship.core.gradleprojectnature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu May 24 11:08:06 EDT 2018 2 | connection.project.dir= 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Continuous Integration and Deployment using VSTS , Terraform and Ansible 2 | ============ 3 | 4 | This repo is demontrating CI/CD Flow: 5 | - Uses VSTS Build to build SpringMusic App (gradle) 6 | - Uses VSTS Release to invoke Terraform to provision Infrastructure for the application (VMSS, LB, NSG) 7 | - Uses VSTS Release to invoke Ansible to install JDK, Tomcat 7 and SpringMusic App on provisioned VMs 8 | 9 | ![Flow](./iac/CICD-Flow.PNG) 10 | 11 | ## Terraform 12 | Terraform template is located at `iac/terraform`. It creates VM Scale Set based on RedHat 7.3 image in marketplace. 13 | VSTS uses Azure Storage backend to store state file. Storage account and Container should be created before starting the build. (Defaults are in backend.tfvars) 14 | 15 | ## Ansible 16 | Ansible playbook is located at `iac/ansible`. It uses `selinux` and `tomcat` roles to inctall and configure JDK, Tomcat 7 and deploy the application. 17 | 18 | 19 | ## Spring Music Sample Application 20 | 21 | 22 | This is a sample application for using database services on [Cloud Foundry](http://cloudfoundry.org) with the [Spring Framework](http://spring.io). 23 | 24 | This application has been built to store the same domain objects in one of a variety of different persistence technologies - relational, document, and key-value stores. This is not meant to represent a realistic use case for these technologies, since you would typically choose the one most applicable to the type of data you need to store, but it is useful for testing and experimenting with different types of services on Cloud Foundry. 25 | 26 | The application use Spring Java configuration and [bean profiles](https://spring.io/blog/2011/02/14/spring-3-1-m1-introducing-profile/) to configure the application and the connection objects needed to use the persistence stores. It also uses the [Spring Cloud Connectors](http://cloud.spring.io/spring-cloud-connectors/) library to inspect the environment when running on Cloud Foundry. See the [Cloud Foundry documentation](http://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html) for details on configuring a Spring application for Cloud Foundry. 27 | 28 | ## Running the application locally 29 | 30 | One Spring bean profile should be activated to choose the database provider that the application should use. The profile is selected by setting the system property `spring.profiles.active` when starting the app. 31 | 32 | The application can be started locally using the following command: 33 | 34 | ~~~ 35 | $ ./gradlew tomcatRun -Dspring.profiles.active= 36 | ~~~ 37 | 38 | where `` is one of the following values: 39 | 40 | * `in-memory` (no external database required) 41 | * `mysql` 42 | * `postgres` 43 | * `mongodb` 44 | * `redis` 45 | 46 | If no profile is provided, `in-memory` will be used. If any other profile is provided, the appropriate database server 47 | must be started separately. The application will use the host name `localhost` and the default port to connect to the database. 48 | 49 | If more than one of these profiles is provided, the application will throw an exception and fail to start. 50 | 51 | ## Running the application on Cloud Foundry 52 | 53 | When running on Cloud Foundry, the application will detect the type of database service bound to the application 54 | (if any). If a service of one of the supported types (MySQL, Postgres, Oracle, MongoDB, or Redis) is bound to the app, the 55 | appropriate Spring profile will be configured to use the database service. The connection strings and credentials 56 | needed to use the service will be extracted from the Cloud Foundry environment. 57 | 58 | If no bound services are found containing any of these values in the name, then the `in-memory` profile will be used. 59 | 60 | If more than one service containing any of these values is bound to the application, the application will throw an 61 | exception and fail to start. 62 | 63 | After installing the 'cf' [command-line interface for Cloud Foundry](http://docs.cloudfoundry.org/cf-cli/), targeting a Cloud Foundry instance, and logging in, the application can be built and pushed using these commands: 64 | 65 | ~~~ 66 | $ ./gradlew assemble 67 | 68 | $ cf push 69 | ~~~ 70 | 71 | The application will be pushed using settings in the provided `manifest.yml` file. The output from the command will show the URL that has been assigned to the application. 72 | 73 | ### Creating and binding services 74 | 75 | Using the provided manifest, the application will be created without an external database (in the `in-memory` profile). 76 | You can create and bind database services to the application using the information below. 77 | 78 | #### System-managed services 79 | 80 | Depending on the Cloud Foundry service provider, persistence services might be offered and managed by the platform. These 81 | steps can be used to create and bind a service that is managed by the platform: 82 | 83 | ~~~ 84 | # view the services available 85 | $ cf marketplace 86 | # create a service instance 87 | $ cf create-service 88 | # bind the service instance to the application 89 | $ cf bind-service 90 | # restart the application so the new service is detected 91 | $ cf restart 92 | ~~~ 93 | 94 | #### User-provided services 95 | 96 | Cloud Foundry also allows service connection information and credentials to be provided by a user. In order for the 97 | application to detect and connect to a user-provided service, a single `uri` field should be given in the credentials 98 | using the form `://:@:/`. 99 | 100 | These steps use examples for username, password, host name, and database name that should be replaced with real values. 101 | 102 | ~~~ 103 | # create a user-provided Oracle database service instance 104 | $ cf create-user-provided-service oracle-db -p '{"uri":"oracle://root:secret@dbserver.example.com:1521/mydatabase"}' 105 | # create a user-provided MySQL database service instance 106 | $ cf create-user-provided-service mysql-db -p '{"uri":"mysql://root:secret@dbserver.example.com:3306/mydatabase"}' 107 | # bind a service instance to the application 108 | $ cf bind-service 109 | # restart the application so the new service is detected 110 | $ cf restart 111 | ~~~ 112 | 113 | #### Changing bound services 114 | 115 | To test the application with different services, you can simply stop the app, unbind a service, bind a different 116 | database service, and start the app: 117 | 118 | ~~~ 119 | $ cf unbind-service 120 | $ cf bind-service 121 | $ cf restart 122 | ~~~ 123 | 124 | ## Courses using this application. 125 | 126 | `Note`: When updating this application please make sure the corresponding instructions are updated within the following dependent courses. The instructions for these labs may not change but please review before pushing application to production with this [pipeline](http://concourse.enablement.pivotal.io/pipelines/spring-music-war). 127 | 128 | - [pivotal-cloud-foundry-developer](https://github.com/pivotal-education/pivotal-cloud-foundry-developer): 129 | 130 | #### Database drivers 131 | 132 | Database drivers for MySQL, Postgres, MongoDB, and Redis are included in the project. To connect to an Oracle database, 133 | you will need to download the appropriate driver (e.g. from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html?ssSourceSiteId=otnjp), 134 | add the driver .jar file to the `src/main/webapp/WEB-INF/lib` directory in the project, and re-build the 135 | application .war file using `./gradlew assemble`. 136 | -------------------------------------------------------------------------------- /bin/albums.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "_class": "org.cloudfoundry.samples.music.domain.Album", 4 | "artist": "Nirvana", 5 | "title": "Nevermind", 6 | "releaseYear": "1991", 7 | "genre": "Rock" 8 | }, 9 | { 10 | "_class": "org.cloudfoundry.samples.music.domain.Album", 11 | "artist": "The Beach Boys", 12 | "title": "Pet Sounds", 13 | "releaseYear": "1966", 14 | "genre": "Rock" 15 | }, 16 | { 17 | "_class": "org.cloudfoundry.samples.music.domain.Album", 18 | "artist": "Marvin Gaye", 19 | "title": "What's Going On", 20 | "releaseYear": "1971", 21 | "genre": "Rock" 22 | }, 23 | { 24 | "_class": "org.cloudfoundry.samples.music.domain.Album", 25 | "artist": "Jimi Hendrix Experience", 26 | "title": "Are You Experienced?", 27 | "releaseYear": "1967", 28 | "genre": "Rock" 29 | }, 30 | { 31 | "_class": "org.cloudfoundry.samples.music.domain.Album", 32 | "artist": "U2", 33 | "title": "The Joshua Tree", 34 | "releaseYear": "1987", 35 | "genre": "Rock" 36 | }, 37 | { 38 | "_class": "org.cloudfoundry.samples.music.domain.Album", 39 | "artist": "The Beatles", 40 | "title": "Abbey Road", 41 | "releaseYear": "1969", 42 | "genre": "Rock" 43 | }, 44 | { 45 | "_class": "org.cloudfoundry.samples.music.domain.Album", 46 | "artist": "Fleetwood Mac", 47 | "title": "Rumours", 48 | "releaseYear": "1977", 49 | "genre": "Rock" 50 | }, 51 | { 52 | "_class": "org.cloudfoundry.samples.music.domain.Album", 53 | "artist": "Elvis Presley", 54 | "title": "Sun Sessions", 55 | "releaseYear": "1976", 56 | "genre": "Rock" 57 | }, 58 | { 59 | "_class": "org.cloudfoundry.samples.music.domain.Album", 60 | "artist": "Michael Jackson", 61 | "title": "Thriller", 62 | "releaseYear": "1982", 63 | "genre": "Pop" 64 | }, 65 | { 66 | "_class": "org.cloudfoundry.samples.music.domain.Album", 67 | "artist": "The Rolling Stones", 68 | "title": "Exile on Main Street", 69 | "releaseYear": "1972", 70 | "genre": "Rock" 71 | }, 72 | { 73 | "_class": "org.cloudfoundry.samples.music.domain.Album", 74 | "artist": "Bruce Springsteen", 75 | "title": "Born to Run", 76 | "releaseYear": "1975", 77 | "genre": "Rock" 78 | }, 79 | { 80 | "_class": "org.cloudfoundry.samples.music.domain.Album", 81 | "artist": "The Clash", 82 | "title": "London Calling", 83 | "releaseYear": "1980", 84 | "genre": "Rock" 85 | }, 86 | { 87 | "_class": "org.cloudfoundry.samples.music.domain.Album", 88 | "artist": "The Eagles", 89 | "title": "Hotel California", 90 | "releaseYear": "1976", 91 | "genre": "Rock" 92 | }, 93 | { 94 | "_class": "org.cloudfoundry.samples.music.domain.Album", 95 | "artist": "Led Zeppelin", 96 | "title": "Led Zeppelin", 97 | "releaseYear": "1969", 98 | "genre": "Rock" 99 | }, 100 | { 101 | "_class": "org.cloudfoundry.samples.music.domain.Album", 102 | "artist": "Led Zeppelin", 103 | "title": "IV", 104 | "releaseYear": "1971", 105 | "genre": "Rock" 106 | }, 107 | { 108 | "_class": "org.cloudfoundry.samples.music.domain.Album", 109 | "artist": "Police", 110 | "title": "Synchronicity", 111 | "releaseYear": "1983", 112 | "genre": "Rock" 113 | }, 114 | { 115 | "_class": "org.cloudfoundry.samples.music.domain.Album", 116 | "artist": "U2", 117 | "title": "Achtung Baby", 118 | "releaseYear": "1991", 119 | "genre": "Rock" 120 | }, 121 | { 122 | "_class": "org.cloudfoundry.samples.music.domain.Album", 123 | "artist": "The Rolling Stones", 124 | "title": "Let it Bleed", 125 | "releaseYear": "1969", 126 | "genre": "Rock" 127 | }, 128 | { 129 | "_class": "org.cloudfoundry.samples.music.domain.Album", 130 | "artist": "The Beatles", 131 | "title": "Rubber Soul", 132 | "releaseYear": "1965", 133 | "genre": "Rock" 134 | }, 135 | { 136 | "_class": "org.cloudfoundry.samples.music.domain.Album", 137 | "artist": "The Ramones", 138 | "title": "The Ramones", 139 | "releaseYear": "1976", 140 | "genre": "Rock" 141 | }, 142 | { 143 | "_class": "org.cloudfoundry.samples.music.domain.Album", 144 | "artist": "Queen", 145 | "title": "A Night At The Opera", 146 | "releaseYear": "1975", 147 | "genre": "Rock" 148 | }, 149 | { 150 | "_class": "org.cloudfoundry.samples.music.domain.Album", 151 | "artist": "Boston", 152 | "title": "Don't Look Back", 153 | "releaseYear": "1978", 154 | "genre": "Rock" 155 | }, 156 | { 157 | "_class": "org.cloudfoundry.samples.music.domain.Album", 158 | "artist": "BB King", 159 | "title": "Singin' The Blues", 160 | "releaseYear": "1956", 161 | "genre": "Blues" 162 | }, 163 | { 164 | "_class": "org.cloudfoundry.samples.music.domain.Album", 165 | "artist": "Albert King", 166 | "title": "Born Under A Bad Sign", 167 | "releaseYear": "1967", 168 | "genre": "Blues" 169 | }, 170 | { 171 | "_class": "org.cloudfoundry.samples.music.domain.Album", 172 | "artist": "Muddy Waters", 173 | "title": "Folk Singer", 174 | "releaseYear": "1964", 175 | "genre": "Blues" 176 | }, 177 | { 178 | "_class": "org.cloudfoundry.samples.music.domain.Album", 179 | "artist": "The Fabulous Thunderbirds", 180 | "title": "Rock With Me", 181 | "releaseYear": "1979", 182 | "genre": "Blues" 183 | }, 184 | { 185 | "_class": "org.cloudfoundry.samples.music.domain.Album", 186 | "artist": "Robert Johnson", 187 | "title": "King of the Delta Blues", 188 | "releaseYear": "1961", 189 | "genre": "Blues" 190 | }, 191 | { 192 | "_class": "org.cloudfoundry.samples.music.domain.Album", 193 | "artist": "Stevie Ray Vaughan", 194 | "title": "Texas Flood", 195 | "releaseYear": "1983", 196 | "genre": "Blues" 197 | }, 198 | { 199 | "_class": "org.cloudfoundry.samples.music.domain.Album", 200 | "artist": "Stevie Ray Vaughan", 201 | "title": "Couldn't Stand The Weather", 202 | "releaseYear": "1984", 203 | "genre": "Blues" 204 | } 205 | ] -------------------------------------------------------------------------------- /bin/log4j.properties: -------------------------------------------------------------------------------- 1 | # Direct log messages to stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.Target=System.out 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n 6 | 7 | # Root logger option 8 | log4j.rootLogger=INFO,stdout 9 | 10 | -------------------------------------------------------------------------------- /bin/messages.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenisha/vsts-terraform-ansible/fdb433aa3d8f17a1b0e411f09dd69fe05f37177c/bin/messages.properties -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | mavenCentral() 5 | maven { url "https://repo.spring.io/plugins-release" } 6 | } 7 | 8 | dependencies { 9 | classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.5' 10 | classpath("io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE") 11 | classpath("org.springframework.build.gradle:propdeps-plugin:0.0.7") 12 | } 13 | } 14 | 15 | apply plugin: 'java' 16 | 17 | apply plugin: 'eclipse-wtp' 18 | apply plugin: 'idea' 19 | 20 | apply plugin: 'tomcat' 21 | apply plugin: 'war' 22 | 23 | 24 | apply plugin: 'io.spring.dependency-management' 25 | apply plugin: 'propdeps' 26 | apply plugin: "propdeps-idea" 27 | 28 | version = '1.0' 29 | 30 | sourceSets { 31 | main { 32 | java { 33 | srcDir 'src/main/java' 34 | } 35 | resources { 36 | srcDir 'src/main/resources' 37 | srcDir 'src/main/java' 38 | } 39 | } 40 | } 41 | 42 | sourceCompatibility = 1.7 43 | targetCompatibility = 1.7 44 | archivesBaseName = "spring-music" 45 | 46 | jar { 47 | manifest { 48 | attributes 'Implementation-Title': 'Spring Sample Application', 'Implementation-Version': version 49 | } 50 | } 51 | 52 | repositories { 53 | mavenCentral() 54 | maven { url "http://repo.spring.io/milestone" } 55 | } 56 | 57 | dependencyManagement { 58 | imports { 59 | mavenBom 'io.spring.platform:platform-bom:2.0.0.RC1' 60 | } 61 | } 62 | 63 | dependencies { 64 | // Spring and dependencies 65 | compile "org.springframework:spring-context" 66 | compile "org.springframework:spring-webmvc" 67 | 68 | // Spring Cloud 69 | compile "org.springframework.cloud:spring-cloud-spring-service-connector" 70 | compile "org.springframework.cloud:spring-cloud-cloudfoundry-connector" 71 | 72 | // Spring Data 73 | compile "org.springframework.data:spring-data-jpa" 74 | compile "org.springframework.data:spring-data-redis" 75 | compile "org.springframework.data:spring-data-mongodb" 76 | 77 | // JPA Persistence 78 | compile "commons-dbcp:commons-dbcp" 79 | compile "org.hibernate:hibernate-entitymanager" 80 | runtime "com.h2database:h2" 81 | runtime "mysql:mysql-connector-java" 82 | runtime "postgresql:postgresql:9.1-901-1.jdbc4" 83 | 84 | // Redis Persistence 85 | compile "redis.clients:jedis" 86 | 87 | // JSR-303 validation 88 | compile "javax.validation:validation-api" 89 | compile "org.hibernate:hibernate-validator" 90 | 91 | // Webjars 92 | compile "org.webjars:bootstrap:3.1.1" 93 | compile "org.webjars:angularjs:1.2.16" 94 | compile "org.webjars:angular-ui:0.4.0-2" 95 | compile "org.webjars:angular-ui-bootstrap:0.10.0-1" 96 | compile "org.webjars:jquery:2.1.0-2" 97 | 98 | // Jackson 99 | compile "org.codehaus.jackson:jackson-core-asl:1.9.13" 100 | compile "org.codehaus.jackson:jackson-mapper-asl:1.9.13" 101 | compile "com.fasterxml.jackson.core:jackson-core" 102 | compile "com.fasterxml.jackson.core:jackson-databind" 103 | 104 | // Logging 105 | compile "org.slf4j:slf4j-api" 106 | compile "org.slf4j:slf4j-log4j12" 107 | 108 | // Servlet 109 | compile "javax.servlet:jstl:1.2" 110 | providedCompile 'javax.servlet:javax.servlet-api' 111 | 112 | // Testing 113 | testCompile "junit:junit" 114 | 115 | // Spring Testing 116 | testCompile "org.springframework:spring-test" 117 | 118 | // Tomcat 119 | tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}" 120 | tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}" 121 | tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") { 122 | exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj' 123 | } 124 | } 125 | 126 | task wrapper(type: Wrapper) { 127 | gradleVersion = '2.3' 128 | } 129 | 130 | war { 131 | // omit the version from the war file name 132 | version = "" 133 | } 134 | 135 | tomcatRun { 136 | outputFile = file('tomcat.log') 137 | } 138 | 139 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | tomcatVersion=7.0.54 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenisha/vsts-terraform-ansible/fdb433aa3d8f17a1b0e411f09dd69fe05f37177c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Apr 02 19:08:18 EDT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /iac/CICD-Flow.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenisha/vsts-terraform-ansible/fdb433aa3d8f17a1b0e411f09dd69fe05f37177c/iac/CICD-Flow.PNG -------------------------------------------------------------------------------- /iac/ansible/roles/selinux/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Download and install EPEL for Centos/RHEL version 6 3 | - name: Download EPEL Repo - Centos/RHEL 6 4 | get_url: url=http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm dest=/tmp/epel-release-latest-6.noarch.rpm 5 | when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '6'" 6 | 7 | - name: Install EPEL Repo - Centos/RHEL 6 8 | command: rpm -ivh /tmp/epel-release-latest-6.noarch.rpm creates=/etc/yum.repos.d/epel.repo 9 | when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '6'" 10 | 11 | # Download and install EPEL for Centos/RHEL version 7 12 | - name: Download EPEL Repo - Centos/RHEL 7 13 | get_url: url=http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm dest=/tmp/epel-release-latest-7.noarch.rpm 14 | when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7'" 15 | 16 | - name: Install EPEL Repo - Centos/RHEL 7 17 | command: rpm -ivh /tmp/epel-release-latest-7.noarch.rpm creates=/etc/yum.repos.d/epel.repo 18 | when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7'" 19 | 20 | - name: Install libselinux-python 21 | yum: name=libselinux-python 22 | -------------------------------------------------------------------------------- /iac/ansible/roles/tomcat/files/tomcat-initscript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # chkconfig: 345 99 28 4 | # description: Starts/Stops Apache Tomcat 5 | # 6 | # Tomcat 7 start/stop/status script 7 | # Forked from: https://gist.github.com/valotas/1000094 8 | # @author: Miglen Evlogiev 9 | # 10 | # Release updates: 11 | # Updated method for gathering pid of the current proccess 12 | # Added usage of CATALINA_BASE 13 | # Added coloring and additional status 14 | # Added check for existence of the tomcat user 15 | # 16 | 17 | #Location of JAVA_HOME (bin files) 18 | export JAVA_HOME=/usr/lib/jvm/jre 19 | 20 | #Add Java binary files to PATH 21 | export PATH=$JAVA_HOME/bin:$PATH 22 | 23 | #CATALINA_HOME is the location of the bin files of Tomcat 24 | export CATALINA_HOME=/usr/share/tomcat 25 | 26 | #CATALINA_BASE is the location of the configuration files of this instance of Tomcat 27 | export CATALINA_BASE=/usr/share/tomcat 28 | 29 | #TOMCAT_USER is the default user of tomcat 30 | export TOMCAT_USER=tomcat 31 | 32 | #TOMCAT_USAGE is the message if this script is called without any options 33 | TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}" 34 | 35 | #SHUTDOWN_WAIT is wait time in seconds for java proccess to stop 36 | SHUTDOWN_WAIT=20 37 | 38 | tomcat_pid() { 39 | echo `ps -fe | grep $CATALINA_BASE | grep -v grep | tr -s " "|cut -d" " -f2` 40 | } 41 | 42 | start() { 43 | pid=$(tomcat_pid) 44 | if [ -n "$pid" ] 45 | then 46 | echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m" 47 | else 48 | # Start tomcat 49 | echo -e "\e[00;32mStarting tomcat\e[00m" 50 | #ulimit -n 100000 51 | #umask 007 52 | #/bin/su -p -s /bin/sh tomcat 53 | if [ `user_exists $TOMCAT_USER` = "1" ] 54 | then 55 | su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh 56 | else 57 | sh $CATALINA_HOME/bin/startup.sh 58 | fi 59 | status 60 | fi 61 | return 0 62 | } 63 | 64 | status(){ 65 | pid=$(tomcat_pid) 66 | if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m" 67 | else echo -e "\e[00;31mTomcat is not running\e[00m" 68 | fi 69 | } 70 | 71 | stop() { 72 | pid=$(tomcat_pid) 73 | if [ -n "$pid" ] 74 | then 75 | echo -e "\e[00;31mStoping Tomcat\e[00m" 76 | #/bin/su -p -s /bin/sh tomcat 77 | sh $CATALINA_HOME/bin/shutdown.sh 78 | 79 | let kwait=$SHUTDOWN_WAIT 80 | count=0; 81 | until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ] 82 | do 83 | echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m"; 84 | sleep 1 85 | let count=$count+1; 86 | done 87 | 88 | if [ $count -gt $kwait ]; then 89 | echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m" 90 | kill -9 $pid 91 | fi 92 | else 93 | echo -e "\e[00;31mTomcat is not running\e[00m" 94 | fi 95 | 96 | return 0 97 | } 98 | 99 | user_exists(){ 100 | if id -u $1 >/dev/null 2>&1; then 101 | echo "1" 102 | else 103 | echo "0" 104 | fi 105 | } 106 | 107 | case $1 in 108 | 109 | start) 110 | start 111 | ;; 112 | 113 | stop) 114 | stop 115 | ;; 116 | 117 | restart) 118 | stop 119 | start 120 | ;; 121 | 122 | status) 123 | status 124 | 125 | ;; 126 | 127 | *) 128 | echo -e $TOMCAT_USAGE 129 | ;; 130 | esac 131 | exit 0 132 | -------------------------------------------------------------------------------- /iac/ansible/roles/tomcat/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart tomcat 3 | service: name=tomcat state=restarted 4 | 5 | - name: restart iptables 6 | service: name=iptables state=restarted 7 | -------------------------------------------------------------------------------- /iac/ansible/roles/tomcat/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install Java 1.7 3 | yum: name=java-1.7.0-openjdk state=present 4 | 5 | - name: add group "tomcat" 6 | group: name=tomcat 7 | 8 | - name: add user "tomcat" 9 | user: name=tomcat group=tomcat home=/usr/share/tomcat createhome=no 10 | become: True 11 | become_method: sudo 12 | 13 | - name: Download Tomcat 14 | get_url: url=http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61.tar.gz dest=/opt/apache-tomcat-7.0.61.tar.gz 15 | 16 | - name: Extract archive 17 | command: chdir=/usr/share /bin/tar xvf /opt/apache-tomcat-7.0.61.tar.gz -C /opt/ creates=/opt/apache-tomcat-7.0.61 18 | 19 | - name: Symlink install directory 20 | file: src=/opt/apache-tomcat-7.0.61 path=/usr/share/tomcat state=link 21 | 22 | - name: Change ownership of Tomcat installation 23 | file: path=/usr/share/tomcat/ owner=tomcat group=tomcat state=directory recurse=yes 24 | 25 | - name: Configure Tomcat server 26 | template: src=server.xml dest=/usr/share/tomcat/conf/ 27 | notify: restart tomcat 28 | 29 | - name: Configure Tomcat users 30 | template: src=tomcat-users.xml dest=/usr/share/tomcat/conf/ 31 | notify: restart tomcat 32 | 33 | - name: Install Tomcat init script 34 | copy: src=tomcat-initscript.sh dest=/etc/init.d/tomcat mode=0755 35 | 36 | - name: Start Tomcat 37 | service: name=tomcat state=started enabled=yes 38 | 39 | - name: deploy iptables rules 40 | template: src=iptables-save dest=/etc/sysconfig/iptables 41 | when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '6'" 42 | notify: restart iptables 43 | 44 | - name: insert firewalld rule for tomcat http port 45 | firewalld: port={{ http_port }}/tcp permanent=true state=enabled immediate=yes 46 | when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7'" 47 | 48 | - name: insert firewalld rule for tomcat https port 49 | firewalld: port={{ https_port }}/tcp permanent=true state=enabled immediate=yes 50 | when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7'" 51 | 52 | - name: wait for tomcat to start 53 | wait_for: port={{http_port}} 54 | 55 | - name: unDeploy sample app 56 | file: path=/usr/share/tomcat/webapps/spring-music.war owner=tomcat group=tomcat state=absent 57 | 58 | - name: wait for tomcat to undeploy the app 59 | wait_for: path=/usr/share/tomcat/webapps/spring-music/ state=absent 60 | 61 | - name: Deploy sample app 62 | copy: src=../../build/libs/spring-music.war dest=/usr/share/tomcat/webapps/spring-music.war owner=tomcat group=tomcat 63 | notify: restart tomcat 64 | 65 | - name: Start Tomcat 66 | service: name=tomcat state=started enabled=yes 67 | -------------------------------------------------------------------------------- /iac/ansible/roles/tomcat/templates/iptables-save: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | *filter 3 | :INPUT ACCEPT [0:0] 4 | :FORWARD ACCEPT [0:0] 5 | :OUTPUT ACCEPT [4:512] 6 | -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 7 | -A INPUT -p icmp -j ACCEPT 8 | -A INPUT -i lo -j ACCEPT 9 | -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 10 | -A INPUT -p tcp -m state --state NEW -m tcp --dport {{ http_port }} -j ACCEPT 11 | -A INPUT -p tcp -m state --state NEW -m tcp --dport {{ https_port }} -j ACCEPT 12 | -A INPUT -j REJECT --reject-with icmp-host-prohibited 13 | -A FORWARD -j REJECT --reject-with icmp-host-prohibited 14 | COMMIT 15 | -------------------------------------------------------------------------------- /iac/ansible/roles/tomcat/templates/server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 45 | 50 | 51 | 52 | 57 | 58 | 59 | 60 | 64 | 65 | 66 | 73 | 76 | 77 | 83 | 87 | 92 | 93 | 94 | 95 | 96 | 97 | 102 | 103 | 106 | 107 | 108 | 111 | 114 | 115 | 117 | 118 | 122 | 124 | 125 | 126 | 128 | 129 | 131 | 134 | 135 | 138 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /iac/ansible/roles/tomcat/templates/tomcat-users.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | 27 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /iac/ansible/site.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # This playbook deploys a simple standalone Tomcat 7 server. 4 | 5 | - hosts: all 6 | become: true 7 | become_method: sudo 8 | vars: 9 | http_port: 8080 10 | https_port: 8443 11 | admin_username: admin 12 | admin_password: adminsecret 13 | roles: 14 | - selinux 15 | - tomcat -------------------------------------------------------------------------------- /iac/terraform/apply.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "************* execute terraform apply" 3 | ## execute terrafotm build and sendout to packer-build-output 4 | export ARM_CLIENT_ID=$1 5 | export ARM_CLIENT_SECRET=$2 6 | export ARM_SUBSCRIPTION_ID=$3 7 | export ARM_TENANT_ID=$4 8 | export ARM_ACCESS_KEY=$5 9 | export SSH_PUB_KEY=$6 10 | 11 | terraform apply -auto-approve -var ssh_key=$6 12 | 13 | export vmss_ip=$(terraform output vm_ip) 14 | echo "host1 ansible_ssh_port=50001 ansible_ssh_host=$vmss_ip" > inventory 15 | echo "host2 ansible_port=50002 ansible_ssh_host=$vmss_ip" >> inventory 16 | 17 | cat inventory 18 | -------------------------------------------------------------------------------- /iac/terraform/azure/backend.tfvars: -------------------------------------------------------------------------------- 1 | storage_account_name = "vstsbuildterraform" 2 | 3 | container_name = "terraform-state" 4 | 5 | key = "demo-java.terraform.tfstate" 6 | -------------------------------------------------------------------------------- /iac/terraform/azure/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.11" 3 | 4 | backend "azurerm" {} 5 | } 6 | 7 | # Configure the Microsoft Azure Provider 8 | provider "azurerm" {} 9 | 10 | # Create a resource group if it doesn’t exist 11 | resource "azurerm_resource_group" "rg" { 12 | name = "javademo" 13 | location = "eastus" 14 | 15 | tags { 16 | environment = "Terraform Demo" 17 | } 18 | } 19 | 20 | resource "azurerm_storage_account" "stor" { 21 | name = "${var.dns_name}stor" 22 | location = "${azurerm_resource_group.rg.location}" 23 | resource_group_name = "${azurerm_resource_group.rg.name}" 24 | account_tier = "${var.storage_account_tier}" 25 | account_replication_type = "${var.storage_replication_type}" 26 | } 27 | 28 | resource "azurerm_availability_set" "avset" { 29 | name = "${var.dns_name}avset" 30 | location = "${azurerm_resource_group.rg.location}" 31 | resource_group_name = "${azurerm_resource_group.rg.name}" 32 | platform_fault_domain_count = 2 33 | platform_update_domain_count = 2 34 | managed = true 35 | } 36 | 37 | resource "azurerm_public_ip" "lbpip" { 38 | name = "${var.lb_ip_dns_name}-ip" 39 | location = "${azurerm_resource_group.rg.location}" 40 | resource_group_name = "${azurerm_resource_group.rg.name}" 41 | public_ip_address_allocation = "dynamic" 42 | domain_name_label = "${var.lb_ip_dns_name}" 43 | } 44 | 45 | resource "azurerm_virtual_network" "vnet" { 46 | name = "${var.virtual_network_name}" 47 | location = "${azurerm_resource_group.rg.location}" 48 | address_space = ["${var.address_space}"] 49 | resource_group_name = "${azurerm_resource_group.rg.name}" 50 | } 51 | 52 | resource "azurerm_subnet" "subnet" { 53 | name = "${var.rg_prefix}subnet" 54 | virtual_network_name = "${azurerm_virtual_network.vnet.name}" 55 | resource_group_name = "${azurerm_resource_group.rg.name}" 56 | address_prefix = "${var.subnet_prefix}" 57 | } 58 | 59 | resource "azurerm_lb" "lb" { 60 | resource_group_name = "${azurerm_resource_group.rg.name}" 61 | name = "${var.rg_prefix}lb" 62 | location = "${azurerm_resource_group.rg.location}" 63 | 64 | frontend_ip_configuration { 65 | name = "LoadBalancerFrontEnd" 66 | public_ip_address_id = "${azurerm_public_ip.lbpip.id}" 67 | } 68 | } 69 | 70 | resource "azurerm_lb_backend_address_pool" "backend_pool" { 71 | resource_group_name = "${azurerm_resource_group.rg.name}" 72 | loadbalancer_id = "${azurerm_lb.lb.id}" 73 | name = "BackendPool1" 74 | } 75 | 76 | resource "azurerm_lb_nat_rule" "tcp" { 77 | resource_group_name = "${azurerm_resource_group.rg.name}" 78 | loadbalancer_id = "${azurerm_lb.lb.id}" 79 | name = "SSH-VM-${count.index}" 80 | protocol = "tcp" 81 | frontend_port = "5000${count.index + 1}" 82 | backend_port = 22 83 | frontend_ip_configuration_name = "LoadBalancerFrontEnd" 84 | count = 2 85 | } 86 | 87 | resource "azurerm_lb_rule" "lb_rule" { 88 | resource_group_name = "${azurerm_resource_group.rg.name}" 89 | loadbalancer_id = "${azurerm_lb.lb.id}" 90 | name = "LBRule" 91 | protocol = "tcp" 92 | frontend_port = 80 93 | backend_port = 8080 94 | frontend_ip_configuration_name = "LoadBalancerFrontEnd" 95 | enable_floating_ip = false 96 | backend_address_pool_id = "${azurerm_lb_backend_address_pool.backend_pool.id}" 97 | idle_timeout_in_minutes = 5 98 | probe_id = "${azurerm_lb_probe.lb_probe.id}" 99 | depends_on = ["azurerm_lb_probe.lb_probe"] 100 | } 101 | 102 | resource "azurerm_lb_probe" "lb_probe" { 103 | resource_group_name = "${azurerm_resource_group.rg.name}" 104 | loadbalancer_id = "${azurerm_lb.lb.id}" 105 | name = "tcpProbe" 106 | protocol = "tcp" 107 | port = 8080 108 | interval_in_seconds = 5 109 | number_of_probes = 2 110 | } 111 | 112 | resource "azurerm_network_interface" "nic" { 113 | name = "nic${count.index}" 114 | location = "${azurerm_resource_group.rg.location}" 115 | resource_group_name = "${azurerm_resource_group.rg.name}" 116 | count = 2 117 | 118 | ip_configuration { 119 | name = "ipconfig${count.index}" 120 | subnet_id = "${azurerm_subnet.subnet.id}" 121 | private_ip_address_allocation = "Dynamic" 122 | load_balancer_backend_address_pools_ids = ["${azurerm_lb_backend_address_pool.backend_pool.id}"] 123 | load_balancer_inbound_nat_rules_ids = ["${element(azurerm_lb_nat_rule.tcp.*.id, count.index)}"] 124 | } 125 | } 126 | 127 | # Create virtual machine 128 | resource "azurerm_virtual_machine" "vm" { 129 | name = "vm${count.index}" 130 | location = "${azurerm_resource_group.rg.location}" 131 | resource_group_name = "${azurerm_resource_group.rg.name}" 132 | availability_set_id = "${azurerm_availability_set.avset.id}" 133 | network_interface_ids = ["${element(azurerm_network_interface.nic.*.id, count.index)}"] 134 | count = 2 135 | vm_size = "Standard_D1" 136 | 137 | storage_os_disk { 138 | name = "osdisk${count.index}" 139 | create_option = "FromImage" 140 | } 141 | 142 | storage_image_reference { 143 | publisher = "RedHat" 144 | offer = "RHEL" 145 | sku = "7.3" 146 | version = "latest" 147 | } 148 | 149 | os_profile { 150 | computer_name = "myvm" 151 | admin_username = "azureuser" 152 | admin_password = "Passwword1234" 153 | } 154 | 155 | os_profile_linux_config { 156 | disable_password_authentication = true 157 | 158 | ssh_keys { 159 | path = "/home/azureuser/.ssh/authorized_keys" 160 | key_data = "${var.ssh_key}" 161 | } 162 | } 163 | 164 | tags { 165 | environment = "Terraform Demo" 166 | } 167 | } 168 | 169 | output "vm_ip" { 170 | value = "${azurerm_public_ip.lbpip.fqdn}" 171 | } 172 | 173 | output "vm_dns" { 174 | value = "http://${azurerm_public_ip.lbpip.fqdn}" 175 | } 176 | -------------------------------------------------------------------------------- /iac/terraform/azure/variables.tf: -------------------------------------------------------------------------------- 1 | variable "storage-account-name" { 2 | default = "vstsbuildterraform" 3 | } 4 | 5 | variable "container-name" { 6 | default = "terraform-state" 7 | } 8 | 9 | variable "rg_prefix" { 10 | description = "The shortened abbreviation to represent your resource group that will go on the front of some resources." 11 | default = "rg" 12 | } 13 | 14 | variable "dns_name" { 15 | description = " Label for the Domain Name. Will be used to make up the FQDN." 16 | default = "demojavaiac" 17 | } 18 | 19 | variable "lb_ip_dns_name" { 20 | description = "DNS for Load Balancer IP" 21 | default = "demojavaiac" 22 | } 23 | 24 | variable "location" { 25 | description = "The location/region where the virtual network is created. Changing this forces a new resource to be created." 26 | default = "eastus" 27 | } 28 | 29 | variable "virtual_network_name" { 30 | description = "The name for the virtual network." 31 | default = "vnet" 32 | } 33 | 34 | variable "address_space" { 35 | description = "The address space that is used by the virtual network. You can supply more than one address space. Changing this forces a new resource to be created." 36 | default = "10.0.0.0/16" 37 | } 38 | 39 | variable "subnet_prefix" { 40 | description = "The address prefix to use for the subnet." 41 | default = "10.0.10.0/24" 42 | } 43 | 44 | variable "storage_account_tier" { 45 | description = "Defines the Tier of storage account to be created. Valid options are Standard and Premium." 46 | default = "Standard" 47 | } 48 | 49 | variable "storage_replication_type" { 50 | description = "Defines the Replication Type to use for this storage account. Valid options include LRS, GRS etc." 51 | default = "LRS" 52 | } 53 | 54 | variable "vm_size" { 55 | description = "Specifies the size of the virtual machine." 56 | default = "Standard_D1" 57 | } 58 | -------------------------------------------------------------------------------- /iac/terraform/graph.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la 3 | echo "************* execute terraform graph" 4 | ## execute terrafotm build and sendout to packer-build-output 5 | 6 | terraform graph | dot -Tsvg > graph.svg -------------------------------------------------------------------------------- /iac/terraform/init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "************* execute terraform init" 3 | ## execute terrafotm build and sendout to packer-build-output 4 | export ARM_CLIENT_ID=$1 5 | export ARM_CLIENT_SECRET=$2 6 | export ARM_SUBSCRIPTION_ID=$3 7 | export ARM_TENANT_ID=$4 8 | export ARM_ACCESS_KEY=$5 9 | echo "Run" 10 | terraform init -backend-config=backend.tfvars -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: spring-music 4 | memory: 512M 5 | instances: 1 6 | random-route: true 7 | path: build/libs/spring-music.war 8 | 9 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/AppInitializer.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config; 2 | 3 | import org.cloudfoundry.samples.music.config.root.RepositoryConfig; 4 | import org.cloudfoundry.samples.music.config.web.WebMvcConfig; 5 | import org.springframework.util.StringUtils; 6 | import org.springframework.web.WebApplicationInitializer; 7 | import org.springframework.web.context.ContextLoader; 8 | import org.springframework.web.context.ContextLoaderListener; 9 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 10 | import org.springframework.web.servlet.DispatcherServlet; 11 | 12 | import javax.servlet.ServletContext; 13 | import javax.servlet.ServletException; 14 | import javax.servlet.ServletRegistration; 15 | 16 | public class AppInitializer implements WebApplicationInitializer { 17 | 18 | @Override 19 | public void onStartup(ServletContext container) throws ServletException { 20 | configureAppContextInitializers(container, SpringApplicationContextInitializer.class.getName()); 21 | createRootAppContext(container, RepositoryConfig.class); 22 | createDispatcherServlet(container, WebMvcConfig.class); 23 | } 24 | 25 | private void configureAppContextInitializers(ServletContext container, String... initClassNames) { 26 | String initializerClasses = container.getInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM); 27 | 28 | String delimitedClassNames = StringUtils.arrayToDelimitedString(initClassNames, " "); 29 | 30 | if (StringUtils.hasText(initializerClasses)) { 31 | initializerClasses += " " + delimitedClassNames; 32 | } 33 | else { 34 | initializerClasses = delimitedClassNames; 35 | } 36 | 37 | container.setInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, initializerClasses); 38 | } 39 | 40 | private void createRootAppContext(ServletContext container, java.lang.Class... configClasses) { 41 | AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); 42 | rootContext.register(configClasses); 43 | container.addListener(new ContextLoaderListener(rootContext)); 44 | } 45 | 46 | private void createDispatcherServlet(ServletContext container, java.lang.Class... configClasses) { 47 | AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext(); 48 | webContext.register(configClasses); 49 | 50 | DispatcherServlet dispatcherServlet = new DispatcherServlet(webContext); 51 | ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", dispatcherServlet); 52 | dispatcher.setLoadOnStartup(1); 53 | dispatcher.addMapping("/"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/SpringApplicationContextInitializer.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | import org.springframework.cloud.Cloud; 6 | import org.springframework.cloud.CloudException; 7 | import org.springframework.cloud.CloudFactory; 8 | import org.springframework.cloud.service.ServiceInfo; 9 | import org.springframework.cloud.service.common.MongoServiceInfo; 10 | import org.springframework.cloud.service.common.MysqlServiceInfo; 11 | import org.springframework.cloud.service.common.OracleServiceInfo; 12 | import org.springframework.cloud.service.common.PostgresqlServiceInfo; 13 | import org.springframework.cloud.service.common.RedisServiceInfo; 14 | import org.springframework.context.ApplicationContextInitializer; 15 | import org.springframework.core.env.ConfigurableEnvironment; 16 | import org.springframework.util.StringUtils; 17 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 18 | 19 | import java.util.*; 20 | 21 | public class SpringApplicationContextInitializer implements ApplicationContextInitializer { 22 | 23 | private static final Log logger = LogFactory.getLog(SpringApplicationContextInitializer.class); 24 | 25 | private static final Map, String> serviceTypeToProfileName = 26 | new HashMap, String>(); 27 | private static final List validLocalProfiles = Arrays.asList("mysql", "postgres", "mongodb", "redis"); 28 | 29 | public static final String IN_MEMORY_PROFILE = "in-memory"; 30 | 31 | static { 32 | serviceTypeToProfileName.put(MongoServiceInfo.class, "mongodb"); 33 | serviceTypeToProfileName.put(PostgresqlServiceInfo.class, "postgres"); 34 | serviceTypeToProfileName.put(MysqlServiceInfo.class, "mysql"); 35 | serviceTypeToProfileName.put(RedisServiceInfo.class, "redis"); 36 | serviceTypeToProfileName.put(OracleServiceInfo.class, "oracle"); 37 | } 38 | 39 | @Override 40 | public void initialize(AnnotationConfigWebApplicationContext applicationContext) { 41 | Cloud cloud = getCloud(); 42 | 43 | ConfigurableEnvironment appEnvironment = applicationContext.getEnvironment(); 44 | 45 | String[] persistenceProfiles = getCloudProfile(cloud); 46 | if (persistenceProfiles == null) { 47 | persistenceProfiles = getActiveProfile(appEnvironment); 48 | } 49 | if (persistenceProfiles == null) { 50 | persistenceProfiles = new String[] { IN_MEMORY_PROFILE }; 51 | } 52 | 53 | for (String persistenceProfile : persistenceProfiles) { 54 | appEnvironment.addActiveProfile(persistenceProfile); 55 | } 56 | } 57 | 58 | public String[] getCloudProfile(Cloud cloud) { 59 | if (cloud == null) { 60 | return null; 61 | } 62 | 63 | List profiles = new ArrayList(); 64 | 65 | List serviceInfos = cloud.getServiceInfos(); 66 | 67 | logger.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos)); 68 | 69 | for (ServiceInfo serviceInfo : serviceInfos) { 70 | if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) { 71 | profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass())); 72 | } 73 | } 74 | 75 | if (profiles.size() > 1) { 76 | throw new IllegalStateException( 77 | "Only one service of the following types may be bound to this application: " + 78 | serviceTypeToProfileName.values().toString() + ". " + 79 | "These services are bound to the application: [" + 80 | StringUtils.collectionToCommaDelimitedString(profiles) + "]"); 81 | } 82 | 83 | if (profiles.size() > 0) { 84 | return createProfileNames(profiles.get(0), "cloud"); 85 | } 86 | 87 | return null; 88 | } 89 | 90 | private Cloud getCloud() { 91 | try { 92 | CloudFactory cloudFactory = new CloudFactory(); 93 | return cloudFactory.getCloud(); 94 | } catch (CloudException ce) { 95 | return null; 96 | } 97 | } 98 | 99 | private String[] getActiveProfile(ConfigurableEnvironment appEnvironment) { 100 | List serviceProfiles = new ArrayList(); 101 | 102 | for (String profile : appEnvironment.getActiveProfiles()) { 103 | if (validLocalProfiles.contains(profile)) { 104 | serviceProfiles.add(profile); 105 | } 106 | } 107 | 108 | if (serviceProfiles.size() > 1) { 109 | throw new IllegalStateException("Only one active Spring profile may be set among the following: " + 110 | validLocalProfiles.toString() + ". " + 111 | "These profiles are active: [" + 112 | StringUtils.collectionToCommaDelimitedString(serviceProfiles) + "]"); 113 | } 114 | 115 | if (serviceProfiles.size() > 0) { 116 | return createProfileNames(serviceProfiles.get(0), "local"); 117 | } 118 | 119 | return null; 120 | } 121 | 122 | private String[] createProfileNames(String baseName, String suffix) { 123 | String[] profileNames = {baseName, baseName + "-" + suffix}; 124 | logger.info("Setting profile names: " + StringUtils.arrayToCommaDelimitedString(profileNames)); 125 | return profileNames; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/AbstractJpaRepositoryConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.cloudfoundry.samples.music.domain.Album; 4 | import org.hibernate.ejb.HibernatePersistence; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.orm.jpa.JpaTransactionManager; 7 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; 8 | 9 | import javax.persistence.EntityManagerFactory; 10 | import javax.sql.DataSource; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public abstract class AbstractJpaRepositoryConfig { 15 | 16 | @Bean(name = "entityManagerFactory") 17 | public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { 18 | return createEntityManagerFactoryBean(dataSource, getHibernateDialect()); 19 | } 20 | 21 | @Bean(name = "transactionManager") 22 | public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { 23 | return new JpaTransactionManager(entityManagerFactory); 24 | } 25 | 26 | protected abstract String getHibernateDialect(); 27 | 28 | protected LocalContainerEntityManagerFactoryBean createEntityManagerFactoryBean(DataSource dataSource, String dialectClassName) { 29 | Map properties = new HashMap(); 30 | properties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, "update"); 31 | properties.put(org.hibernate.cfg.Environment.DIALECT, dialectClassName); 32 | properties.put(org.hibernate.cfg.Environment.SHOW_SQL, "true"); 33 | 34 | LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); 35 | em.setDataSource(dataSource); 36 | em.setPackagesToScan(Album.class.getPackage().getName()); 37 | em.setPersistenceProvider(new HibernatePersistence()); 38 | em.setJpaPropertyMap(properties); 39 | return em; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/AbstractLocalDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.apache.commons.dbcp.BasicDataSource; 4 | 5 | public class AbstractLocalDataSourceConfig { 6 | 7 | protected BasicDataSource createBasicDataSource(String jdbcUrl, String driverClass, String userName, String password) { 8 | BasicDataSource dataSource = new BasicDataSource(); 9 | dataSource.setUrl(jdbcUrl); 10 | dataSource.setDriverClassName(driverClass); 11 | dataSource.setUsername(userName); 12 | dataSource.setPassword(password); 13 | return dataSource; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/H2DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | import javax.sql.DataSource; 11 | 12 | @Configuration 13 | @Profile("in-memory") 14 | @EnableJpaRepositories("org.cloudfoundry.samples.music.repositories.jpa") 15 | public class H2DataSourceConfig extends AbstractLocalDataSourceConfig { 16 | @Bean 17 | public DataSource dataSource() { 18 | return new EmbeddedDatabaseBuilder() 19 | .setName("music") 20 | .setType(EmbeddedDatabaseType.H2) 21 | .build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/LocalJpaRepositoryConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.hibernate.dialect.H2Dialect; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | @Configuration 9 | @Profile("in-memory") 10 | @EnableJpaRepositories("org.cloudfoundry.samples.music.repositories.jpa") 11 | public class LocalJpaRepositoryConfig extends AbstractJpaRepositoryConfig { 12 | 13 | protected String getHibernateDialect() { 14 | return H2Dialect.class.getName(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/MongoCloudConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.springframework.cloud.config.java.AbstractCloudConfig; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | import org.springframework.data.mongodb.MongoDbFactory; 8 | 9 | @Configuration 10 | @Profile("mongodb-cloud") 11 | public class MongoCloudConfig extends AbstractCloudConfig { 12 | 13 | @Bean 14 | public MongoDbFactory mongoDbFactory() { 15 | return connectionFactory().mongoDbFactory(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/MongoConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.cloudfoundry.samples.music.repositories.mongodb.MongoAlbumRepository; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | import org.springframework.data.mongodb.MongoDbFactory; 8 | import org.springframework.data.mongodb.core.MongoTemplate; 9 | import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; 10 | 11 | @Configuration 12 | @Profile("mongodb") 13 | @EnableMongoRepositories(basePackageClasses = {MongoAlbumRepository.class}) 14 | public class MongoConfig { 15 | 16 | @Bean 17 | public MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory) { 18 | return new MongoTemplate(mongoDbFactory); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/MongoLocalConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import com.mongodb.MongoClient; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | import org.springframework.data.mongodb.MongoDbFactory; 8 | import org.springframework.data.mongodb.core.SimpleMongoDbFactory; 9 | 10 | import java.net.UnknownHostException; 11 | 12 | @Configuration 13 | @Profile("mongodb-local") 14 | public class MongoLocalConfig { 15 | 16 | @Bean 17 | public MongoDbFactory mongoDbFactory() { 18 | try { 19 | return new SimpleMongoDbFactory(new MongoClient(), "music"); 20 | } catch (UnknownHostException e) { 21 | throw new RuntimeException("Error creating MongoDbFactory: " + e); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/MySqlLocalDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | import javax.sql.DataSource; 8 | 9 | @Configuration 10 | @Profile("mysql-local") 11 | public class MySqlLocalDataSourceConfig extends AbstractLocalDataSourceConfig { 12 | 13 | @Bean 14 | public DataSource dataSource() { 15 | return createBasicDataSource("jdbc:mysql://localhost/music", "com.mysql.jdbc.Driver", "", ""); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/MySqlRepositoryConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.hibernate.dialect.MySQL5Dialect; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | @Configuration 9 | @Profile("mysql") 10 | @EnableJpaRepositories("org.cloudfoundry.samples.music.repositories.jpa") 11 | public class MySqlRepositoryConfig extends AbstractJpaRepositoryConfig { 12 | 13 | protected String getHibernateDialect() { 14 | return MySQL5Dialect.class.getName(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/OracleRepositoryConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.hibernate.dialect.Oracle10gDialect; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | @Configuration 9 | @Profile("oracle") 10 | @EnableJpaRepositories("org.cloudfoundry.samples.music.repositories.jpa") 11 | public class OracleRepositoryConfig extends AbstractJpaRepositoryConfig { 12 | 13 | protected String getHibernateDialect() { 14 | return Oracle10gDialect.class.getName(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/PostgresLocalDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | import javax.sql.DataSource; 8 | 9 | @Configuration 10 | @Profile("postgres-local") 11 | public class PostgresLocalDataSourceConfig extends AbstractLocalDataSourceConfig { 12 | 13 | @Bean 14 | public DataSource dataSource() { 15 | return createBasicDataSource("jdbc:postgresql://localhost/music", 16 | "org.postgresql.Driver", "postgres", "postgres"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/PostgresRepositoryConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.hibernate.dialect.PostgreSQL82Dialect; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | @Configuration 9 | @Profile("postgres") 10 | @EnableJpaRepositories("org.cloudfoundry.samples.music.repositories.jpa") 11 | public class PostgresRepositoryConfig extends AbstractJpaRepositoryConfig { 12 | 13 | protected String getHibernateDialect() { 14 | return PostgreSQL82Dialect.class.getName(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/RedisCloudConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.springframework.cloud.config.java.AbstractCloudConfig; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | import org.springframework.data.redis.connection.RedisConnectionFactory; 8 | 9 | @Configuration 10 | @Profile("redis-cloud") 11 | public class RedisCloudConfig extends AbstractCloudConfig { 12 | 13 | @Bean 14 | public RedisConnectionFactory redisConnection() { 15 | return connectionFactory().redisConnectionFactory(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.cloudfoundry.samples.music.domain.Album; 4 | import org.cloudfoundry.samples.music.repositories.redis.RedisAlbumRepository; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.annotation.Profile; 8 | import org.springframework.data.redis.connection.RedisConnectionFactory; 9 | import org.springframework.data.redis.core.RedisTemplate; 10 | import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer; 11 | import org.springframework.data.redis.serializer.RedisSerializer; 12 | import org.springframework.data.redis.serializer.StringRedisSerializer; 13 | 14 | @Configuration 15 | @Profile("redis") 16 | public class RedisConfig { 17 | 18 | @Bean 19 | public RedisAlbumRepository redisRepository(RedisTemplate redisTemplate) { 20 | return new RedisAlbumRepository(redisTemplate); 21 | } 22 | 23 | @Bean 24 | public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { 25 | RedisTemplate template = new RedisTemplate(); 26 | 27 | template.setConnectionFactory(redisConnectionFactory); 28 | 29 | RedisSerializer stringSerializer = new StringRedisSerializer(); 30 | RedisSerializer albumSerializer = new JacksonJsonRedisSerializer(Album.class); 31 | 32 | template.setKeySerializer(stringSerializer); 33 | template.setValueSerializer(albumSerializer); 34 | template.setHashKeySerializer(stringSerializer); 35 | template.setHashValueSerializer(albumSerializer); 36 | 37 | return template; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/RedisLocalConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import org.springframework.data.redis.connection.RedisConnectionFactory; 7 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; 8 | 9 | @Configuration 10 | @Profile("redis-local") 11 | public class RedisLocalConfig { 12 | 13 | @Bean 14 | public RedisConnectionFactory redisConnection() { 15 | return new JedisConnectionFactory(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/data/RelationalCloudDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.data; 2 | 3 | import org.springframework.cloud.config.java.AbstractCloudConfig; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | 8 | import javax.sql.DataSource; 9 | 10 | @Configuration 11 | @Profile({"mysql-cloud", "postgres-cloud", "oracle-cloud"}) 12 | public class RelationalCloudDataSourceConfig extends AbstractCloudConfig { 13 | 14 | @Bean 15 | public DataSource dataSource() { 16 | return connectionFactory().dataSource(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/root/RepositoryConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.root; 2 | 3 | import org.cloudfoundry.samples.music.config.data.LocalJpaRepositoryConfig; 4 | import org.cloudfoundry.samples.music.repositories.AlbumRepository; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | @ComponentScan(basePackageClasses = {AlbumRepository.class, LocalJpaRepositoryConfig.class}) 10 | public class RepositoryConfig { 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/config/web/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.config.web; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.*; 7 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 8 | import org.cloudfoundry.samples.music.web.controllers.AlbumController; 9 | 10 | @Configuration 11 | @EnableWebMvc 12 | @ComponentScan(basePackageClasses = {AlbumController.class}) 13 | public class WebMvcConfig extends WebMvcConfigurerAdapter { 14 | 15 | @Bean 16 | public InternalResourceViewResolver internalResourceViewResolver() { 17 | InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver(); 18 | internalResourceViewResolver.setPrefix("/WEB-INF/"); 19 | internalResourceViewResolver.setSuffix(".html"); 20 | return internalResourceViewResolver; 21 | } 22 | 23 | @Override 24 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 25 | registry.addResourceHandler("/assets/**").addResourceLocations("/assets/"); 26 | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); 27 | } 28 | 29 | @Override 30 | public void addViewControllers(ViewControllerRegistry registry) { 31 | registry.addViewController("/").setViewName("index"); 32 | } 33 | 34 | @Override 35 | public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { 36 | configurer.enable(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/domain/Album.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.domain; 2 | 3 | import org.hibernate.annotations.GenericGenerator; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | 10 | @Entity 11 | public class Album { 12 | @Id 13 | @Column(length=40) 14 | @GeneratedValue(generator="randomId") 15 | @GenericGenerator(name="randomId", strategy="org.cloudfoundry.samples.music.domain.RandomIdGenerator") 16 | private String id; 17 | 18 | private String title; 19 | private String artist; 20 | private String releaseYear; 21 | private String genre; 22 | private int trackCount; 23 | private String albumId; 24 | 25 | public Album() { 26 | } 27 | 28 | public Album(String title, String artist, String releaseYear, String genre) { 29 | this.title = title; 30 | this.artist = artist; 31 | this.releaseYear = releaseYear; 32 | this.genre = genre; 33 | } 34 | 35 | public String getId() { 36 | return id; 37 | } 38 | 39 | public void setId(String id) { 40 | this.id = id; 41 | } 42 | 43 | public String getTitle() { 44 | return title; 45 | } 46 | 47 | public void setTitle(String title) { 48 | this.title = title; 49 | } 50 | 51 | public String getArtist() { 52 | return artist; 53 | } 54 | 55 | public void setArtist(String artist) { 56 | this.artist = artist; 57 | } 58 | 59 | public String getReleaseYear() { 60 | return releaseYear; 61 | } 62 | 63 | public void setReleaseYear(String releaseYear) { 64 | this.releaseYear = releaseYear; 65 | } 66 | 67 | public String getGenre() { 68 | return genre; 69 | } 70 | 71 | public void setGenre(String genre) { 72 | this.genre = genre; 73 | } 74 | 75 | public int getTrackCount() { 76 | return trackCount; 77 | } 78 | 79 | public void setTrackCount(int trackCount) { 80 | this.trackCount = trackCount; 81 | } 82 | 83 | public String getAlbumId() { 84 | return albumId; 85 | } 86 | 87 | public void setAlbumId(String albumId) { 88 | this.albumId = albumId; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/domain/ApplicationInfo.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.domain; 2 | 3 | public class ApplicationInfo { 4 | private String[] profiles; 5 | private String[] services; 6 | 7 | public ApplicationInfo(String[] profiles, String[] services) { 8 | this.profiles = profiles; 9 | this.services = services; 10 | } 11 | 12 | public String[] getProfiles() { 13 | return profiles; 14 | } 15 | 16 | public void setProfiles(String[] profiles) { 17 | this.profiles = profiles; 18 | } 19 | 20 | public String[] getServices() { 21 | return services; 22 | } 23 | 24 | public void setServices(String[] services) { 25 | this.services = services; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/domain/RandomIdGenerator.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.domain; 2 | 3 | import org.hibernate.HibernateException; 4 | import org.hibernate.engine.spi.SessionImplementor; 5 | import org.hibernate.id.IdentifierGenerator; 6 | 7 | import java.io.Serializable; 8 | import java.util.UUID; 9 | 10 | public class RandomIdGenerator implements IdentifierGenerator { 11 | @Override 12 | public Serializable generate(SessionImplementor session, Object object) throws HibernateException { 13 | return generateId(); 14 | } 15 | 16 | public String generateId() { 17 | return UUID.randomUUID().toString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/repositories/AlbumRepository.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.repositories; 2 | 3 | import org.cloudfoundry.samples.music.domain.Album; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface AlbumRepository extends CrudRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/repositories/AlbumRepositoryPopulator.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.repositories; 2 | 3 | import com.fasterxml.jackson.databind.DeserializationFeature; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import org.cloudfoundry.samples.music.domain.Album; 6 | import org.springframework.beans.BeansException; 7 | import org.springframework.beans.factory.BeanFactoryUtils; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.context.ApplicationContextAware; 10 | import org.springframework.context.ApplicationListener; 11 | import org.springframework.context.event.ContextRefreshedEvent; 12 | import org.springframework.core.io.ClassPathResource; 13 | import org.springframework.core.io.Resource; 14 | import org.springframework.data.repository.init.Jackson2ResourceReader; 15 | import org.springframework.stereotype.Component; 16 | 17 | import java.util.Collection; 18 | 19 | @Component 20 | public class AlbumRepositoryPopulator implements ApplicationListener, ApplicationContextAware { 21 | private final Jackson2ResourceReader resourceReader; 22 | private final Resource sourceData; 23 | 24 | private ApplicationContext applicationContext; 25 | 26 | public AlbumRepositoryPopulator() { 27 | ObjectMapper mapper = new ObjectMapper(); 28 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 29 | resourceReader = new Jackson2ResourceReader(mapper); 30 | sourceData = new ClassPathResource("albums.json"); 31 | } 32 | 33 | @Override 34 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 35 | this.applicationContext = applicationContext; 36 | } 37 | 38 | @Override 39 | public void onApplicationEvent(ContextRefreshedEvent event) { 40 | if (event.getApplicationContext().equals(applicationContext)) { 41 | AlbumRepository albumRepository = 42 | BeanFactoryUtils.beanOfTypeIncludingAncestors(applicationContext, AlbumRepository.class); 43 | 44 | if (albumRepository != null && albumRepository.count() == 0) { 45 | populate(albumRepository); 46 | } 47 | } 48 | 49 | } 50 | 51 | @SuppressWarnings("unchecked") 52 | public void populate(AlbumRepository repository) { 53 | Object entity = getEntityFromResource(sourceData); 54 | 55 | if (entity instanceof Collection) { 56 | for (Album album : (Collection) entity) { 57 | if (album != null) { 58 | repository.save(album); 59 | } 60 | } 61 | } else { 62 | repository.save((Album) entity); 63 | } 64 | } 65 | 66 | private Object getEntityFromResource(Resource resource) { 67 | try { 68 | return resourceReader.readFrom(resource, this.getClass().getClassLoader()); 69 | } catch (Exception e) { 70 | throw new RuntimeException(e); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/repositories/jpa/JpaAlbumRepository.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.repositories.jpa; 2 | 3 | import org.cloudfoundry.samples.music.domain.Album; 4 | import org.cloudfoundry.samples.music.repositories.AlbumRepository; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface JpaAlbumRepository extends JpaRepository, AlbumRepository { 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/repositories/mongodb/MongoAlbumRepository.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.repositories.mongodb; 2 | 3 | import org.cloudfoundry.samples.music.domain.Album; 4 | import org.cloudfoundry.samples.music.repositories.AlbumRepository; 5 | import org.springframework.data.mongodb.repository.MongoRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface MongoAlbumRepository extends MongoRepository, AlbumRepository { 10 | } -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/repositories/redis/RedisAlbumRepository.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.repositories.redis; 2 | 3 | import org.cloudfoundry.samples.music.domain.Album; 4 | import org.cloudfoundry.samples.music.domain.RandomIdGenerator; 5 | import org.cloudfoundry.samples.music.repositories.AlbumRepository; 6 | import org.springframework.data.redis.core.HashOperations; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Set; 12 | 13 | public class RedisAlbumRepository implements AlbumRepository { 14 | public static final String ALBUMS_KEY = "albums"; 15 | 16 | private final RandomIdGenerator idGenerator; 17 | private final HashOperations hashOps; 18 | 19 | public RedisAlbumRepository(RedisTemplate redisTemplate) { 20 | this.hashOps = redisTemplate.opsForHash(); 21 | this.idGenerator = new RandomIdGenerator(); 22 | } 23 | 24 | @Override 25 | public S save(S album) { 26 | if (album.getId() == null) { 27 | album.setId(idGenerator.generateId()); 28 | } 29 | 30 | hashOps.put(ALBUMS_KEY, album.getId(), album); 31 | 32 | return album; 33 | } 34 | 35 | @Override 36 | public Iterable save(Iterable albums) { 37 | List result = new ArrayList(); 38 | 39 | for (S entity : albums) { 40 | save(entity); 41 | result.add(entity); 42 | } 43 | 44 | return result; 45 | } 46 | 47 | @Override 48 | public Album findOne(String id) { 49 | return hashOps.get(ALBUMS_KEY, id); 50 | } 51 | 52 | @Override 53 | public boolean exists(String id) { 54 | return hashOps.hasKey(ALBUMS_KEY, id); 55 | } 56 | 57 | @Override 58 | public Iterable findAll() { 59 | return hashOps.values(ALBUMS_KEY); 60 | } 61 | 62 | @Override 63 | public Iterable findAll(Iterable ids) { 64 | return hashOps.multiGet(ALBUMS_KEY, convertIterableToList(ids)); 65 | } 66 | 67 | @Override 68 | public long count() { 69 | return hashOps.keys(ALBUMS_KEY).size(); 70 | } 71 | 72 | @Override 73 | public void delete(String id) { 74 | hashOps.delete(ALBUMS_KEY, id); 75 | } 76 | 77 | @Override 78 | public void delete(Album album) { 79 | hashOps.delete(ALBUMS_KEY, album.getId()); 80 | } 81 | 82 | @Override 83 | public void delete(Iterable albums) { 84 | for (Album album : albums) { 85 | delete(album); 86 | } 87 | } 88 | 89 | @Override 90 | public void deleteAll() { 91 | Set ids = hashOps.keys(ALBUMS_KEY); 92 | for (String id : ids) { 93 | delete(id); 94 | } 95 | } 96 | 97 | private List convertIterableToList(Iterable iterable) { 98 | List list = new ArrayList(); 99 | for (T object : iterable) { 100 | list.add(object); 101 | } 102 | return list; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/web/controllers/AlbumController.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.web.controllers; 2 | 3 | import org.cloudfoundry.samples.music.domain.Album; 4 | import org.cloudfoundry.samples.music.repositories.AlbumRepository; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.validation.Valid; 12 | 13 | @Controller 14 | @RequestMapping(value = "/albums") 15 | public class AlbumController { 16 | private static final Logger logger = LoggerFactory.getLogger(AlbumController.class); 17 | private AlbumRepository repository; 18 | 19 | @Autowired 20 | public AlbumController(AlbumRepository repository) { 21 | this.repository = repository; 22 | } 23 | 24 | @ResponseBody 25 | @RequestMapping(method = RequestMethod.GET) 26 | public Iterable albums() { 27 | return repository.findAll(); 28 | } 29 | 30 | @ResponseBody 31 | @RequestMapping(method = RequestMethod.PUT) 32 | public Album add(@RequestBody @Valid Album album) { 33 | logger.info("Adding album " + album.getId()); 34 | return repository.save(album); 35 | } 36 | 37 | @ResponseBody 38 | @RequestMapping(method = RequestMethod.POST) 39 | public Album update(@RequestBody @Valid Album album) { 40 | logger.info("Updating album " + album.getId()); 41 | return repository.save(album); 42 | } 43 | 44 | @ResponseBody 45 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 46 | public Album getById(@PathVariable String id) { 47 | logger.info("Getting album " + id); 48 | return repository.findOne(id); 49 | } 50 | 51 | @ResponseBody 52 | @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) 53 | public void deleteById(@PathVariable String id) { 54 | logger.info("Deleting album " + id); 55 | repository.delete(id); 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/web/controllers/ErrorController.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.web.controllers; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | 9 | @Controller 10 | @RequestMapping("/errors") 11 | public class ErrorController { 12 | private static final Logger logger = LoggerFactory.getLogger(ErrorController.class); 13 | 14 | @ResponseBody 15 | @RequestMapping(value = "/kill") 16 | public void kill() { 17 | logger.info("Forcing application exit"); 18 | System.exit(1); 19 | } 20 | 21 | @ResponseBody 22 | @RequestMapping(value = "/throw") 23 | public void throwException() { 24 | logger.info("Forcing an exception to be thrown"); 25 | throw new NullPointerException("Forcing an exception to be thrown"); 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/org/cloudfoundry/samples/music/web/controllers/InfoController.java: -------------------------------------------------------------------------------- 1 | package org.cloudfoundry.samples.music.web.controllers; 2 | 3 | import org.cloudfoundry.samples.music.domain.ApplicationInfo; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.cloud.Cloud; 6 | import org.springframework.cloud.service.ServiceInfo; 7 | import org.springframework.core.env.Environment; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | @Controller 17 | public class InfoController { 18 | @Autowired(required = false) 19 | private Cloud cloud; 20 | 21 | private Environment springEnvironment; 22 | 23 | @Autowired 24 | public InfoController(Environment springEnvironment) { 25 | this.springEnvironment = springEnvironment; 26 | } 27 | 28 | @ResponseBody 29 | @RequestMapping(value = "/info") 30 | public ApplicationInfo info() { 31 | return new ApplicationInfo(springEnvironment.getActiveProfiles(), getServiceNames()); 32 | } 33 | 34 | @RequestMapping(value = "/env") 35 | @ResponseBody 36 | public Map showEnvironment() { 37 | return System.getenv(); 38 | } 39 | 40 | @RequestMapping(value = "/service") 41 | @ResponseBody 42 | public List showServiceInfo() { 43 | if (cloud != null) { 44 | return cloud.getServiceInfos(); 45 | } else { 46 | return new ArrayList(); 47 | } 48 | } 49 | 50 | private String[] getServiceNames() { 51 | if (cloud != null) { 52 | final List serviceInfos = cloud.getServiceInfos(); 53 | 54 | List names = new ArrayList(); 55 | for (ServiceInfo serviceInfo : serviceInfos) { 56 | names.add(serviceInfo.getId()); 57 | } 58 | return names.toArray(new String[names.size()]); 59 | } else { 60 | return new String[]{}; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/resources/albums.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "_class": "org.cloudfoundry.samples.music.domain.Album", 4 | "artist": "Nirvana", 5 | "title": "Nevermind", 6 | "releaseYear": "1991", 7 | "genre": "Rock" 8 | }, 9 | { 10 | "_class": "org.cloudfoundry.samples.music.domain.Album", 11 | "artist": "The Beach Boys", 12 | "title": "Pet Sounds", 13 | "releaseYear": "1966", 14 | "genre": "Rock" 15 | }, 16 | { 17 | "_class": "org.cloudfoundry.samples.music.domain.Album", 18 | "artist": "Marvin Gaye", 19 | "title": "What's Going On", 20 | "releaseYear": "1971", 21 | "genre": "Rock" 22 | }, 23 | { 24 | "_class": "org.cloudfoundry.samples.music.domain.Album", 25 | "artist": "Jimi Hendrix Experience", 26 | "title": "Are You Experienced?", 27 | "releaseYear": "1967", 28 | "genre": "Rock" 29 | }, 30 | { 31 | "_class": "org.cloudfoundry.samples.music.domain.Album", 32 | "artist": "U2", 33 | "title": "The Joshua Tree", 34 | "releaseYear": "1987", 35 | "genre": "Rock" 36 | }, 37 | { 38 | "_class": "org.cloudfoundry.samples.music.domain.Album", 39 | "artist": "The Beatles", 40 | "title": "Abbey Road", 41 | "releaseYear": "1969", 42 | "genre": "Rock" 43 | }, 44 | { 45 | "_class": "org.cloudfoundry.samples.music.domain.Album", 46 | "artist": "Fleetwood Mac", 47 | "title": "Rumours", 48 | "releaseYear": "1977", 49 | "genre": "Rock" 50 | }, 51 | { 52 | "_class": "org.cloudfoundry.samples.music.domain.Album", 53 | "artist": "Elvis Presley", 54 | "title": "Sun Sessions", 55 | "releaseYear": "1976", 56 | "genre": "Rock" 57 | }, 58 | { 59 | "_class": "org.cloudfoundry.samples.music.domain.Album", 60 | "artist": "Michael Jackson", 61 | "title": "Thriller", 62 | "releaseYear": "1982", 63 | "genre": "Pop" 64 | }, 65 | { 66 | "_class": "org.cloudfoundry.samples.music.domain.Album", 67 | "artist": "The Rolling Stones", 68 | "title": "Exile on Main Street", 69 | "releaseYear": "1972", 70 | "genre": "Rock" 71 | }, 72 | { 73 | "_class": "org.cloudfoundry.samples.music.domain.Album", 74 | "artist": "Bruce Springsteen", 75 | "title": "Born to Run", 76 | "releaseYear": "1975", 77 | "genre": "Rock" 78 | }, 79 | { 80 | "_class": "org.cloudfoundry.samples.music.domain.Album", 81 | "artist": "The Clash", 82 | "title": "London Calling", 83 | "releaseYear": "1980", 84 | "genre": "Rock" 85 | }, 86 | { 87 | "_class": "org.cloudfoundry.samples.music.domain.Album", 88 | "artist": "The Eagles", 89 | "title": "Hotel California", 90 | "releaseYear": "1976", 91 | "genre": "Rock" 92 | }, 93 | { 94 | "_class": "org.cloudfoundry.samples.music.domain.Album", 95 | "artist": "Led Zeppelin", 96 | "title": "Led Zeppelin", 97 | "releaseYear": "1969", 98 | "genre": "Rock" 99 | }, 100 | { 101 | "_class": "org.cloudfoundry.samples.music.domain.Album", 102 | "artist": "Led Zeppelin", 103 | "title": "IV", 104 | "releaseYear": "1971", 105 | "genre": "Rock" 106 | }, 107 | { 108 | "_class": "org.cloudfoundry.samples.music.domain.Album", 109 | "artist": "Police", 110 | "title": "Synchronicity", 111 | "releaseYear": "1983", 112 | "genre": "Rock" 113 | }, 114 | { 115 | "_class": "org.cloudfoundry.samples.music.domain.Album", 116 | "artist": "U2", 117 | "title": "Achtung Baby", 118 | "releaseYear": "1991", 119 | "genre": "Rock" 120 | }, 121 | { 122 | "_class": "org.cloudfoundry.samples.music.domain.Album", 123 | "artist": "The Rolling Stones", 124 | "title": "Let it Bleed", 125 | "releaseYear": "1969", 126 | "genre": "Rock" 127 | }, 128 | { 129 | "_class": "org.cloudfoundry.samples.music.domain.Album", 130 | "artist": "The Beatles", 131 | "title": "Rubber Soul", 132 | "releaseYear": "1965", 133 | "genre": "Rock" 134 | }, 135 | { 136 | "_class": "org.cloudfoundry.samples.music.domain.Album", 137 | "artist": "The Ramones", 138 | "title": "The Ramones", 139 | "releaseYear": "1976", 140 | "genre": "Rock" 141 | }, 142 | { 143 | "_class": "org.cloudfoundry.samples.music.domain.Album", 144 | "artist": "Queen", 145 | "title": "A Night At The Opera", 146 | "releaseYear": "1975", 147 | "genre": "Rock" 148 | }, 149 | { 150 | "_class": "org.cloudfoundry.samples.music.domain.Album", 151 | "artist": "Boston", 152 | "title": "Don't Look Back", 153 | "releaseYear": "1978", 154 | "genre": "Rock" 155 | }, 156 | { 157 | "_class": "org.cloudfoundry.samples.music.domain.Album", 158 | "artist": "BB King", 159 | "title": "Singin' The Blues", 160 | "releaseYear": "1956", 161 | "genre": "Blues" 162 | }, 163 | { 164 | "_class": "org.cloudfoundry.samples.music.domain.Album", 165 | "artist": "Albert King", 166 | "title": "Born Under A Bad Sign", 167 | "releaseYear": "1967", 168 | "genre": "Blues" 169 | }, 170 | { 171 | "_class": "org.cloudfoundry.samples.music.domain.Album", 172 | "artist": "Muddy Waters", 173 | "title": "Folk Singer", 174 | "releaseYear": "1964", 175 | "genre": "Blues" 176 | }, 177 | { 178 | "_class": "org.cloudfoundry.samples.music.domain.Album", 179 | "artist": "The Fabulous Thunderbirds", 180 | "title": "Rock With Me", 181 | "releaseYear": "1979", 182 | "genre": "Blues" 183 | }, 184 | { 185 | "_class": "org.cloudfoundry.samples.music.domain.Album", 186 | "artist": "Robert Johnson", 187 | "title": "King of the Delta Blues", 188 | "releaseYear": "1961", 189 | "genre": "Blues" 190 | }, 191 | { 192 | "_class": "org.cloudfoundry.samples.music.domain.Album", 193 | "artist": "Stevie Ray Vaughan", 194 | "title": "Texas Flood", 195 | "releaseYear": "1983", 196 | "genre": "Blues" 197 | }, 198 | { 199 | "_class": "org.cloudfoundry.samples.music.domain.Album", 200 | "artist": "Stevie Ray Vaughan", 201 | "title": "Couldn't Stand The Weather", 202 | "releaseYear": "1984", 203 | "genre": "Blues" 204 | } 205 | ] -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Direct log messages to stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.Target=System.out 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n 6 | 7 | # Root logger option 8 | log4j.rootLogger=INFO,stdout 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/messages.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenisha/vsts-terraform-ansible/fdb433aa3d8f17a1b0e411f09dd69fe05f37177c/src/main/resources/messages.properties -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Spring Music 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |
19 |
20 | 21 |
22 | 23 |
24 | 25 |
26 |
27 |
28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/webapp/assets/css/app.css: -------------------------------------------------------------------------------- 1 | #body { 2 | padding-top: 10px; 3 | } 4 | 5 | .navbar { 6 | background-color: white; 7 | border: 0; 8 | margin-bottom: 20px; 9 | } 10 | 11 | .navbar .container { 12 | background-color: #008a00; 13 | background-image: -moz-linear-gradient(top, #008a00, #006b00); 14 | background-image: -ms-linear-gradient(top, #008a00, #006b00); 15 | background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#008a00), to(#006b00)); 16 | background-image: -webkit-linear-gradient(top, #008a00, #006b00); 17 | background-image: -o-linear-gradient(top, #008a00, #006b00); 18 | background-image: linear-gradient(top, #008a00, #006b00); 19 | } 20 | 21 | .navbar .navbar-brand { 22 | color: white; 23 | } 24 | 25 | .navbar .navbar-brand:hover { 26 | color: white; 27 | } 28 | 29 | .btn { 30 | background-color: white; 31 | } 32 | 33 | .icon-white { 34 | color: white; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/webapp/assets/css/multi-columns-row.css: -------------------------------------------------------------------------------- 1 | /* From https://github.com/sixfootsixdesigns/Bootstrap-3-Grid-Columns-Clearing */ 2 | 3 | /* clear first in row in ie 8 or lower */ 4 | .multi-columns-row .first-in-row { 5 | clear: left; 6 | } 7 | 8 | /* clear the first in row for any block that has the class "multi-columns-row" */ 9 | .multi-columns-row .col-xs-6:nth-child(2n + 3) { clear: left; } 10 | .multi-columns-row .col-xs-4:nth-child(3n + 4) { clear: left; } 11 | .multi-columns-row .col-xs-3:nth-child(4n + 5) { clear: left; } 12 | .multi-columns-row .col-xs-2:nth-child(6n + 7) { clear: left; } 13 | .multi-columns-row .col-xs-1:nth-child(12n + 13) { clear: left; } 14 | 15 | @media (min-width: 768px) { 16 | /* reset previous grid */ 17 | .multi-columns-row .col-xs-6:nth-child(2n + 3) { clear: none; } 18 | .multi-columns-row .col-xs-4:nth-child(3n + 4) { clear: none; } 19 | .multi-columns-row .col-xs-3:nth-child(4n + 5) { clear: none; } 20 | .multi-columns-row .col-xs-2:nth-child(6n + 7) { clear: none; } 21 | .multi-columns-row .col-xs-1:nth-child(12n + 13) { clear: none; } 22 | 23 | /* clear first in row for small columns */ 24 | .multi-columns-row .col-sm-6:nth-child(2n + 3) { clear: left; } 25 | .multi-columns-row .col-sm-4:nth-child(3n + 4) { clear: left; } 26 | .multi-columns-row .col-sm-3:nth-child(4n + 5) { clear: left; } 27 | .multi-columns-row .col-sm-2:nth-child(6n + 7) { clear: left; } 28 | .multi-columns-row .col-sm-1:nth-child(12n + 13) { clear: left; } 29 | } 30 | @media (min-width: 992px) { 31 | /* reset previous grid */ 32 | .multi-columns-row .col-sm-6:nth-child(2n + 3) { clear: none; } 33 | .multi-columns-row .col-sm-4:nth-child(3n + 4) { clear: none; } 34 | .multi-columns-row .col-sm-3:nth-child(4n + 5) { clear: none; } 35 | .multi-columns-row .col-sm-2:nth-child(6n + 7) { clear: none; } 36 | .multi-columns-row .col-sm-1:nth-child(12n + 13) { clear: none; } 37 | 38 | /* clear first in row for medium columns */ 39 | .multi-columns-row .col-md-6:nth-child(2n + 3) { clear: left; } 40 | .multi-columns-row .col-md-4:nth-child(3n + 4) { clear: left; } 41 | .multi-columns-row .col-md-3:nth-child(4n + 5) { clear: left; } 42 | .multi-columns-row .col-md-2:nth-child(6n + 7) { clear: left; } 43 | .multi-columns-row .col-md-1:nth-child(12n + 13) { clear: left; } 44 | } 45 | @media (min-width: 1200px) { 46 | /* reset previous grid */ 47 | .multi-columns-row .col-md-6:nth-child(2n + 3) { clear: none; } 48 | .multi-columns-row .col-md-4:nth-child(3n + 4) { clear: none; } 49 | .multi-columns-row .col-md-3:nth-child(4n + 5) { clear: none; } 50 | .multi-columns-row .col-md-2:nth-child(6n + 7) { clear: none; } 51 | .multi-columns-row .col-md-1:nth-child(12n + 13) { clear: none; } 52 | 53 | /* clear first in row for large columns */ 54 | .multi-columns-row .col-lg-6:nth-child(2n + 3) { clear: left; } 55 | .multi-columns-row .col-lg-4:nth-child(3n + 4) { clear: left; } 56 | .multi-columns-row .col-lg-3:nth-child(4n + 5) { clear: left; } 57 | .multi-columns-row .col-lg-2:nth-child(6n + 7) { clear: left; } 58 | .multi-columns-row .col-lg-1:nth-child(12n + 13) { clear: left; } 59 | } -------------------------------------------------------------------------------- /src/main/webapp/assets/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenisha/vsts-terraform-ansible/fdb433aa3d8f17a1b0e411f09dd69fe05f37177c/src/main/webapp/assets/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /src/main/webapp/assets/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenisha/vsts-terraform-ansible/fdb433aa3d8f17a1b0e411f09dd69fe05f37177c/src/main/webapp/assets/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /src/main/webapp/assets/js/albums.js: -------------------------------------------------------------------------------- 1 | angular.module('albums', ['ngResource', 'ui.bootstrap']). 2 | factory('Albums', function ($resource) { 3 | return $resource('albums'); 4 | }). 5 | factory('Album', function ($resource) { 6 | return $resource('albums/:id', {id: '@id'}); 7 | }). 8 | factory("EditorStatus", function () { 9 | var editorEnabled = {}; 10 | 11 | var enable = function (id, fieldName) { 12 | this.editorEnabled = { 'id': id, 'fieldName': fieldName }; 13 | }; 14 | 15 | var disable = function () { 16 | this.editorEnabled = {}; 17 | }; 18 | 19 | var isEnabled = function(id, fieldName) { 20 | return (this.editorEnabled['id'] == id && this.editorEnabled['fieldName'] == fieldName); 21 | }; 22 | 23 | return { 24 | isEnabled: isEnabled, 25 | enable: enable, 26 | disable: disable 27 | } 28 | }); 29 | 30 | function AlbumsController($scope, $modal, Albums, Album, Status) { 31 | function list() { 32 | $scope.albums = Albums.query(); 33 | } 34 | 35 | function clone (obj) { 36 | return JSON.parse(JSON.stringify(obj)); 37 | } 38 | 39 | function saveAlbum(album) { 40 | Albums.save(album, 41 | function () { 42 | Status.success("Album saved"); 43 | list(); 44 | }, 45 | function (result) { 46 | Status.error("Error saving album: " + result.status); 47 | } 48 | ); 49 | } 50 | 51 | $scope.addAlbum = function () { 52 | var addModal = $modal.open({ 53 | templateUrl: 'assets/templates/albumForm.html', 54 | controller: AlbumModalController, 55 | resolve: { 56 | album: function () { 57 | return {}; 58 | }, 59 | action: function() { 60 | return 'add'; 61 | } 62 | } 63 | }); 64 | 65 | addModal.result.then(function (album) { 66 | saveAlbum(album); 67 | }); 68 | }; 69 | 70 | $scope.updateAlbum = function (album) { 71 | var updateModal = $modal.open({ 72 | templateUrl: 'assets/templates/albumForm.html', 73 | controller: AlbumModalController, 74 | resolve: { 75 | album: function() { 76 | return clone(album); 77 | }, 78 | action: function() { 79 | return 'update'; 80 | } 81 | } 82 | }); 83 | 84 | updateModal.result.then(function (album) { 85 | saveAlbum(album); 86 | }); 87 | }; 88 | 89 | $scope.deleteAlbum = function (album) { 90 | Album.delete({id: album.id}, 91 | function () { 92 | Status.success("Album deleted"); 93 | list(); 94 | }, 95 | function (result) { 96 | Status.error("Error deleting album: " + result.status); 97 | } 98 | ); 99 | }; 100 | 101 | $scope.setAlbumsView = function (viewName) { 102 | $scope.albumsView = "assets/templates/" + viewName + ".html"; 103 | }; 104 | 105 | $scope.init = function() { 106 | list(); 107 | $scope.setAlbumsView("grid"); 108 | $scope.sortField = "name"; 109 | $scope.sortDescending = false; 110 | }; 111 | } 112 | 113 | function AlbumModalController($scope, $modalInstance, album, action) { 114 | $scope.albumAction = action; 115 | $scope.yearPattern = /^[1-2]\d{3}$/; 116 | $scope.album = album; 117 | 118 | $scope.ok = function () { 119 | $modalInstance.close($scope.album); 120 | }; 121 | 122 | $scope.cancel = function () { 123 | $modalInstance.dismiss('cancel'); 124 | }; 125 | }; 126 | 127 | function AlbumEditorController($scope, Albums, Status, EditorStatus) { 128 | $scope.enableEditor = function (album, fieldName) { 129 | $scope.newFieldValue = album[fieldName]; 130 | EditorStatus.enable(album.id, fieldName); 131 | }; 132 | 133 | $scope.disableEditor = function () { 134 | EditorStatus.disable(); 135 | }; 136 | 137 | $scope.isEditorEnabled = function (album, fieldName) { 138 | return EditorStatus.isEnabled(album.id, fieldName); 139 | }; 140 | 141 | $scope.save = function (album, fieldName) { 142 | if ($scope.newFieldValue === "") { 143 | return false; 144 | } 145 | 146 | album[fieldName] = $scope.newFieldValue; 147 | 148 | Albums.save({}, album, 149 | function () { 150 | Status.success("Album saved"); 151 | list(); 152 | }, 153 | function (result) { 154 | Status.error("Error saving album: " + result.status); 155 | } 156 | ); 157 | 158 | $scope.disableEditor(); 159 | }; 160 | 161 | $scope.disableEditor(); 162 | } 163 | 164 | angular.module('albums'). 165 | directive('inPlaceEdit', function () { 166 | return { 167 | restrict: 'E', 168 | transclude: true, 169 | replace: true, 170 | 171 | scope: { 172 | ipeFieldName: '@fieldName', 173 | ipeInputType: '@inputType', 174 | ipeInputClass: '@inputClass', 175 | ipePattern: '@pattern', 176 | ipeModel: '=model' 177 | }, 178 | 179 | template: 180 | '
' + 181 | '' + 182 | '' + 183 | '' + 184 | '' + 185 | '
' + 186 | '' + 189 | '' + 193 | '
' + 194 | '
' + 195 | '
', 196 | 197 | controller: 'AlbumEditorController' 198 | }; 199 | }); 200 | -------------------------------------------------------------------------------- /src/main/webapp/assets/js/app.js: -------------------------------------------------------------------------------- 1 | angular.module('SpringMusic', ['albums', 'errors', 'status', 'info', 'ngRoute', 'ui.directives']). 2 | config(function ($locationProvider, $routeProvider) { 3 | // $locationProvider.html5Mode(true); 4 | 5 | $routeProvider.when('/errors', { 6 | controller: 'ErrorsController', 7 | templateUrl: 'assets/templates/errors.html' 8 | }); 9 | $routeProvider.otherwise({ 10 | controller: 'AlbumsController', 11 | templateUrl: 'assets/templates/albums.html' 12 | }); 13 | } 14 | ); 15 | -------------------------------------------------------------------------------- /src/main/webapp/assets/js/errors.js: -------------------------------------------------------------------------------- 1 | angular.module('errors', ['ngResource']). 2 | factory('Errors', function ($resource) { 3 | return $resource('errors', {}, { 4 | kill: { url: 'errors/kill' }, 5 | throw: { url: 'errors/throw' } 6 | }); 7 | }); 8 | 9 | function ErrorsController($scope, Errors, Status) { 10 | $scope.kill = function() { 11 | Errors.kill({}, 12 | function () { 13 | Status.error("The application should have been killed, but returned successfully instead."); 14 | }, 15 | function (result) { 16 | if (result.status === 502) 17 | Status.error("An error occurred as expected, the application backend was killed: " + result.status); 18 | else 19 | Status.error("An unexpected error occurred: " + result.status); 20 | } 21 | ); 22 | }; 23 | 24 | $scope.throwException = function() { 25 | Errors.throw({}, 26 | function () { 27 | Status.error("An exception should have been thrown, but was not."); 28 | }, 29 | function (result) { 30 | if (result.status === 500) 31 | Status.error("An error occurred as expected: " + result.status); 32 | else 33 | Status.error("An unexpected error occurred: " + result.status); 34 | } 35 | ); 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/webapp/assets/js/info.js: -------------------------------------------------------------------------------- 1 | angular.module('info', ['ngResource']). 2 | factory('Info', function ($resource) { 3 | return $resource('info'); 4 | }); 5 | 6 | function InfoController($scope, Info) { 7 | $scope.info = Info.get(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/webapp/assets/js/status.js: -------------------------------------------------------------------------------- 1 | angular.module('status', []). 2 | factory("Status", function () { 3 | var status = null; 4 | 5 | var success = function (message) { 6 | this.status = { isError: false, message: message }; 7 | }; 8 | 9 | var error = function (message) { 10 | this.status = { isError: true, message: message }; 11 | }; 12 | 13 | var clear = function () { 14 | this.status = null; 15 | }; 16 | 17 | return { 18 | status: status, 19 | success: success, 20 | error: error, 21 | clear: clear 22 | } 23 | }); 24 | 25 | function StatusController($scope, Status) { 26 | $scope.$watch( 27 | function () { 28 | return Status.status; 29 | }, 30 | function (status) { 31 | $scope.status = status; 32 | }, 33 | true); 34 | 35 | $scope.clearStatus = function () { 36 | Status.clear(); 37 | }; 38 | } -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/albumForm.html: -------------------------------------------------------------------------------- 1 | 5 | 29 | 33 | -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/albums.html: -------------------------------------------------------------------------------- 1 |
2 | 21 | 22 |
23 |
24 |
25 | 26 |
27 |
28 |
29 |
30 | -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/errors.html: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 |
7 |
8 |
9 | 10 |
11 |
12 |
13 |

Kill this instance of the application

14 | Kill 15 |
16 |
17 |

Force an exception to be thrown from the application

18 | Throw Exception 19 |
20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/footer.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/grid.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

5 | {{album.title}} 6 |

7 | 8 |

9 | {{album.artist}} 10 |

11 | 12 |
13 | {{album.releaseYear}} 14 |
15 | 16 |
17 | {{album.genre}} 18 |
19 | 20 | 29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/header.html: -------------------------------------------------------------------------------- 1 | 25 | -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/list.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 20 | 23 | 26 | 35 | 36 | 37 |
Album TitleArtistYearGenre
15 | {{album.title}} 16 | 18 | {{album.artist}} 19 | 21 | {{album.releaseYear}} 22 | 24 | {{album.genre}} 25 |
38 |
39 | -------------------------------------------------------------------------------- /src/main/webapp/assets/templates/status.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |

{{status.message}}

6 |
7 |
8 |
-------------------------------------------------------------------------------- /vsts/Build-Java-CI.json: -------------------------------------------------------------------------------- 1 | {"options":[{"enabled":true,"definition":{"id":"5d58cc01-7c75-450c-be18-a388ddb129ec"},"inputs":{"branchFilters":"[\"+refs/heads/*\"]","additionalFields":"{}"}},{"enabled":false,"definition":{"id":"a9db38f9-9fdc-478c-b0f9-464221e58316"},"inputs":{"workItemType":"1644370","assignToRequestor":"true","additionalFields":"{}"}}],"triggers":[{"branchFilters":["+refs/heads/master"],"pathFilters":[],"batchChanges":false,"maxConcurrentBuildsPerBranch":1,"pollingInterval":0,"triggerType":2}],"variables":{"system.debug":{"value":"false","allowOverride":true}},"retentionRules":[{"branches":["+refs/heads/*"],"artifacts":[],"artifactTypesToDelete":["FilePath","SymbolStore"],"daysToKeep":10,"minimumToKeep":1,"deleteBuildRecord":true,"deleteTestResults":true}],"properties":{},"tags":[],"metrics":[{"name":"CurrentBuildsInQueue","scope":"refs/heads/master","intValue":0},{"name":"CurrentBuildsInProgress","scope":"refs/heads/master","intValue":0},{"name":"CanceledBuilds","scope":"refs/heads/master","intValue":0,"date":"2018-05-13T00:00:00.000Z"},{"name":"FailedBuilds","scope":"refs/heads/master","intValue":0,"date":"2018-05-13T00:00:00.000Z"},{"name":"PartiallySuccessfulBuilds","scope":"refs/heads/master","intValue":0,"date":"2018-05-13T00:00:00.000Z"},{"name":"SuccessfulBuilds","scope":"refs/heads/master","intValue":11,"date":"2018-05-13T00:00:00.000Z"},{"name":"TotalBuilds","scope":"refs/heads/master","intValue":11,"date":"2018-05-13T00:00:00.000Z"}],"_links":{"self":{"href":"https://eneros.visualstudio.com/59065378-0e3f-4947-973b-212c1ff1b7a4/_apis/build/Definitions/7?revision=12"},"web":{"href":"https://eneros.visualstudio.com/59065378-0e3f-4947-973b-212c1ff1b7a4/_build/index?definitionId=7"},"editor":{"href":"https://eneros.visualstudio.com/59065378-0e3f-4947-973b-212c1ff1b7a4/_build/definitionEditor?definitionId=7"}},"buildNumberFormat":"$(date:yyyyMMdd)$(rev:.r)","jobAuthorizationScope":1,"jobTimeoutInMinutes":60,"jobCancelTimeoutInMinutes":5,"process":{"phases":[{"steps":[{"environment":{},"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"gradlew clean assemble","timeoutInMinutes":0,"task":{"id":"8d8eebd8-2b94-4c97-85af-839254cc6da4","versionSpec":"2.*","definitionType":"task"},"inputs":{"wrapperScript":"$(Parameters.wrapperScript)","cwd":"","options":"","tasks":"$(Parameters.tasks)","publishJUnitResults":"true","testResultsFiles":"**/build/test-results/TEST-*.xml","testRunTitle":"","codeCoverageTool":"None","classFilesDirectories":"build/classes/main/","classFilter":"","failIfCoverageEmpty":"false","javaHomeSelection":"JDKVersion","jdkVersion":"default","jdkUserInputPath":"","jdkArchitecture":"x64","gradleOpts":"-Xmx1024m","sqAnalysisEnabled":"false","sqGradlePluginVersionChoice":"specify","sqGradlePluginVersion":"2.6.1","checkstyleAnalysisEnabled":"false","findbugsAnalysisEnabled":"false","pmdAnalysisEnabled":"false"}},{"environment":{},"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"Copy Files to: $(build.artifactstagingdirectory)","timeoutInMinutes":0,"task":{"id":"5bfb729a-a7c8-4a78-a7c3-8d717bb7c13c","versionSpec":"2.*","definitionType":"task"},"inputs":{"SourceFolder":"$(system.defaultworkingdirectory)","Contents":"**/*.war\niac/**\n","TargetFolder":"$(build.artifactstagingdirectory)","CleanTargetFolder":"false","OverWrite":"false","flattenFolders":"false"}},{"environment":{},"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"Publish Artifact: drop","timeoutInMinutes":0,"task":{"id":"2ff763a7-ce83-4e1f-bc89-0ae63477cebe","versionSpec":"1.*","definitionType":"task"},"inputs":{"PathtoPublish":"$(build.artifactstagingdirectory)","ArtifactName":"drop","ArtifactType":"Container","TargetPath":"\\\\my\\share\\$(Build.DefinitionName)\\$(Build.BuildNumber)","Parallel":"false","ParallelCount":"8"}}],"name":"Phase 1","refName":"Phase_1","condition":"succeeded()","target":{"executionOptions":{"type":0},"allowScriptsAuthAccessOption":false,"type":1},"jobAuthorizationScope":"projectCollection","jobCancelTimeoutInMinutes":1}],"type":1},"repository":{"properties":{"cleanOptions":"0","labelSources":"0","labelSourcesFormat":"$(build.buildNumber)","reportBuildStatus":"true","gitLfsSupport":"false","skipSyncSource":"false","checkoutNestedSubmodules":"false","fetchDepth":"0"},"id":"b6dec4fa-7b0b-4659-a121-9e28b2e0d88a","type":"TfsGit","name":"DemoJava","url":"https://eneros.visualstudio.com/DemoIAC/_git/DemoJava","defaultBranch":"refs/heads/master","clean":"false","checkoutSubmodules":false},"processParameters":{"inputs":[{"aliases":[],"options":{},"properties":{},"name":"wrapperScript","label":"Gradle wrapper","defaultValue":"gradlew","required":true,"type":"filePath","helpMarkDown":"Relative path from the repository root to the Gradle Wrapper script.","visibleRule":"","groupName":""},{"aliases":[],"options":{},"properties":{},"name":"tasks","label":"Tasks","defaultValue":"build","required":true,"type":"string","helpMarkDown":"","visibleRule":"","groupName":""}]},"quality":1,"authoredBy":{"displayName":"Elena Neroslavskaya","url":"https://app.vssps.visualstudio.com/Ab962ed4f-6670-4a37-ad24-8b9381530e67/_apis/Identities/a355a0dd-039c-6ee0-a25e-6351af069b94","_links":{"avatar":{"href":"https://eneros.visualstudio.com/_apis/GraphProfile/MemberAvatars/aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"}},"id":"a355a0dd-039c-6ee0-a25e-6351af069b94","uniqueName":"eneros@microsoft.com","imageUrl":"https://eneros.visualstudio.com/_api/_common/identityImage?id=a355a0dd-039c-6ee0-a25e-6351af069b94","descriptor":"aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"},"drafts":[],"queue":{"_links":{"self":{"href":"https://eneros.visualstudio.com/_apis/build/Queues/24"}},"id":24,"name":"ACI-Pool","url":"https://eneros.visualstudio.com/_apis/build/Queues/24","pool":{"id":6,"name":"ACI-Pool"}},"id":7,"name":"Build-Java-CI","url":"https://eneros.visualstudio.com/59065378-0e3f-4947-973b-212c1ff1b7a4/_apis/build/Definitions/7?revision=12","uri":"vstfs:///Build/Definition/7","path":"\\","type":2,"queueStatus":0,"revision":12,"createdDate":"2018-05-13T06:24:51.180Z","project":{"id":"59065378-0e3f-4947-973b-212c1ff1b7a4","name":"DemoIAC","url":"https://eneros.visualstudio.com/_apis/projects/59065378-0e3f-4947-973b-212c1ff1b7a4","state":"wellFormed","revision":40,"visibility":1}} -------------------------------------------------------------------------------- /vsts/Java-Terraform-CD.json: -------------------------------------------------------------------------------- 1 | {"source":2,"revision":17,"description":null,"createdBy":{"displayName":"Elena Neroslavskaya","url":"https://app.vssps.visualstudio.com/Ab962ed4f-6670-4a37-ad24-8b9381530e67/_apis/Identities/a355a0dd-039c-6ee0-a25e-6351af069b94","_links":{"avatar":{"href":"https://tfsprodcca1.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/_apis/GraphProfile/MemberAvatars/aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"}},"id":"a355a0dd-039c-6ee0-a25e-6351af069b94","uniqueName":"eneros@microsoft.com","imageUrl":"https://tfsprodcca1.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/_api/_common/identityImage?id=a355a0dd-039c-6ee0-a25e-6351af069b94","descriptor":"aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"},"createdOn":"2018-04-02T23:20:37.267Z","modifiedBy":{"displayName":"Elena Neroslavskaya","url":"https://app.vssps.visualstudio.com/Ab962ed4f-6670-4a37-ad24-8b9381530e67/_apis/Identities/a355a0dd-039c-6ee0-a25e-6351af069b94","_links":{"avatar":{"href":"https://tfsprodcca1.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/_apis/GraphProfile/MemberAvatars/aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"}},"id":"a355a0dd-039c-6ee0-a25e-6351af069b94","uniqueName":"eneros@microsoft.com","imageUrl":"https://tfsprodcca1.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/_api/_common/identityImage?id=a355a0dd-039c-6ee0-a25e-6351af069b94","descriptor":"aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"},"modifiedOn":"2018-05-28T03:59:54.613Z","isDeleted":false,"variables":{"SSH_PUB_KEY":{"value":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDzWnLrGQrrR/1ghPRWzRVGLi64vMv+h+Wqx1BbgjHBUJd+TmJwrt8jJn7g/lMt9v2nkPU31B5iFeJJei5E/ShPAhxss4N5/J4fP6Uxq3iXcDC9LdC3P4wdQh5bxTYN1ruQtPpmyTPrLpfK++SPu42pAiAoAWdiw7s/WXLzxNALWsl2zrpNqTK9OdrDWmDFeu7PzVGxJ3cPEhPHfxzBTmj87vN5obSGr7uHrmtDwX5+5l6UscyWLdC6q6Wbk/SW8bICfccXJua3yddtXb5sx8jSivo99qusSpE8uUrpzFz9XFlARJQWtO0fsZKnK+yxZktcGNh8FvI89AU7iW4A180z lenisha@Terraform"}},"variableGroups":[1],"environments":[{"id":10,"name":"Azure-CC","rank":1,"owner":{"displayName":"Elena Neroslavskaya","url":"https://app.vssps.visualstudio.com/Ab962ed4f-6670-4a37-ad24-8b9381530e67/_apis/Identities/a355a0dd-039c-6ee0-a25e-6351af069b94","_links":{"avatar":{"href":"https://tfsprodcca1.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/_apis/GraphProfile/MemberAvatars/aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"}},"id":"a355a0dd-039c-6ee0-a25e-6351af069b94","uniqueName":"eneros@microsoft.com","imageUrl":"https://tfsprodcca1.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/_api/_common/identityImage?id=a355a0dd-039c-6ee0-a25e-6351af069b94","descriptor":"aad.YTM1NWEwZGQtMDM5Yy03ZWUwLWEyNWUtNjM1MWFmMDY5Yjk0"},"variables":{},"variableGroups":[],"preDeployApprovals":{"approvals":[{"rank":1,"isAutomated":true,"isNotificationOn":false,"id":28}],"approvalOptions":{"requiredApproverCount":null,"releaseCreatorCanBeApprover":false,"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped":false,"enforceIdentityRevalidation":false,"timeoutInMinutes":0,"executionOrder":1}},"deployStep":{"id":29},"postDeployApprovals":{"approvals":[{"rank":1,"isAutomated":true,"isNotificationOn":false,"id":30}],"approvalOptions":{"requiredApproverCount":null,"releaseCreatorCanBeApprover":false,"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped":false,"enforceIdentityRevalidation":false,"timeoutInMinutes":0,"executionOrder":2}},"deployPhases":[{"deploymentInput":{"parallelExecution":{"parallelExecutionType":"none"},"skipArtifactsDownload":false,"artifactsDownloadInput":{"downloadInputs":[{"artifactItems":[],"alias":"Build-Java-CI","artifactType":"Build","artifactDownloadMode":"All"}]},"queueId":24,"demands":[],"enableAccessToken":false,"timeoutInMinutes":0,"jobCancelTimeoutInMinutes":1,"condition":"succeeded()","overrideInputs":{}},"rank":1,"phaseType":1,"name":"Agent phase","workflowTasks":[{"taskId":"5c9af2eb-5fc5-42dc-9b91-dc234a8c4400","version":"0.*","name":"Install an SSH key","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"hostName":"default","sshPublicKey":"$(SSH_PUB_KEY)","sshPassphrase":"","sshKeySecureFile":"ed7be082-28ee-4cc6-83ea-7685f856c16d"}},{"taskId":"6c731c3c-3c68-459a-a5c9-bde6e6595b5b","version":"2.*","name":"Terraform init","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"scriptPath":"$(System.DefaultWorkingDirectory)/Build-Java-CI/drop/iac/terraform/init.sh","args":"$(ARM_CLIENT_ID) $(ARM_CLIENT_SECRET) $(ARM_SUBSCRIPTION_ID) $(ARM_TENANT_ID) $(ARM_ACCESS_KEY)","disableAutoCwd":"true","cwd":"$(System.DefaultWorkingDirectory)/Build-Java-CI/drop/iac/terraform/azure","failOnStandardError":"false"}},{"taskId":"6c731c3c-3c68-459a-a5c9-bde6e6595b5b","version":"2.*","name":"Terraform apply","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"scriptPath":"$(System.DefaultWorkingDirectory)/Build-Java-CI/drop/iac/terraform/apply.sh","args":"$(ARM_CLIENT_ID) $(ARM_CLIENT_SECRET) $(ARM_SUBSCRIPTION_ID) $(ARM_TENANT_ID) $(ARM_ACCESS_KEY) $(SSH_PUB_KEY)","disableAutoCwd":"true","cwd":"$(System.DefaultWorkingDirectory)/Build-Java-CI/drop/iac/terraform/azure","failOnStandardError":"false"}},{"taskId":"6f650d20-9c5d-4cce-ad66-e68742ceadf5","version":"0.*","name":"Run playbook","refName":"","enabled":true,"alwaysRun":false,"continueOnError":false,"timeoutInMinutes":0,"definitionType":"task","overrideInputs":{},"condition":"succeeded()","inputs":{"ansibleInterface":"agentMachine","connectionOverSsh":"","playbookSourceRemoteMachine":"agentMachine","playbookRootRemoteMachine":"","playbookPathLinkedArtifactOnRemoteMachine":"","playbookPathAnsibleMachineOnRemoteMachine":"","playbookPathOnAgentMachine":"$(System.DefaultWorkingDirectory)/Build-Java-CI/drop/iac/ansible/site.yml","inventoriesRemoteMachine":"noInventory","inventoryFileSourceRemoteMachine":"agentMachine","inventoryFileLinkedArtifactOnRemoteMachine":"","inventoryFileAnsibleMachineOnRemoteMachine":"","inventoryHostListRemoteMachine":"","inventoryInlineDynamicRemoteMachine":"false","inventoryInlineContentRemoteMachine":"","inventoriesAgentMachine":"file","inventoryFileOnAgentMachine":"$(System.DefaultWorkingDirectory)/Build-Java-CI/drop/iac/terraform/azure/inventory","inventoryHostListAgentMachine":"$(System.DefaultWorkingDirectory)/Build-CI/drop/terraform/azure/inventory","inventoryInlineDynamicAgentMachine":"false","inventoryInlineContentAgentMachine":"","sudoEnabled":"false","sudoUser":"","args":"-u azureuser --ssh-extra-args='-o StrictHostKeyChecking=no' ","failOnStdErr":"true","connectionAnsibleTower":"","jobTemplateName":""}}]}],"environmentOptions":{"emailNotificationType":"OnlyOnFailure","emailRecipients":"release.environment.owner;release.creator","skipArtifactsDownload":false,"timeoutInMinutes":0,"enableAccessToken":false,"publishDeploymentStatus":true,"badgeEnabled":false,"autoLinkWorkItems":false,"pullRequestDeploymentEnabled":false},"demands":[],"conditions":[{"name":"ReleaseStarted","conditionType":1,"value":""}],"executionPolicy":{"concurrencyCount":0,"queueDepthCount":0},"schedules":[],"currentRelease":{"id":235,"url":"https://eneros.vsrm.visualstudio.com/DemoIAC/_apis/Release/releases/235","_links":{}},"retentionPolicy":{"daysToKeep":30,"releasesToKeep":3,"retainBuild":true},"processParameters":{},"properties":{},"preDeploymentGates":{"id":0,"gatesOptions":null,"gates":[]},"postDeploymentGates":{"id":0,"gatesOptions":null,"gates":[]},"environmentTriggers":[],"badgeUrl":"https://rmprodcca1.vsrm.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/_apis/public/Release/badge/59065378-0e3f-4947-973b-212c1ff1b7a4/7/10"}],"artifacts":[{"sourceId":"59065378-0e3f-4947-973b-212c1ff1b7a4:7","type":"Build","alias":"Build-Java-CI","definitionReference":{"artifactSourceDefinitionUrl":{"id":"https://eneros.visualstudio.com/_permalink/_build/index?collectionId=59ad7d92-851b-429c-a578-a2e3c394199c&projectId=59065378-0e3f-4947-973b-212c1ff1b7a4&definitionId=7","name":""},"defaultVersionBranch":{"id":"","name":""},"defaultVersionSpecific":{"id":"","name":""},"defaultVersionTags":{"id":"","name":""},"defaultVersionType":{"id":"latestType","name":"Latest"},"definition":{"id":"7","name":"Build-Java-CI"},"project":{"id":"59065378-0e3f-4947-973b-212c1ff1b7a4","name":"DemoIAC"}},"isPrimary":true}],"triggers":[{"artifactAlias":"Build-Java-CI","triggerConditions":[],"triggerType":1}],"releaseNameFormat":"Release-$(rev:r)","tags":[],"properties":{"DefinitionCreationSource":{"$type":"System.String","$value":"ReleaseImport"}},"id":7,"name":"Java-Terraform","path":"\\","projectReference":null,"url":"https://eneros.vsrm.visualstudio.com/59065378-0e3f-4947-973b-212c1ff1b7a4/_apis/Release/definitions/7","_links":{"self":{"href":"https://eneros.vsrm.visualstudio.com/59065378-0e3f-4947-973b-212c1ff1b7a4/_apis/Release/definitions/7"},"web":{"href":"https://tfsprodcca1.visualstudio.com/A59ad7d92-851b-429c-a578-a2e3c394199c/59065378-0e3f-4947-973b-212c1ff1b7a4/_release?definitionId=7"}}} --------------------------------------------------------------------------------