Skip to content

Commit

Permalink
use serverProperties API to pull view defaults from server rather tha…
Browse files Browse the repository at this point in the history
…n rely upon query parameters (from configured/hacked root context)
  • Loading branch information
trautmane committed Apr 15, 2018
1 parent 8532484 commit e53d520
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 99 deletions.
28 changes: 18 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
# ======================================================================================
# Stage 0: builder
# Stage 0: build_environment
#
# Install library dependencies before actually building source.
# This caches libraries into an image layer that can be reused when only source code has changed.

FROM openjdk:8-jdk as builder
FROM openjdk:8-jdk as build_environment
LABEL maintainer="Forrest Collman <[email protected]>, Eric Trautman <[email protected]>"

RUN apt-get update && apt-get install -y maven

# ---------------------------------
# Install library dependencies before actually building source.
# This caches libraries into an image layer that can be reused when only source code has changed.

WORKDIR /var/www/render/
COPY pom.xml .
COPY docs/pom.xml render-app/pom.xml
COPY render-app/pom.xml render-app/pom.xml
COPY render-ws/pom.xml render-ws/pom.xml
COPY render-ws-java-client/pom.xml render-ws-java-client/pom.xml
COPY render-ws-spark-client/pom.xml render-ws-spark-client/pom.xml
COPY render-app/pom.xml render-app/pom.xml
COPY trakem2-scripts/pom.xml trakem2-scripts/pom.xml
COPY docs/pom.xml docs/pom.xml

# use -T 1C option to multi-thread maven, using 1 thread per available core
RUN mvn -T 1C verify clean --fail-never

# ---------------------------------
# ======================================================================================
# Stage 1: builder
#
# Build the source code, save resulting jar and war files, and remove everything else

FROM build_environment as builder

COPY . /var/www/render/
RUN mvn clean

# use -T 1C maven option to multi-thread process
# use -T 1C option to multi-thread maven, using 1 thread per available core
RUN mvn -T 1C -Dproject.build.sourceEncoding=UTF-8 package && \
mkdir -p /root/render-lib && \
mv */target/*.*ar /root/render-lib && \
Expand All @@ -38,7 +44,9 @@ RUN mvn -T 1C -Dproject.build.sourceEncoding=UTF-8 package && \
rm -rf /root/.embedmongo

# ======================================================================================
# Stage 1: render-ws
# Stage 2: render-ws
#
# Once web service application is built, set up jetty server and deploy application to it.

# NOTE: jetty version should be kept in sync with values in render/render-ws/pom.xml and render/render-ws/src/main/scripts/install.sh
FROM jetty:9.4.6-jre8-alpine as render-ws
Expand Down
15 changes: 11 additions & 4 deletions docs/src/site/markdown/render-ws-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ To build the full render-ws image:
docker build -t render-ws:latest --target render-ws .
```

You can speed up future builds by building and tagging the build environment:

```bash
# cd to root directory of render repo (where Dockerfile is located)
docker build -t render-ws-build-environment:latest --target build_environment .
```

To build just the web service JARs without deploying into a Jetty container:

```bash
Expand All @@ -25,7 +32,7 @@ docker build -t render-ws:latest-build --target builder .
To run the full render-ws image:

```bash
# with database running on same host at default port
# with database running on same host at default port and no authentication
docker run -p 8080:8080 -e "MONGO_HOST=localhost" --rm render-ws:latest

# with customized environment variables in a file (named dev.env)
Expand Down Expand Up @@ -60,7 +67,7 @@ MONGO_CONNECTION_STRING_USES_AUTH=n
MONGO_HOST=
MONGO_PORT=

# if authentication is not needed, leave these empty
# if authentication is not needed (or you are using a connection string), leave these empty
MONGO_USERNAME=
MONGO_PASSWORD=
MONGO_AUTH_DB=
Expand All @@ -71,7 +78,7 @@ MONGO_AUTH_DB=
JAVA_OPTIONS=-Xms3g -Xmx3g -server -Djava.awt.headless=true

# ---------------------------------
# Web Service Threadpool Parameters
# Web Service Threadpool Parameters (leave these alone unless you really know what you are doing)

JETTY_THREADPOOL_MIN_THREADS=10
JETTY_THREADPOOL_MAX_THREADS=200
Expand All @@ -90,7 +97,7 @@ LOG_JETTY_JANELIA_LEVEL=WARN
# ---------------------------------
# Web Service Rendering Parameters

# use this to improve dynamic rendering speed for zoomed-out views
# use this to improve dynamic rendering speed for zoomed-out views,
# views that contain more than this number of tiles will have bounding boxes rendered instead of actual tile content
WEB_SERVICE_MAX_TILE_SPECS_TO_RENDER=20

Expand Down
61 changes: 1 addition & 60 deletions render-ws/src/main/scripts/docker/render-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,63 +158,4 @@ sed -i """
[email protected]=.*@view.renderStackProject=${VIEW_RENDER_STACK_PROJECT}@
[email protected]=.*@webService.maxTileSpecsToRender=${WEB_SERVICE_MAX_TILE_SPECS_TO_RENDER}@
[email protected]=.*@webService.maxImageProcessorCacheGb=${WEB_SERVICE_MAX_IMAGE_PROCESSOR_GB}@
""" "${JETTY_BASE}/resources/render-server.properties"

# --------------------------------------------------------------
# Default view query parameters

appendParameter() {
local PARAMETERS="$1"
local KEY="$2"
local VALUE="$3"
if [ -n "${PARAMETERS}" ]; then
PARAMETERS="${PARAMETERS}\&amp;${KEY}=${VALUE}"
else
PARAMETERS="?${KEY}=${VALUE}"
fi
echo "${PARAMETERS}"
}

unset VIEW_PARAMETERS

# NOTE: NDVIZ_URL has already been aggregated from host and port above if necessary
if [ -n "${NDVIZ_URL}" ]; then
VIEW_PARAMETERS="?ndvizHost=${NDVIZ_URL}"
fi

if [ -n "${VIEW_CATMAID_HOST_AND_PORT}" ]; then
VIEW_PARAMETERS=$(appendParameter "${VIEW_PARAMETERS}" catmaidHost "${VIEW_CATMAID_HOST_AND_PORT}")
fi

if [ -n "${VIEW_DYNAMIC_RENDER_HOST_AND_PORT}" ]; then
VIEW_PARAMETERS=$(appendParameter "${VIEW_PARAMETERS}" dynamicRenderHost "${VIEW_DYNAMIC_RENDER_HOST_AND_PORT}")
fi

if [ -n "${VIEW_RENDER_STACK_OWNER}" ]; then

VIEW_PARAMETERS=$(appendParameter "${VIEW_PARAMETERS}" renderStackOwner "${VIEW_RENDER_STACK_OWNER}")

if [ -n "${VIEW_RENDER_STACK_PROJECT}" ]; then

VIEW_PARAMETERS=$(appendParameter "${VIEW_PARAMETERS}" renderStackProject "${VIEW_RENDER_STACK_PROJECT}")

if [ -n "${VIEW_RENDER_STACK}" ]; then

VIEW_PARAMETERS=$(appendParameter "${VIEW_PARAMETERS}" renderStack "${VIEW_RENDER_STACK}")

fi
fi
fi

if [ -n "${VIEW_MATCH_OWNER}" ]; then

VIEW_PARAMETERS=$(appendParameter "${VIEW_PARAMETERS}" matchOwner "${VIEW_MATCH_OWNER}")

if [ -n "${VIEW_MATCH_COLLECTION}" ]; then

VIEW_PARAMETERS=$(appendParameter "${VIEW_PARAMETERS}" matchCollection "${VIEW_MATCH_COLLECTION}")

fi
fi

sed -i "s@render-ws/view/index.html@render-ws/view/index.html${VIEW_PARAMETERS}@" "${JETTY_BASE}/etc/jetty-rewrite.xml"
""" "${JETTY_BASE}/resources/render-server.properties"
18 changes: 18 additions & 0 deletions render-ws/src/main/webapp/script/janelia-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ JaneliaQueryParameters.prototype.get = function(key, defaultValue) {
return value;
};

JaneliaQueryParameters.prototype.applyServerProperties = function(serverPropertyMap) {
for (var key in serverPropertyMap) {

if (! serverPropertyMap.hasOwnProperty(key)) {
continue; // ignore if the property is from prototype
} else if (! key.startsWith('view.')) {
continue; // ignore non-view properties
}

var viewKey = key.substr(5);

var queryParameterValue = this.map[viewKey];
if (typeof queryParameterValue == 'undefined') {
this.map[viewKey] = serverPropertyMap[key];
}
}
};

JaneliaQueryParameters.prototype.updateParameter = function (key, value) {

if (typeof key != 'undefined') {
Expand Down
69 changes: 44 additions & 25 deletions render-ws/src/main/webapp/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Render Web Service Views</title>
<link type="text/css" href="../css/render.css" rel="stylesheet" />
<script type="text/javascript" src="../script/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../script/janelia-render.js?v=20170105_001"></script>
<script type="text/javascript" src="../script/janelia-render.js?v=20180415_001"></script>
<script type="text/javascript" src="../script/janelia-match.js?v=20170105_001"></script>
<script type="text/javascript">

Expand All @@ -26,34 +26,53 @@
inputId,
function(changedValue) { renderWebServiceViews.updateParameter(inputId, changedValue) });
$('#' + inputId).val(renderWebServiceViews.parameters.get(inputId));
},
loadServerDefaultParameters : function() {
var self = this;
$.ajax({
url: self.util.getServicesBaseUrl() + '/serverProperties',
cache: false,
success: function(data) {
self.parameters.applyServerProperties(data.properties);
self.loadPage();
},
error: function(data, text, xhr) {
console.log(xhr);
self.loadPage();
}
});
},
updateSwaggerLink : function() {
// change API link to reference Swagger UI if it is deployed on server
var swaggerUiUrl = renderWebServiceViews.util.getServicesBaseUrl() + '/../../swagger-ui/';
$.ajax({
url: swaggerUiUrl,
cache: false,
type: "HEAD",
success: function() {
$('#apiLink').attr("href", swaggerUiUrl).text('Web Service APIs');
}
});
},
loadPage : function() {
var renderUi = new JaneliaRenderServiceDataUI(renderWebServiceViews.parameters,
'renderStackOwner', 'renderStackProject', 'renderStack',
'message', 'urlToView');
renderUi.loadData();

renderWebServiceViews.setUpHostData('dynamicRenderHost');
renderWebServiceViews.setUpHostData('catmaidHost');
renderWebServiceViews.setUpHostData('ndvizHost');

new JaneliaMatchServiceDataUI(
renderWebServiceViews.parameters,
'matchOwner', 'matchCollection', 'matchCollectionPairCount', 'message', 'urlToView');
}

};

$( document ).ready(function() {
var renderUi = new JaneliaRenderServiceDataUI(renderWebServiceViews.parameters,
'renderStackOwner', 'renderStackProject', 'renderStack',
'message', 'urlToView');
renderUi.loadData();

renderWebServiceViews.setUpHostData('dynamicRenderHost');
renderWebServiceViews.setUpHostData('catmaidHost');
renderWebServiceViews.setUpHostData('ndvizHost');

new JaneliaMatchServiceDataUI(
renderWebServiceViews.parameters, 'matchOwner', 'matchCollection', 'matchCollectionPairCount', 'message', 'urlToView');

// change API link to reference Swagger UI if it is deployed on server
var swaggerUiUrl = renderWebServiceViews.util.getServicesBaseUrl() + '/../../swagger-ui/';
$.ajax({
url: swaggerUiUrl,
cache: false,
type: "HEAD",
success: function() {
$('#apiLink').attr("href", swaggerUiUrl).text('Web Service APIs');
}
});

renderWebServiceViews.loadServerDefaultParameters();
renderWebServiceViews.updateSwaggerLink();
});

</script>
Expand Down

0 comments on commit e53d520

Please sign in to comment.