Skip to content

Commit

Permalink
add sample app and enablement script
Browse files Browse the repository at this point in the history
  • Loading branch information
pxaws committed Nov 30, 2023
1 parent e7e5b6c commit 2678ccb
Show file tree
Hide file tree
Showing 207 changed files with 25,643 additions and 9 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Maven
target/
!.mvn/wrapper/maven-wrapper.jar

# Jenv
.java-version

# Eclipse
.settings/
.classpath
.project

# IntelliJ IDEA
.idea
*.iml

# Visual Studio Code
.factorypath

# Branch switching
generated/

# Mac OS
*.DS_Store
117 changes: 117 additions & 0 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;

public class MavenWrapperDownloader {

private static final String WRAPPER_VERSION = "0.5.4";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + " .jar";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}

}
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.4/maven-wrapper-0.5.4.jar
114 changes: 105 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,113 @@
## My Project
# Introduction
This is a modified version of the [spring-petclinic-microservices](https://github.com/spring-petclinic/spring-petclinic-microservices) Spring Boot sample application.
Our modifications focus on showcasing the capabilities of Application Signals within a Spring Boot environment.
If your interest lies in exploring the broader aspects of the Spring Boot stack, we recommend visiting the original repository at [spring-petclinic-microservices](https://github.com/spring-petclinic/spring-petclinic-microservices).

TODO: Fill this README out!
In the following, we will focus on how customers can set up the current sample application to explore the features of Application Signals.

Be sure to:
# Prerequisite
* A Linux or Mac machine with x86-64 (AMD64) architecture is required for building Docker images for the sample application.
* Docker is installed and running on the machine.
* AWS CLI 2.x is installed. For more information about installing the AWS CLI, see [Install or update the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).
* kubectl is installed - https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html
* eksctl is installed - https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html
* jq is installed - https://jqlang.github.io/jq/download/

* Change the title in this README
* Edit your repository description on GitHub
# EKS demo

## Security
## Build the sample application images and push to ECR
1. Build container images for each micro-service application

See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
```
./mvnw clean install -P buildDocker
```

## License
2. Create an ECR repo for each micro service and push the images to the relevant repos. Replace the aws account id and the AWS Region.

```
export ACCOUNT='111122223333'
export REGION='us-east-1'
./push-ecr.sh
```

This project is licensed under the Apache-2.0 License.
## Try Application Signals with the sample application
1. Create an EKS cluster, enable Application Signals, and deploy the sample application to your EKS cluster. Replace `new-cluster-name` with the name that you want to use for the new cluster. Replace `region-name` with the same region in previous section "**Build the sample application images and push to ECR**".

```
cd scripts/eks/appsignals/one-step && ./setup.sh new-cluster-name region-name
```

2. Clean up all the resources. Replace `new-cluster-name` and `region-name` with the same values that you use in previous step.

```
cd scripts/eks/appsignals/one-step && ./cleanup.sh new-cluster-name region-name
```


# EC2 Demo
The following instructions describe how to set up the pet clinic sample application on EC2 instances. You can run these steps in your personal AWS account to follow along.

1. Clone this repository and run `./mvnw clean install`
2. Set up an S3 bucket in your account and put the created JAR files into it
3. Set up a VPC with a public subnet and a security group accepting all traffic.
4. Set up 5 EC2 instances all with the following configuration:
- Running on Amazon Linux
- Instance type t2.small or larger
- A key-pair you save to your computer
- Use the VPC, public subnet, and security group created in step 1
- Enable auto-assign public IP
- An IAM instance profile with the following permissions:
- AmazonDynamoDBFullAccess
- AmazonKinesisFullAccess
- AmazonS3FullAccess
- AmazonSQSFullAccess
5. Rename your instances as follows to follow along with the instructions:
- setup
- pet-clinic-frontend
- vets
- customers
- visits
6. Connect to the EC2 instance named setup and run the following commands to start the config, discovery, and admin services:

```
sudo yum install java-1.8.0
aws s3 sync s3://<S3-bucket-name> .
screen -S config
java -jar spring-petclinic-config...
```
Leave the config service `screen` session by inputting `ctrl+a, d`.
```
clear
screen -S discovery
java -jar spring-petclinic-discovery...
```
Leave the discovery service `screen` session by inputting `ctrl+a, d`.
```
clear
screen -S admin
java -jar spring-petclinic-admin...
```
Leave the admin service `screen` session by inputting `ctrl+a, d`.
Feel free to end your connection to the EC2 instance, the screens will continue running.

7. Connect to the EC2 instance named pet-clinic-frontend and run the following commands to start the api-gateway service. Make sure to replace the private IP in the export commands.
```
sudo yum install java-1.8.0
aws s3 sync s3://<S3-bucket-name> .
export CONFIG_SERVER_URL=http://<PRIVATE-IP-OF-SETUP-INSTANCE>:8888
export DISCOVERY_SERVER_URL=http://<PRIVATE-IP-OF-SETUP-INSTANCE>:8761/eureka
screen -S frontend
java -jar spring-petclinic-api-gateway...
```
Leave the api-gateway service `screen` session by inputting `ctrl+a, d`.
Feel free to end your connection to the EC2 instance, the screen will continue running the service

8. Repeat step 7 for the remaining EC2 instances (vets, customers, visits)

9. Visit the sample application by going to http://<PUBLIC-IPv4-DNS-OF-PET-CLINIC-FRONTEND-INSTANCE>:8080

10. Interact with the application to ensure you've properly set up the backend services. Note that each service takes a few seconds to come up.


To enable Application Signals on the sample application, please refer to [this user guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-EC2.html).

Loading

0 comments on commit 2678ccb

Please sign in to comment.