<commit_before>## what is it?
This is a sample running multiple [Tomcats](http://tomcat.apache.org/) and a [Apache WebServer](http://httpd.apache.org/) for load balancing using a central Configuration Service [etcd](https://github.com/coreos/etcd).

The main subject under test is [confd](https://github.com/kelseyhightower/confd). It is a tiny  useful tool to move distributed local configuration files to a central configuration repositories a la [etcd](https://github.com/coreos/etcd), [redis](http://redis.io), [consul](http://consul.io), [dynamodb](http://aws.amazon.com/dynamodb/), [zookeeper](https://zookeeper.apache.org).   

## what is it doing?
Apache Tomcat uses config files e.g. tomcat-users.xml to define access rights to the manager webapp. Here the admin user shall be configured centrally, so we can define it within etcd.

Supported Tomcat configurations in etcd with the prefix tomcat:
- Xmx: maximum heap size
- Xms: initial heap size
- username: manager webapp username
- password: <PASSWORD>
- jvmRoute: this is set to hostname defined in docker-compose.yml

## run it
This sample uses Vagrant and VMware or VirtualBox - but this is optional. You can run the containers in your prefered Docker environment. 

```
vagrant plugin list
vagrant plugin install vagrant-docker-compose
```
Clone this repo, run 
```
cd tomcat-confd
vagrant up
```
Find out the IP of your VM. Open your Browser, go to Tomcat Manager e.g.
http://192.168.xx.xx:8081/manager/
login with Username admin and Password admin

## some interesting code snippets

manually rebuild everything within the VM
```
sudo su -
cd /vagrant/docker
docker-compose stop && docker-compose rm -f && docker-compose build
docker-compose up --force-recreate
```

open another bash - fill in the required etcd keys

```
curl -L http://localhost:2379/v2/keys/tomcat/Xmx -XPUT -d value='1024M' && \
curl -L http://localhost:2379/v2/keys/tomcat/Xms -XPUT -d value='512M' && \
curl -L http://localhost:2379/v2/keys/tomcat/user -XPUT -d value='admin' && \
curl -L http://localhost:2379/v2/keys/tomcat/password -XPUT -d value='<PASSWORD>'

# by the way: The order matters: this is not always working (!)
curl -L http://localhost:2379/v2/keys/tomcat/user -XPUT -d value='admin' && \
curl -L http://localhost:2379/v2/keys/tomcat/password -XPUT -d value='<PASSWORD>' && \
curl -L http://localhost:2379/v2/keys/tomcat/Xmx -XPUT -d value='1024M' && \
curl -L http://localhost:2379/v2/keys/tomcat/Xms -XPUT -d value='512M' 

```

debug confd - e.g. if templates are ok
```
/usr/local/bin/confd -onetime -backend etcd -node docker_etcdservice_1:4001
```

or manually build the tomcat Docker image within the VM :)
```
sudo su -
cd /vagrant/docker/tomcat
docker build -t docker_tomcatservice .

cd /vagrant/docker
docker-compose up
```

todo:
/usr/local/tomcat/webapps/manager/whoIsIt.html
<commit_msg>wording<commit_after>## what is it?
This is a sample running multiple [Tomcats](http://tomcat.apache.org/) and a [Apache WebServer](http://httpd.apache.org/) for load balancing using a central Configuration Service [etcd](https://github.com/coreos/etcd).

The main subject under test is [confd](https://github.com/kelseyhightower/confd). It is a tiny  useful tool to move distributed local configuration files to a central configuration repositories a la [etcd](https://github.com/coreos/etcd), [redis](http://redis.io), [consul](http://consul.io), [dynamodb](http://aws.amazon.com/dynamodb/), [zookeeper](https://zookeeper.apache.org).   

## what is it doing?
Apache Tomcat uses config files e.g. tomcat-users.xml to define access rights to the manager webapp. Here the admin user shall be configured centrally, so we can define it within etcd.

Supported Tomcat configurations that can be done in etcd under the prefix 'tomcat':
- Xmx: maximum heap size
- Xms: initial heap size
- username: manager webapp username
- password: <PASSWORD>
- jvmRoute: this is set to hostname defined in docker-compose.yml

## run it
This sample uses Vagrant and VMware or VirtualBox - but this is optional. You can run the containers in your prefered Docker environment. 

```
vagrant plugin list
vagrant plugin install vagrant-docker-compose
```
Clone this repo, run 
```
cd tomcat-confd
vagrant up
```
Find out the IP of your VM. Open your Browser, go to Tomcat Manager e.g.
http://192.168.xx.xx:8081/manager/
login with Username admin and Password admin

## some interesting code snippets

manually rebuild everything within the VM
```
sudo su -
cd /vagrant/docker
docker-compose stop && docker-compose rm -f && docker-compose build
docker-compose up --force-recreate
```

open another bash - fill in the required etcd keys

```
curl -L http://localhost:2379/v2/keys/tomcat/Xmx -XPUT -d value='1024M' && \
curl -L http://localhost:2379/v2/keys/tomcat/Xms -XPUT -d value='512M' && \
curl -L http://localhost:2379/v2/keys/tomcat/user -XPUT -d value='admin' && \
curl -L http://localhost:2379/v2/keys/tomcat/password -XPUT -d value='<PASSWORD>'

# by the way: The order matters: this is not always working (!)
curl -L http://localhost:2379/v2/keys/tomcat/user -XPUT -d value='admin' && \
curl -L http://localhost:2379/v2/keys/tomcat/password -XPUT -d value='<PASSWORD>' && \
curl -L http://localhost:2379/v2/keys/tomcat/Xmx -XPUT -d value='1024M' && \
curl -L http://localhost:2379/v2/keys/tomcat/Xms -XPUT -d value='512M' 

```

debug confd - e.g. if templates are ok
```
/usr/local/bin/confd -onetime -backend etcd -node docker_etcdservice_1:4001
```

or manually build the tomcat Docker image within the VM :)
```
sudo su -
cd /vagrant/docker/tomcat
docker build -t docker_tomcatservice .

cd /vagrant/docker
docker-compose up
```

todo:
/usr/local/tomcat/webapps/manager/whoIsIt.html

{'fraction_non_alphanumeric': 0.1261904761904762, 'fraction_numerical': 0.02346938775510204, 'mean_word_length': 3.5766536964980546, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1931138', 'n_tokens_mistral': 2178, 'n_tokens_neox': 1963, 'n_words': 628}