Skip to content
This repository was archived by the owner on Mar 25, 2018. It is now read-only.

TEAMMEME_INFRA_HOUR3 #42

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Dockerfile
Empty file.
157 changes: 157 additions & 0 deletions INSTRUCTIONS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#
#
# Working in a fresh Ubuntu 16.04 AWS cloud environment.
# https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Instances:sort=instanceId
# NOTE: CHECK IN ADVANCE THE STACK TRACE AT THE END OF THIS DOCUMENT.
#
# This may help you, "...pem" might be the path to your PEM file if it's not in ~/.ssh/. "-R" is to enable rsub/rmate with sublime, but you may want the first ssh option.
# ssh ubuntu@ec2-52-91-103-145.compute-1.amazonaws.com
# ssh -i ...pem ubuntu@ec2-52-91-103-145.compute-1.amazonaws.com
# ssh -R 52698:localhost:52698 -i ...pem ubuntu@ec2-52-91-103-145.compute-1.amazonaws.com
#
#
sudo apt install docker
sudo apt update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
uname -r
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt update
sudo apt-get install docker-ce
sudo docker run hello-world
mkdir ~/Documents
mkdir ~/Documents/wilau2/
cd ~/Documents/wilau2/
git clone https://github.com/guillaume-chevalier/cs-games-2018-relay-cloud
ls
cd cs-games-2018-relay-cloud/
git status
ls
# rsub gradle.bat
# sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate
# sudo chmod +x /usr/local/bin/rsub
# rsub gradle.bat
# cat gradle.bat
# ls
./gradlew clean build
java --version
java -version
ls /usr/lib/jvm/open-jdk
ls /usr/lib/jvm/
ls /usr/lib/
sudo apt install default-jre default-jdk
# Not installed from here, possible to for java8:
# sudo add-apt-repository ppa:webupd8team/java
# sudo apt update
# sudo apt-get install oracle-java8-installer
./gradlew clean build
docker pull redis:4.0.8-alpine
sudo -H docker pull redis:4.0.8-alpine
screen -L
# This was done in screen session:
# sudo -H docker run --name redis -p 6379:6379 redis:4.0.8-alpine
# sudo docker run redis:4.0.8-alpine
# CTRL+A+D to exit screen session
ls config-server/src/main/resources
cat config-server/src/main/resources/application.yml
screen -L
# In the screen session, run this and then CTRL+A+D to exit softly:
# ./gradlew :config-server:bootRun -Dspring.profiles.active=native
# Now, back outside screen:
curl -L http://configUser:configPassword@localhost:8888/config/eureka-server.yml -o eureka-server.yml
cat eureka-server.yml
# git add eureka-server.yml
# You should see "eureka:" and a few lines, I think. There is a meme under this car.
screen -L
# Yet another screen session in parallel to others, do this then CTRL+A+D:
# ./gradlew :eureka-server:bootRun -Dspring.profiles.active=native
curl -L http://discUser:discPassword@localhost:8082/eureka/apps -o test2.txt


# NOTE: FROM THIS POINT ON, MY SERVER FROZE AND I NEEDED A RESTART. HERE IS THE RECUPERATED STACK TRACE FROM SCREEN SESSION:
# HERE IS STACK TRACE:

# $ tail -100 screenlog.0
# at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_151]
# a<=========----> 75% EXECUTING [3m 42s]
# > :eureka-server:bootRun
# ksSocketImpl.java:392) ~[na:1.8.0_151]
# at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_151]
# at <=========----> 75% EX<=========---- at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.5.jar:4.5.5]
# at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.5.jar:4.5.5]lient-4.5.5.jar:4.5.5]
# at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) ~[httpclient-4.5.5.jar:4.5.5]
# at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) ~[httpclient-4.5.5.jar:4.5.5]
# at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.5.jar:4.5.5]
# <=========[0;3<=========----> 75% EXECUTING [3m 52s]t.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.5.jar:4.5.5]
# <===> :config-serve> :eureka-server:bootRun
# <==B====== at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.5.jar:4.5.5]
# at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
# ... 27 common frames omitted
#
# 2018-03-24 18:37:59.661 WARN 12223 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
# 2018-0<=========----> 75% EXECUTING [4m 3s]
# 2018-03-24 18:38:01.043 ERROR 12223 --- [scoveryClient-0] c.netflix.discovery.TimedSupervisorTask : task supervisor timed out
#
# java.util.concurrent.TimeoutException: null
# at java.util.concurrent.FutureTask.get(FutureTask.java:205) [na:1.8.0_151]
# at com.netflix.discovery.TimedSupervisorTask.run(TimedSupervisorTask.java:63) ~[eureka-client-1.7.0.jar:1.7.0]
# at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_151]
# at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151]
# at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151]
# at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_151]
# at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
# at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
# at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
#
# 2018-03-24 18:38:01.030 WARN 12223 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-SERVER/ip-172-31-53-96.ec2.internal:config-server:8888 - registration failed Cannot execute request on any known server
#
# com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
# at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.7.0.jar:1.7.0]
# at at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104) [eureka-client-1.7.0.jar:1.7.0]reka-client-1.7.0.jar:1.7.0]
# at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_151]nt-1.7.0.jar:1.7.0]
# at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151]
# at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151]
# at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_151]
# at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
# at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
# at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
#
# 2018-03-24 18:38:01.030 ERROR 12223 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-SERVER/ip-172-31-53-96.ec2.internal:config-server:8888 - was unable to send heartbeat!
#
# com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
# at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.sendHeartBeat(EurekaHttpClientDecorator.java:89) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$3.execute(EurekaHttpClientDecorator.java:92) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.sendHeartBeat(EurekaHttpClientDecorator.java:89) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.DiscoveryClient.renew(DiscoveryClient.java:824) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.DiscoveryClient$HeartbeatThread.run(DiscoveryClient.java:1388) [eureka-client-1.7.0.jar:1.7.0]
# at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_151]
# at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151]
# at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
# at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
# at java.lang.Thread.run(Thread.java:748) [na:1.8.0<=========----> 75% EXECUTING [4m 12s]
# > :eureka-server:bootRun
# 2018-03-24 18:38:02.350 ERROR 12223 --- [freshExecutor-0] d.RedirectingEurekaHttpClient : Request execution error
#
# com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)
# at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
# at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
# at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
# at at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509) ~[jersey-client-1.19.1.jar:1.19.1]
# at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplicationsInternal(AbstractJerseyEurekaHttpClient.java:194) ~[eureka-client-1.7.0.jar:1.7.0]
# at com.netflix.discovery.shared.transport.jersey.Abstrac<=========----> 75% EXECUTING [4m 22s]
# > :eureka-<=========----> 75% EXECUTING [8m 51s] > :eureka-server:bootRun
# > :config-server:bootRun ekaHttpClient.getApplications(AbstractJerseyEurekaHttpClient.java:165) ~[eureka-client-1.7.0.jar:1.7.0]
# <=========----> 75% EXECUTING [4m 28s]
# > :eureka-server:bootRun
#


9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Java micro-services

## To improve in the architecture.

For what concerns security, we should expose as few ports as possible and have only secure calls from the outside, but security here is not the question here... Let's answer this for real now.

It seems that we need to start many microservices in parallel, the architecture is scattered there and there. This is tedious and the web app could be more self-contained. In just an hour, analysing this feels heavy. There is too much complexity in this project for such as scope. No localhost things called amid the code execution would be a good thing to have. Doing local API calls is inefficient in a local environment, both in term of software engineering, development, time spent, and material resources. We should just call code with packages in java rather than always passing trough many ridiculous REST APIS. Those excessive APIS consumes more RAM than it should, take more time to devlelop, are too complex, and on. I would work on simplifying the system and making it more lightweight on the architecture side.

What I would do with unilimited time is to find a way to merge those different services into one clean service to start. If needed, the database can still be left as a different microservice running elsewhere: it's common practice to decouple storage layers from business logic. It could me more clear how and when to use docker and graddle.


## Build
build all projects
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.Assert;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;
import java.io.Serializable;
Expand All @@ -26,6 +30,7 @@ public class Message implements Serializable {

@Column(nullable = false)
private String sender;
private static List<String> ranks = Arrays.asList("CREWMAN", "ENSIGN", "LIEUTENANT", "COMMANDER", "CAPTAIN", "VICE_ADMIRAL", "ADMIRAL");

@JsonCreator
public Message(@JsonProperty("id") Long id,
Expand All @@ -34,6 +39,9 @@ public Message(@JsonProperty("id") Long id,
@JsonProperty("recipient") String recipient,
@JsonProperty("sender") String sender
) {
int senderRank = ranks.indexOf(sender);
int recipientRank = ranks.indexOf(recipient);
Assert.isTrue(recipientRank <= senderRank + 1, "Cannot send message");
this.id = id;
this.title = title;
this.content = content;
Expand Down
13 changes: 13 additions & 0 deletions eureka-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
eureka:
client:
fetchRegistry: false
region: default
registerWithEureka: false
registryFetchIntervalSeconds: 5
server:
port: 8082
spring:
application:
name: eureka-server
redis:
port: 6379
Loading