Skip to content

Commit

Permalink
Merge pull request #890 from ohmage/ohmage-2.18
Browse files Browse the repository at this point in the history
ohmage 2.18 release
  • Loading branch information
stevenolen committed Mar 31, 2016
2 parents 4a0d739 + cc7e56d commit cd05696
Show file tree
Hide file tree
Showing 85 changed files with 7,113 additions and 734 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git/objects/pack
77 changes: 77 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
FROM debian:jessie
MAINTAINER Steve Nolen <[email protected]>
# Report issues here: https://github.com/ohmage/server

RUN set -x \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y openjdk-7-jdk ant curl libtcnative-1 netcat git mysql-client\
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# download tomcat
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH
RUN mkdir -p "$CATALINA_HOME"
WORKDIR $CATALINA_HOME

# see https://www.apache.org/dist/tomcat/tomcat-8/KEYS
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys \
05AB33110949707C93A279E3D3EFE6B686867BA6 \
07E48665A34DCAFAE522E5E6266191C37C037D42 \
47309207D818FFD8DCD3F83F1931D684307A10A5 \
541FBE7D8F78B25E055DDEE13C370389288584E7 \
61B832AC2F1C5A90F0F9B00A1C506407564C17A3 \
713DA88BE50911535FE716F5208B0AB1D63011C7 \
79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED \
9BA44C2621385CB966EBA586F72C284D731FABEE \
A27677289986DB50844682F8ACB77FC2E86E29AC \
A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 \
DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 \
F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE \
F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23

ENV TOMCAT_MAJOR 7
ENV TOMCAT_VERSION 7.0.67
ENV TOMCAT_TGZ_URL https://www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz

RUN set -x \
&& curl -fSL "$TOMCAT_TGZ_URL" -o tomcat.tar.gz \
&& curl -fSL "$TOMCAT_TGZ_URL.asc" -o tomcat.tar.gz.asc \
&& gpg --verify tomcat.tar.gz.asc \
&& tar -xvf tomcat.tar.gz --strip-components=1 \
&& rm bin/*.bat \
&& rm tomcat.tar.gz* \
&& rm -rf /usr/local/tomcat/webapps/ROOT \
&& rm -rf /usr/local/tomcat/webapps/docs \
&& rm -rf /usr/local/tomcat/webapps/examples \
&& rm -rf /usr/local/tomcat/webapps/manager \
&& rm -rf /usr/local/tomcat/webapps/host-manager

#### download flyway (ohmage doesn't do migrations) ####
WORKDIR /flyway
ENV FLYWAY_TGZ_URL http://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/3.2.1/flyway-commandline-3.2.1.tar.gz
RUN set -x \
&& curl -fSL "$FLYWAY_TGZ_URL" -o flyway.tar.gz \
&& tar -xvf flyway.tar.gz --strip-components=1 \
&& rm flyway.tar.gz

WORKDIR /app
ADD . /app
RUN cp db/migration/* /flyway/sql/ \
&& ant clean dist \
&& cp dist/webapp-ohmage* "$CATALINA_HOME"/webapps/app.war \
&& cp docker_entrypoint.sh /run.sh \
&& chmod +x /run.sh \
&& rm -rf /app

RUN mkdir -p /var/lib/ohmage && ln -s /var/lib/ohmage /ohmage
RUN useradd -ms /bin/bash ohmage && \
chown -R ohmage.ohmage "$CATALINA_HOME" && \
chown -R ohmage.ohmage /var/lib/ohmage

EXPOSE 8080

VOLUME /ohmage

CMD ["/run.sh"]
37 changes: 37 additions & 0 deletions Dockerfile.wildfly
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM jboss/wildfly
MAINTAINER Steve Nolen <[email protected]>
# Report issues here: https://github.com/ohmage/server

USER root

RUN yum install -y ant ant-junit curl nc git mysql

#### download flyway (ohmage doesn't do migrations) ####
WORKDIR /flyway
ENV FLYWAY_TGZ_URL http://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/3.2.1/flyway-commandline-3.2.1.tar.gz
RUN set -x \
&& curl -fSL "$FLYWAY_TGZ_URL" -o flyway.tar.gz \
&& tar -xvf flyway.tar.gz --strip-components=1 \
&& rm flyway.tar.gz

WORKDIR /app
ADD . /app
RUN cp db/migration/* /flyway/sql/ \
&& ant clean dist \
&& cp dist/webapp-ohmage* /opt/jboss/wildfly/standalone/deployments/app.war \
&& cp docker_entrypoint.sh /run.sh \
# modify run.sh to run wildfly instead of tomcat!
&& sed -i 's|^exec.*$|exec /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0|g' /run.sh \
&& chmod +x /run.sh \
&& rm -rf /app

RUN mkdir -p /var/lib/ohmage && ln -s /var/lib/ohmage /ohmage
RUN useradd -ms /bin/bash ohmage && \
chown -R ohmage.ohmage /opt/jboss/wildfly/ && \
chown -R ohmage.ohmage /var/lib/ohmage

EXPOSE 8080

VOLUME /ohmage

CMD ["/run.sh"]
5 changes: 4 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<property file="build.properties"/>
<property name="library" location="lib"/>
<property name="app_name" value="ohmage"/>
<property name="app_version" value="2.17.3"/>
<property name="app_version" value="2.18.0"/>
<property name="src" location="src"/>
<property name="test" location="test"/>
<property name="view" location="view"/>
Expand Down Expand Up @@ -41,6 +41,7 @@
<include name="js.jar"/>
<include name="catalina-2012-09-10.jar"/>
<include name="RunKeeperOmhLayer.jar"/>
<include name="jose4j-0.4.4.jar"/>
</fileset>

<fileset id="run-dependencies" dir="${library}">
Expand Down Expand Up @@ -76,6 +77,8 @@
<include name="slf4j-log4j12-1.7.5.jar"/>
<include name="tomcat-dbcp-7.0.42.jar" />
<include name="tomcat-jdbc-7.0.42.jar" />
<include name="tomcat-juli.jar" />
<include name="jose4j-0.4.4.jar"/>
</fileset>

<path id="compile-classpath">
Expand Down
4 changes: 4 additions & 0 deletions db/migration/V10__2.18_editable_campaign.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Adds a bit column in campaign table to determine if campaign is editable or not.
-- defaults to false since the "participatory sensing"-ness of it is a bit lacking.
ALTER TABLE campaign
ADD COLUMN `editable` bit NOT NULL DEFAULT FALSE;
2 changes: 1 addition & 1 deletion db/migration/V5__2.17_cleanup_user_role_campaign.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ WHERE id IN (
GROUP BY u.id, cp.id, ur.id
HAVING count(cc.class_id) - SUM(IF(uc.class_id IS NULL, 1, 0)) = 0
) t1
)
);

27 changes: 27 additions & 0 deletions db/migration/V6__2.18_access_request.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- ----------------------------------------------------------------------
-- The table to store the user access request
-------------------------------------------------------------------------
-- use status:varchar for simplicity. possible values: pending/approved/rejected
CREATE TABLE IF NOT EXISTS access_request (
id int unsigned NOT NULL auto_increment,
uuid CHAR(36) NOT NULL UNIQUE,
user_id int unsigned NOT NULL,
email_address varchar(320) NOT NULL,
type varchar(25) NOT NULL,
status varchar(25) NOT NULL,
content mediumtext NOT NULL,
creation_timestamp datetime NOT NULL,
last_modified_timestamp timestamp DEFAULT now() ON UPDATE now(),
PRIMARY KEY (id),
UNIQUE (uuid),
INDEX (uuid),
INDEX (user_id),
CONSTRAINT FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO preference (p_key, p_value) VALUES
('mail_admin_address', 'root@localhost'),
('mail_access_request_notify_admin', 'false'),
('mail_access_request_sender_address', '[email protected]'),
('mail_access_request_subject', 'ohmage: Access Request Status')
ON DUPLICATE KEY UPDATE p_value=VALUES(p_value);
8 changes: 8 additions & 0 deletions db/migration/V7__2.18_add_app_name_to_preferences.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- ----------------------------------------------------------------------
-- Inserts a default preference key so as not to be statefully reliant on
-- the compiled war file.
-------------------------------------------------------------------------

INSERT INTO preference (p_key, p_value) VALUES
('application_name', 'ohmage')
ON DUPLICATE KEY UPDATE p_value=VALUES(p_value);
13 changes: 13 additions & 0 deletions db/migration/V8__2.18_add_keycloak_integration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Inserts a default preference key to determine keycloak enabledness
INSERT INTO preference (p_key, p_value) VALUES
('keycloak_auth_enabled', 'false')
ON DUPLICATE KEY UPDATE p_value=VALUES(p_value);

-- Inserts a default preference key to determine local auth enabledness
INSERT INTO preference (p_key, p_value) VALUES
('local_auth_enabled', 'true')
ON DUPLICATE KEY UPDATE p_value=VALUES(p_value);

-- Adds a bit column in user table to determine if user is local or external
ALTER TABLE user
ADD COLUMN `external` bit NOT NULL DEFAULT FALSE;
30 changes: 30 additions & 0 deletions db/migration/V9__2.18_bugfix_887.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- get public class id
SET @public_class_id =
(SELECT id
FROM class
WHERE urn IN
(SELECT p_value
FROM preference
WHERE p_key="public_class_id"));

-- perhaps the analyst role isn't id=3 ?
SET @analyst_role_id =
(SELECT id
FROM user_role
WHERE role = "analyst");

-- add users who are currently *only* "participants" in public campaigns
-- as "analysts" as well. so they can see shared data.
INSERT INTO user_role_campaign (user_id, campaign_id, user_role_id)
SELECT user_id,
campaign_id,
@analyst_role_id
FROM user_role_campaign
WHERE campaign_id IN
(SELECT campaign.id
FROM campaign
JOIN campaign_class ON campaign.id = campaign_class.campaign_id
WHERE campaign_class.class_id = @public_class_id)
GROUP BY user_id,
campaign_id
HAVING sum(user_role_id) = 1;
22 changes: 22 additions & 0 deletions db/sql/base/ohmage-ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,25 @@ CREATE TABLE IF NOT EXISTS `observer_stream_data_invalid` (
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------------------------------------------------
-- The table to store the user access request
-------------------------------------------------------------------------
-- use status:varchar for simplicity. possible values: pending/approved/rejected
CREATE TABLE IF NOT EXISTS access_request (
id int unsigned NOT NULL auto_increment,
uuid CHAR(36) NOT NULL UNIQUE,
user_id int unsigned NOT NULL,
email_address varchar(320) NOT NULL,
type varchar(25) NOT NULL,
status varchar(25) NOT NULL DEFAULT "pending",
content mediumtext NOT NULL,
creation_timestamp datetime NOT NULL,
last_modified_timestamp timestamp DEFAULT now() ON UPDATE now(),
PRIMARY KEY (id),
UNIQUE (uuid),
INDEX (uuid),
INDEX (user_id),
CONSTRAINT FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

4 changes: 2 additions & 2 deletions db/sql/update/2.16-2.17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ WHERE id IN (
AND cc.id IS NULL
GROUP BY u.id, cp.id, ur.id
) t1
)
);

-- delete the relationship between user and campaigns where the campaigns are in
-- classes that users are not members of. Delete all roles except "author".
Expand All @@ -600,6 +600,6 @@ WHERE id IN (
GROUP BY u.id, cp.id, ur.id
HAVING count(cc.class_id) - SUM(IF(uc.class_id IS NULL, 1, 0)) = 0
) t1
)
);


74 changes: 74 additions & 0 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

set -e

# use passed env variable or defaults
DB_HOST=$MYSQL_PORT_3306_TCP_ADDR
DB_PORT=$MYSQL_PORT_3306_TCP_PORT
DB_NAME=${DB_NAME:-ohmage}
DB_USER=${DB_USER:-ohmage}
DB_PASS=${DB_PASS:-ohmage}
FQDN=${FQDN:-$HOSTNAME}
LOG_LEVEL=${LOG_LEVEL:-WARN}
ESCAPED_PW=${DB_PASS/\&/\\&}

# cat out ohmage.conf
echo "#
# DATABASE
#
db.driver=com.mysql.jdbc.Driver
db.jdbcurl=jdbc:mysql://$DB_HOST:$DB_PORT/$DB_NAME?characterEncoding=utf8
db.username=$DB_USER
db.password=$ESCAPED_PW
#
# LOGGING
#
# The root logger
log4j.rootLogger=$LOG_LEVEL, stdout
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold = $LOG_LEVEL
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-5p %d [%t][%F:%L] : %m%n
log4j.logger.org.ohmage=$LOG_LEVEL
log4j.logger.org.springframework=$LOG_LEVEL
log4j.logger.org.ohmage.util.JsonUtils=$LOG_LEVEL
log4j.logger.org.ohmage.cache.UserBin=$LOG_LEVEL" > /etc/ohmage.conf

if [ -n "$KEYCLOAK_JSON" ]; then
echo "keycloak.config=$KEYCLOAK_JSON" >> /etc/ohmage.conf
fi

# cat out flyway.conf
# note that the placeholders wont be updated at each boot.
echo "flyway.url=jdbc:mysql://$DB_HOST:$DB_PORT/$DB_NAME
flyway.user=$DB_USER
flyway.password=$DB_PASS
flyway.placeholders.fqdn=$FQDN
flyway.placeholders.base_dir=/var/lib/ohmage" > /flyway/conf/flyway.conf

# create database stuffz. different depending on linked mysql container.
echo -n "waiting for mysql to start..."
while ! nc -w 1 $DB_HOST $DB_PORT &> /dev/null
do
echo -n .
sleep 1
done
echo 'mysql available.'
mysql -uroot -p$MYSQL_ENV_MYSQL_ROOT_PASSWORD -h$DB_HOST -P$DB_PORT mysql -e "CREATE DATABASE IF NOT EXISTS $DB_NAME; grant all on $DB_NAME.* to \"$DB_USER\"@\"%\" IDENTIFIED BY \"$DB_PASS\"; FLUSH PRIVILEGES;"

# execute migrations
/flyway/flyway migrate

# ensure ohmage directory structure exists
mkdir -p /var/lib/ohmage/audio
mkdir -p /var/lib/ohmage/audits
mkdir -p /var/lib/ohmage/documents
mkdir -p /var/lib/ohmage/images
mkdir -p /var/lib/ohmage/videos
chown -R ohmage.ohmage /var/lib/ohmage

# start tomcat in foreground
exec /usr/local/tomcat/bin/catalina.sh run
Binary file added lib/jose4j-0.4.4.jar
Binary file not shown.
Binary file added lib/tomcat-juli.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion src/org/ohmage/annotator/Annotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static enum ErrorCode {
SURVEY_INVALID_PROMPT_RESPONSE_SEARCH ("0629"),
SURVEY_INVALID_SURVEY_PROMPT_MAP ("0630"),
SURVEY_DUPLICATE_MEDIA_UUIDS ("0631"), // when media or document uuids are duplicate
SURVEY_UPLOAD_INVALID_ARGUMENTS ("0632"),

CAMPAIGN_INVALID_ID ("0700"),
CAMPAIGN_INVALID_NAME ("0701"),
Expand All @@ -128,6 +129,7 @@ public static enum ErrorCode {
CAMPAIGN_INVALID_AUTHORED_BY_VALUE ("0711"),
CAMPAIGN_INVALID_SURVEY_ID ("O712"),
CAMPAIGN_INVALID_PROMPT_ID ("0713"),
CAMPAIGN_INVALID_EDITABLE ("0714"),

IMAGE_INVALID_ID ("0800"),
IMAGE_INVALID_SIZE ("0801"),
Expand Down Expand Up @@ -162,8 +164,11 @@ public static enum ErrorCode {
USER_INVALID_DELETE_PERSONAL_INFO ("1015"),
USER_INVALID_CLASS_CREATION_PRIVILEGE ("1016"),
USER_INVALID_USER_SETUP_PRIVILEGE ("1017"),
// user-setup
// user setup
USER_INVALID_USERNAME_PROPERTY ("1018"),
// access request
USER_ACCESS_REQUEST_INVALID_PRAMETER ("1019"),
USER_ACCESS_REQUEST_EXECUTION_ERROR ("1020"),

DOCUMENT_INVALID_ID ("1100"),
DOCUMENT_INVALID_NAME ("1101"),
Expand Down
Loading

0 comments on commit cd05696

Please sign in to comment.