Post assignment questions - pnguye35/pal-tracker GitHub Wiki

Challenge questions of Spring Boot lab: What the purpose of using "gradle wrapper"? What is a fat jar? How does Spring Boot creats one? What is 12 factor app? (Google it) One of the features of Spring Boot (actually through the Spring Boot Maven/Gradle plugin) is to create a fat jar that contains everything including Tomcat. Among the 12 factors, which factor is relevant to creating and deploying the same fat jar over different deployment environment? How does Spring Boot helps with dependency management? What does @SpringBootApplication do? What is it made of? Why we use random route in our lab? Try the following commands 12:04 cf target cf apps cf app pal-tracker cf routes cf help -a

A couple of CF plugins I would recommend to install: “open” and “mysql” from https://plugins.cloudfoundry.org/ “open”plugin opens a browser for you with the right route by typing “cf open pal-tracker” “mysql” plugin lets you access the mysql database service in the same way you were able to access your local mysql database by “cf mysql tracker-database”. The installation instruction is right there in the website above. But they are as following: cf install-plugin -r CF-Community "open" cf install-plugin -r CF-Community "mysql-plugin"

Sang 10:40 AM Challenge questions on "Configuring an App" lab: Do we have to do “cf restage ” when we set a new environment variable in PCF? What are the examples of PCF log types? (Google “PCF log types”) What could be use cases where you will have to do “cf restage” (as opposed to “cf restart”)? (Related question to the above) What are the differences among 3 different ways of deploying an application on PCF - "pushing", "restaging", and "restarting"? Try to use “create-app-manifest” command to capture the metadata of your running app into a file and try to use that file to deploy the application If you remove "random-route: true" from your manifest.yml file and then do "cf push", will it work? Why? When do you want to use @ConfigurationProperties annotation as opposed to @Value annotation? (edited)

Sang 11:03 AM Challenge Coding exercise: (Only if you have extra time and need more challenging code exercise) Modify the code so that you are using @ConfigurationProperties annotation as opposed to @Value annotation Currently we have testing code for WelcomeController that does the testing of the controller class logic but it does not test Mvc layer, which is covered by API testing using @SpringBootTest. But one trade-off of using @SpringBootTest is that it is slower than Web slice testing because it has to start the server. So you might want to write controller testing code using @WebMvcTest and MockMvc. Find out how you can use IntelliJ version control window to compare your local code against a branch or a tag. Create a WelcomeService that returns a message, WelcomeController depends on the HelloService to get that message, Use Mockito in your WebControllerMockMvcTest code to mock the service, Write the WelcomeServiceTest code to test WelcomeService.

Sang 11:20 AM Coding quiz: - Why the following code throws "ApplicationContext creation failed because .." exception? 11:21 @RestController public class WelcomeController { @Value("${welcome.message}") private String welcomeMessage; public WelcomeController( String welcomeMessage ) { this.welcomeMessage = welcomeMessage; } @GetMapping("/") public String sayHello() { return welcomeMessage; } }

Eshwar MV 11:24 AM joined liveonli-jun-2020-cnd.

Sang 2:07 PM Challenge questions on routing: 2:07 We know multiple routes can be assigned to an applicationh. Now can a route be assigned to multiple applications? Anybody knows what “blue-green-deployment” is? Speaking “blue-green deployment”, anybody can think of conceptual steps you will take in PCF environment? How can we control the ratio of the traffic between V1.0.1 (blue) vs. V1.0.2 (green)? Can a route exist without an application associated with it? (See “cf routes” and “cf create-route” commands.) What could be the use case of "cf create-route"? When mapping or unmapping routes, do you have to restart or restage an application? How can you delete all routes that are not associated with any apps? Can you describe which PCF components are responsible for updating the routing table whenever a new instance is created or old instance gets destroyed?

Sang 2:26 PM Challenge questions on blue-green deployment: 2:27 Is blue-green deployment suitable for major feature change? What are the challenges for doing blue-green deployment? What about table change - don't delete field, don't delete tables 2:28 Challenge exercise:

Sang 2:29 PM Create v2 of pal-tracker Perform blue-green deployment (do your deployment using cf push for the exercise) (edited)

4 replies Last reply 1 day agoView thread

Sang 2:49 PM The following is the steps you can take for blue-green deployment: 2:50 V1 - R1 is currently running Create V2 with R2 and make sure it is working (cf push pal-tracker-v2 -p ./build/libs/pal-tracker-v2.jar -n pal-tracker-r2) Add R1 to V2 - now V2 handles both R1 and R2 (cf map-route pal-tracker-v2 apps.evans.pal.pivotal.io -n pal-tracker-r1) Remove R1 from V1 - now V2 handles 100% of R1 (cf unmap-route pal-tracker-v1 apps.evans.pal.pivotal.io -n pal-tracker-r1) Remove R2 from V2 - now V2 handles only R1 (cf unmap-route pal-tracker-v2 apps.evans.pal.pivotal.io -n pal-tracker-r2)

Sang 3:23 PM If you want to save your changes into a branch do the following: By the way, before you do the above step, if you need to save your current unfinished work into “work in progress” branch so that you can work on that on later time, you do the following:

  • git checkout -b wip-branch
  • git add .
  • git commit -m “work in progress in my lab”
  • git push origin wip-branch --tags 3:23 If you want to get a solution project and move one, the following is the steps to take:
  • git checkout master
  • git reset --hard
  • change manifest files to reflect correct domain and route in manifest file like: - route: pal-tracker-sang-shin.apps.evans.pal.pivotal.io
  • Do the lab work
  • git add-commit -m “my work done”
  • git push origin master -f (to force the remote master to sync with local master - do not to this in production! :-))

Bill Kable 4:43 PM Git cheatsheet: https://www.git-tower.com/blog/git-cheat-sheet/ git-tower.comgit-tower.com Git Cheat Sheet Tower Blog - About Web and Software Development, Marketing and Design(85 kB) https://www.git-tower.com/blog/media/pages/posts/git-cheat-sheet/1744668794-1590818205/[email protected]

Sang 4:48 PM Challenge questions on “Spring Mvc with REST endpoints” lab: What are the differences between unit testing vs integration testing vs end-to-end testing? In “pal-tracker” project, which tests are unit testing? integrating testing or end-to-end testing? Can you do “integration” or “end-to-end” testing as part of CI/CD pipeline? What are differences between RestTemplate vs TestRestTemplate? From unit-testing standpoint, why is it a bad practice to create a dependency object inside your class using “new” keyword or even using factory (as opposed to getting it injected either through constructor method or setting method)? What is the another way of creating InMemoryTimeEntryRepository bean other than using @Bean in the configuration class? What would be pros and cons of each approach? What does SOLID (design principles) stand for? What are the examples of “Open for extension Closed for modification” design principle in the “pal-tracker” project? When do you want to use @SpringBootTest vs @ContextConfiguration for your integration testing that involves Spring application context? Why TimeEntryControllerTest code needs mocking while InMemoryTimeEntryRepositoryTesting code doesn’t? What is the difference between stubbing and mocking? When do you want use stubbing over mocking and vice-versa? What is the reason controller TimeEntryControllerTest code has “verify” method? If you have classes in a tree structure (for example, Class A has dependencies of class B and C and class B has a dependency D, in other words, class A and B has dependencies while class C has no dependencies), which class do you want to do Unit testing and which classes you want to do integration testing? What about a class that depends on backing services such as database? How will you perform the integration testing? What happens to the in-memory data when the application instances come and go? A couple of CF plugins I would recommend to install: “open” and “mysql” from https://plugins.cloudfoundry.org/ “open”plugin opens a browser for you with the right route by typing “cf open pal-tracker” “mysql” plugin lets you access the mysql database service in the same way you were able to access your local mysql database by “cf mysql tracker-database”. The installation instruction is right there in the website above. But they are as following: cf install-plugin -r CF-Community "open" cf install-plugin -r CF-Community "mysql-plugin" 12:57 The following is an example of how to use mysql plugin: Challenge question on “JdbcTemplate” lab: We know that when we are running pal-tracker app locally, Spring Boot auto-configure a DataSource bean from the environment-variable provided database credentials, which is then used to auto-confire JdbcTemplate bean. Now when we deploy the same application to PCF, somehow different DataSource bean gets auto-configured from database credentials from the VCAP_SERVICES. How does PCF do this? (See the following for a clue https://docs.run.pivotal.io/buildpacks/java/configuring-service-connections/spring-service-bindings.html) Suppose I have some VCAP_SERVICES environment variables that I need to read in my Spring Boot application, is there any helper utility? (See the following for a clue https://stackoverflow.com/questions/50456365/how-to-inject-user-provided-vcap-services-in-spring-boot)