Skip to content

Commit

Permalink
Deployment improvements (#82)
Browse files Browse the repository at this point in the history
* adding non-null check for connection

* updating the SAL deployment files

* formatting update

(cherry picked from commit 3e0e113)
  • Loading branch information
ankicabarisic authored and fviale committed Aug 12, 2024
1 parent a391b4f commit 8ac68de
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
4 changes: 2 additions & 2 deletions deployment/sal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ spec:
- name: PWS_URL
value: http://158.39.77.68:8880/
- name: PWS_USERNAME
value: admin
value: <PROACTIVE_USERNAME>
- name: PWS_PASSWORD
value: admin
value: <PROACTIVE_PASSWORD>
- name: DB_USERNAME
value: root
- name: DB_PORT
Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ENV DB_URL='jdbc:mariadb://localhost:3306/proactive'
ENV DB_PLATFORM='org.hibernate.dialect.MariaDB53Dialect'

CMD ["catalina.sh", "jpda", "run"]
#RUN yum install -y nmap-ncat
#RUN chmod +x /usr/local/tomcat/bin/wait_for_db.sh
#CMD ["/bin/bash", "-c", "wait_for_db.sh && catalina.sh jpda run"]
RUN yum install -y nmap-ncat
RUN chmod +x /usr/local/tomcat/bin/wait_for_db.sh
CMD ["/bin/bash", "-c", "wait_for_db.sh && catalina.sh jpda run"]

33 changes: 33 additions & 0 deletions docker/Dockerfile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM tomcat:9.0.68-jdk8-corretto-al2

RUN rm -rf ${CATALINA_HOME}/webapps/*
# NOTE: Switch between local or public builded SAL
RUN curl -o /usr/local/tomcat/webapps/sal.war http://repository.activeeon.com/content/groups/proactive/org/ow2/proactive/scheduling-abstraction-layer/13.1.0-SNAPSHOT/scheduling-abstraction-layer-13.1.0-20221027.125525-9.war
COPY sal-service/build/libs/scheduling-abstraction-layer-*.war /usr/local/tomcat/webapps/sal.war

ENV EXTERNAL_CONFIG_DIR=${CATALINA_HOME}/conf
ENV PROPERTIES_FILENAME='sal'

ENV PA_HOME=${CATALINA_HOME}

COPY docker/scheduling-abstraction-layer.xml ${EXTERNAL_CONFIG_DIR}/Catalina/localhost/sal.xml
# NOTE: Please make sure if you set a different `PROPERTIES_FILENAME` to copy your properties file inside the container
COPY docker/sal.application.properties ${EXTERNAL_CONFIG_DIR}/${PROPERTIES_FILENAME}.properties
COPY docker/wait_for_db.sh /usr/local/tomcat/bin

ENV PWS_URL='http://localhost:8080/'
ENV PWS_USERNAME='admin'
ENV PWS_PASSWORD='admin'

ENV DB_USERNAME='root'
ENV DB_PASSWORD=''

ENV DB_DRIVER_CLASSNAME='org.mariadb.jdbc.Driver'
ENV DB_URL='jdbc:mariadb://localhost:3306/proactive'
ENV DB_PLATFORM='org.hibernate.dialect.MariaDB53Dialect'

CMD ["catalina.sh", "jpda", "run"]
#RUN yum install -y nmap-ncat
#RUN chmod +x /usr/local/tomcat/bin/wait_for_db.sh
#CMD ["/bin/bash", "-c", "wait_for_db.sh && catalina.sh jpda run"]

9 changes: 4 additions & 5 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ cd <SAL_REPO_HOME_DIR>

./gradlew spotlessApply clean build --refresh-dependencies

cd <DOCKEE_SAL_DIR>
cd <DOCKER_SAL_DIR>

rm -f ./artefacts/scheduling-abstraction-layer-13.1.0-SNAPSHOT.war

cp <SAL_REPO_HOME_DIR>/sal-service/build/libs/scheduling-abstraction-layer-13.1.0-SNAPSHOT.war ./artefacts

docker-compose down

docker build -t activeeon/sal:latest -f ./Dockerfile --no-cache .
docker build -t activeeon/sal:test -f ./Dockerfile --no-cache .

docker-compose up


```
> NOTE: Please change <SAL_REPO_HOME_DIR> and <DOCKEE_SAL_DIR> for the correct ones.
> NOTE: Please change `<SAL_REPO_HOME_DIR>` and `<DOCKER_SAL_DIR>` to the correct ones. In case SAL is built on Windows, use `./Dockerfile.win` instead of `./Dockerfile`.

Each time the code is modified in <SAL_REPO_HOME_DIR>, you can simple run this script and it will automatically launch new container with the changes included.
Each time the code is modified in `<SAL_REPO_HOME_DIR>`, you can run this script and it will automatically launch a new container with the changes included.
9 changes: 7 additions & 2 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
database:
image: mariadb
image: mariadb #optionaly set specific version e.g. mariadb:10.7
ports:
- "3307:3306"
networks:
Expand All @@ -15,9 +15,13 @@ services:
timeout: 5s
retries: 5
sal:
#Set up image to be used for SAL from https://hub.docker.com/r/activeeon/sal/tags
image: activeeon/sal:test
build:
context: ..
#Set up Dockerfile to be used:
#Dockerfile is used for Jenkins image creation
#Dockerfile.win to be used for local build on Windows
dockerfile: ./docker/Dockerfile
depends_on:
database:
Expand All @@ -33,6 +37,7 @@ services:
- ./scripts:/usr/local/tomcat/scripts
environment:
PROPERTIES_FILENAME: sal
#Set up connection to ProActive server (PWS)
PWS_URL: <CHANGE_ME>
PWS_USERNAME: <CHANGE_ME>
PWS_PASSWORD: <CHANGE_ME>
Expand All @@ -49,4 +54,4 @@ services:

networks:
# The presence of these objects is sufficient to define them
db-tier: {}
db-tier: {}
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,24 @@ public static JSONObject sendGetRequestAndReturnObjectResponse(URI requestUri) {
@SneakyThrows
public static JSONArray sendGetArrayRequestAndReturnArrayResponse(URI requestUri) throws IOException {
HttpURLConnection connection = null;
BufferedReader br = null;
JSONArray result = new JSONArray();

try {
connection = (HttpURLConnection) requestUri.toURL().openConnection();
connection.setRequestMethod(HttpMethod.GET.toString());
LOGGER.debug("requestUri = {}", requestUri);

br = sendGetRequestAndReturnBufferedResponse(connection);
if (br != null) {
result = new JSONArray(new JSONTokener(br));
// Check if connection is successfully established
if (connection != null) {
try (BufferedReader br = sendGetRequestAndReturnBufferedResponse(connection)) {
if (br != null) {
result = new JSONArray(new JSONTokener(br));
} else {
LOGGER.warn("No response received from request to {}", requestUri);
}
}
} else {
LOGGER.warn("No response received from request to {}", requestUri);
LOGGER.error("Failed to establish connection to {}", requestUri);
}
} catch (IOException e) {
LOGGER.error("IO exception occurred while making request to {}: {}", requestUri, e.getMessage(), e);
Expand All @@ -108,13 +113,6 @@ public static JSONArray sendGetArrayRequestAndReturnArrayResponse(URI requestUri
e);
throw new IOException("Unexpected error occurred", e); // Wrap and throw as IOException
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
LOGGER.warn("Failed to close BufferedReader: {}", e.getMessage(), e);
}
}
if (connection != null) {
connection.disconnect();
}
Expand Down

0 comments on commit 8ac68de

Please sign in to comment.