Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy OTP to AWS load balancer and manage OTP servers in separate collection (and misc other fixes) #225

Merged
merged 50 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ac0b00c
WIP spin up EC2 (no user data)
landonreed Aug 7, 2018
9c5e92c
Merge branch 'remove-r5' into deploy-to-ec2
landonreed Sep 18, 2018
d34b96a
Merge branch 'dev' into deploy-to-ec2
landonreed Nov 6, 2018
560c4c6
refactor(snapshot): remove legacy MapDB-based snapshot jobs
landonreed Nov 12, 2018
dbbd130
fix(delete): delete SQL namespace when feed version/snapshot deleted
landonreed Nov 12, 2018
c01eadc
feature(deploy-ec2): deployment enhancements for load balancers
landonreed Nov 12, 2018
f777b02
fix(user-mgmt): better error handling when Auth0 cannot update/create…
landonreed Nov 12, 2018
8898376
fix: move toGtfsDate from deleted class to FeedTx
landonreed Nov 12, 2018
fa5ce83
refactor: fix whitespace
landonreed Nov 12, 2018
e0a1eb6
refactor: add missing aws pom entry
landonreed Nov 12, 2018
61c04d2
build(pom): update gtfs-lib dependency
landonreed Nov 12, 2018
7231a95
feature(server-mgmt): manage deployment servers at the application level
landonreed Nov 15, 2018
b372303
refactor(server-job): attach just the project ID to the merge feeds job
landonreed Nov 29, 2018
7c92c1d
Merge branch 'dev' into deploy-to-ec2
landonreed Nov 30, 2018
aa0553b
refactor(deploy): shuffle deploy job code for clarity
landonreed Nov 30, 2018
c52d6f0
Merge pull request #133 from ibi-group/dev
landonreed Aug 7, 2019
56f7642
Merge branch 'dev' into deploy-to-ec2
landonreed Aug 7, 2019
6ae2055
refactor: fix issues resulting from merge
landonreed Aug 7, 2019
c33c290
refactor(deployment): tweak user script and update default config
landonreed Aug 8, 2019
05ec4df
refactor(deployment): improve validation of server fields
landonreed Aug 9, 2019
b6d7363
refactor(deployments): modify OtpServer fields and refactor server cr…
landonreed Aug 9, 2019
7a020c8
refactor: remove unused import
landonreed Aug 9, 2019
c753a31
refactor(ServerController): add comment about checking S3 permissions
landonreed Aug 13, 2019
b793727
refactor(ServerController): add missing exceptions to logMessageAndHalt
landonreed Aug 14, 2019
a3ed73c
refactor(deploy): fix check for s3 graph object
landonreed Aug 20, 2019
a07935a
refactor(deploy): revert to default instance type if none specified
landonreed Aug 20, 2019
a177e79
refactor(deploy): make instance profile arn optional
landonreed Aug 20, 2019
2507ab5
refactor(deploy): use set method rather than with for instance profile
landonreed Aug 22, 2019
e1fe1a3
Merge branch 'dev' into deploy-to-ec2
landonreed Sep 3, 2019
4a1ef29
refactor(deploy): move ec2 config into OtpServer
landonreed Sep 9, 2019
9b957dd
refactor(deploy): tweak deployJob for NPE fix and fix server delete
landonreed Sep 10, 2019
bf0f1bc
ci(config): update server.yml.tmp for e2e
landonreed Sep 10, 2019
ade0b40
refactor(EC2InstanceSummary): add empty constructor for serialization
landonreed Sep 10, 2019
95a2333
Merge branch 'dev' into deploy-to-ec2
landonreed Sep 12, 2019
c273350
test(.gitignore): don't ignore test config
landonreed Sep 12, 2019
3493570
test(mtc): fix broken MTC feed merge test with new test config
landonreed Sep 12, 2019
4992b32
refactor(ServerController): isolate jackson parse to utility method
landonreed Sep 12, 2019
3441fa2
refactor(ServerController): surround validation method calls in try/c…
landonreed Sep 12, 2019
a36a7d9
refactor(deploy-to-ec2): address PR comments
landonreed Sep 20, 2019
18bd9d3
refactor(deploy-to-ec2): add json property latest; add server ID to s…
landonreed Sep 20, 2019
c28c215
Merge branch 'dev' into deploy-to-ec2
landonreed Sep 20, 2019
41c21a8
refactor(deploy): fix check for S3 jar
landonreed Sep 20, 2019
7e1528b
refactor(deploy-to-ec2): address PR comments
landonreed Sep 24, 2019
f34affb
refactor(deploy-to-ec2): surround s3 checks in try/catch
landonreed Sep 24, 2019
4cc9b68
refactor(deploy-to-ec2): actually skip termination request
landonreed Sep 24, 2019
fb44a61
refactor(deploy): fix duration calc
landonreed Sep 30, 2019
101b7f9
refactor(deploy): use onboard nginx to signal ec2 deploy status
landonreed Oct 1, 2019
523801d
refactor(deploy): bump default otp version to 1.4
landonreed Oct 3, 2019
c399189
refactor(deploy): add terminate EC2 instance HTTP endpoint
landonreed Oct 8, 2019
240a6e0
refactor(deploy): refine terminate instances endpoint and check for g…
landonreed Oct 8, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ deploy/
# Configurations
configurations/*
!configurations/default
!configurations/test

# Secret config files
.env
Expand Down
45 changes: 14 additions & 31 deletions configurations/default/server.yml.tmp
Original file line number Diff line number Diff line change
@@ -1,61 +1,44 @@
application:
title: Data Tools
logo: https://d2tyb7byn1fef9.cloudfront.net/ibi_group-128x128.png
logo_large: https://d2tyb7byn1fef9.cloudfront.net/ibi_group_black-512x512.png
client_assets_url: https://example.com
shortcut_icon_url: https://d2tyb7byn1fef9.cloudfront.net/ibi-logo-original%402x.png
public_url: http://localhost:9966
notifications_enabled: true
cors:
enabled: true
origins: https://google.com
methods:
headers:
notifications_enabled: false
docs_url: http://conveyal-data-tools.readthedocs.org
support_email: [email protected]
port: 4000
data:
editor_mapdb: /tmp/editor/mapdb
mapdb: /tmp/mapdb
gtfs: /tmp
use_s3_storage: false
s3_region: us-east-1
gtfs_s3_bucket: bucket-name
modules:
dump:
enabled: true
enterprise:
enabled: false
deployment:
enabled: true
editor:
enabled: true
url: http://localhost:9001
alerts:
enabled: true
use_extension: mtc
url: /alerts
sign_config:
deployment:
enabled: true
use_extension: mtc
url: /signs # eventually remove this
ec2:
enabled: false
default_ami: ami-your-ami-id
# Note: using a cloudfront URL for these download URLs will greatly
# increase download/deploy speed.
otp_download_url: https://optional-otp-repo.com
r5_download_url: https://optional-r5-repo.com
user_admin:
enabled: true
# Enable GTFS+ module for testing purposes
gtfsplus:
enabled: true
gtfsapi:
enabled: true
load_on_fetch: false
# use_extension: mtc
# update_frequency: 30 # in seconds

extensions:
mtc:
enabled: true
rtd_api: http://localhost:9876/
s3_bucket: bucket-name
s3_prefix: waiting/
s3_download_prefix: waiting/
transitland:
enabled: true
api: https://transit.land/api/v1/feeds
transitfeeds:
enabled: true
api: http://api.transitfeeds.com/v1/getFeeds
key: your-api-key
19 changes: 19 additions & 0 deletions configurations/test/env.yml.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This client ID refers to the UI client in Auth0.
AUTH0_CLIENT_ID: your-auth0-client-id
AUTH0_DOMAIN: your-auth0-domain
# Note: One of AUTH0_SECRET or AUTH0_PUBLIC_KEY should be used depending on the signing algorithm set on the client.
# It seems that newer Auth0 accounts (2017 and later) might default to RS256 (public key).
AUTH0_SECRET: your-auth0-secret # uses HS256 signing algorithm
# AUTH0_PUBLIC_KEY: /path/to/auth0.pem # uses RS256 signing algorithm
# This client/secret pair refer to a machine-to-machine Auth0 application used to access the Management API.
AUTH0_API_CLIENT: your-api-client-id
AUTH0_API_SECRET: your-api-secret-id
DISABLE_AUTH: false
OSM_VEX: http://localhost:1000
SPARKPOST_KEY: your-sparkpost-key
SPARKPOST_EMAIL: [email protected]
GTFS_DATABASE_URL: jdbc:postgresql://localhost/catalogue
# GTFS_DATABASE_USER:
# GTFS_DATABASE_PASSWORD:
#MONGO_URI: mongodb://mongo-host:27017
MONGO_DB_NAME: catalogue
50 changes: 50 additions & 0 deletions configurations/test/server.yml.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
application:
title: Data Tools
logo: https://d2tyb7byn1fef9.cloudfront.net/ibi_group-128x128.png
logo_large: https://d2tyb7byn1fef9.cloudfront.net/ibi_group_black-512x512.png
client_assets_url: https://example.com
shortcut_icon_url: https://d2tyb7byn1fef9.cloudfront.net/ibi-logo-original%402x.png
public_url: http://localhost:9966
notifications_enabled: false
docs_url: http://conveyal-data-tools.readthedocs.org
support_email: [email protected]
port: 4000
data:
gtfs: /tmp
use_s3_storage: false
s3_region: us-east-1
gtfs_s3_bucket: bucket-name
modules:
enterprise:
enabled: false
editor:
enabled: true
deployment:
enabled: true
ec2:
enabled: false
default_ami: ami-your-ami-id
user_admin:
enabled: true
# Enable GTFS+ module for testing purposes
gtfsplus:
enabled: true
gtfsapi:
enabled: true
load_on_fetch: false
# use_extension: mtc
# update_frequency: 30 # in seconds
extensions:
# Enable MTC extension so MTC-specific feed merge tests
mtc:
enabled: true
rtd_api: http://localhost:9876/
s3_bucket: bucket-name
s3_prefix: waiting/
s3_download_prefix: waiting/
transitland:
enabled: true
api: https://transit.land/api/v1/feeds
transitfeeds:
enabled: true
api: http://api.transitfeeds.com/v1/getFeeds
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<!-- Using the latest version of geotools (e.g, 20) seems to cause issues with the shapefile
plugin where the_geom for each feature is null. -->
<geotools.version>17.5</geotools.version>
<awsjavasdk.version>1.11.625</awsjavasdk.version>
</properties>
<build>
<resources>
Expand Down Expand Up @@ -394,6 +395,22 @@
<artifactId>super-csv</artifactId>
<version>2.4.0</version>
</dependency>
<!-- AWS individual module imports (S3 imported by gtfs-lib) -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ec2</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-iam</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-elasticloadbalancingv2</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
Expand All @@ -18,7 +19,8 @@
/**
* Created by landon on 6/13/16.
*/
public abstract class MonitorableJob implements Runnable {
public abstract class MonitorableJob implements Runnable, Serializable {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(MonitorableJob.class);
public final String owner;

Expand Down Expand Up @@ -60,6 +62,7 @@ public enum JobType {
EXPORT_SNAPSHOT_TO_GTFS,
CONVERT_EDITOR_MAPDB_TO_SQL,
VALIDATE_ALL_FEEDS,
MONITOR_SERVER_STATUS,
MERGE_FEED_VERSIONS
}

Expand Down Expand Up @@ -128,7 +131,6 @@ public void run () {
boolean parentJobErrored = false;
boolean subTaskErrored = false;
String cancelMessage = "";
long startTimeNanos = System.nanoTime();
try {
// First execute the core logic of the specific MonitorableJob subclass
jobLogic();
Expand Down Expand Up @@ -187,8 +189,7 @@ public void run () {
LOG.error("Job failed", ex);
status.update(true, ex.getMessage(), 100, true);
}
status.startTime = TimeUnit.NANOSECONDS.toMillis(startTimeNanos);
status.duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeNanos);
status.duration = System.currentTimeMillis() - status.startTime;
LOG.info("{} {} {} in {} ms", type, jobId, status.error ? "errored" : "completed", status.duration);
}

Expand Down Expand Up @@ -242,7 +243,7 @@ public static class Status {
/** How much of task is complete? */
public double percentComplete;

public long startTime;
public long startTime = System.currentTimeMillis();
public long duration;

// When was the job initialized?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void logMessageAndHalt(
) throws HaltException {
// Note that halting occurred, also print error stacktrace if applicable
if (e != null) e.printStackTrace();
LOG.info("Halting with status code {}. Error message: {}.", statusCode, message);
LOG.info("Halting with status code {}. Error message: {}", statusCode, message);

if (statusCode >= 500) {
LOG.error(message);
Expand All @@ -122,7 +122,7 @@ public static void logMessageAndHalt(
if (bugsnag != null && e != null) {
// create report to send to bugsnag
Report report = bugsnag.buildReport(e);
Auth0UserProfile userProfile = request.attribute("user");
Auth0UserProfile userProfile = request != null ? request.attribute("user") : null;
String userEmail = userProfile != null ? userProfile.getEmail() : "no-auth";
report.setUserEmail(userEmail);
bugsnag.notify(report);
Expand Down Expand Up @@ -218,11 +218,16 @@ public static void logRequestOrResponse(
String bodyString,
int statusCode
) {
// If request is null, log warning and exit. We do not want to hit an NPE in this method.
if (request == null) {
LOG.warn("Request object is null. Cannot log.");
return;
}
Auth0UserProfile userProfile = request.attribute("user");
String userEmail = userProfile != null ? userProfile.getEmail() : "no-auth";
String queryString = request.queryParams().size() > 0 ? "?" + request.queryString() : "";
LOG.info(
"{} {} {}: {}{}{}{}",
"{} {} {}: {}{}{} {}",
logRequest ? "req" : String.format("res (%s)", statusCode),
userEmail,
request.requestMethod(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static Snapshot deleteSnapshot(Request req, Response res) {
if (snapshot == null) logMessageAndHalt(req, 400, "Must provide valid snapshot ID.");
try {
// Remove the snapshot and then renumber the snapshots
Persistence.snapshots.removeById(snapshot.id);
snapshot.delete();
feedSource.renumberSnapshots();
// FIXME Are there references that need to be removed? E.g., what if the active buffer snapshot is deleted?
// FIXME delete tables from database?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

import static com.conveyal.datatools.editor.jobs.ProcessGtfsSnapshotExport.toGtfsDate;

/** a transaction in an agency database */
public class FeedTx extends DatabaseTx {
private static final Logger LOG = LoggerFactory.getLogger(FeedTx.class);
Expand Down Expand Up @@ -124,6 +122,10 @@ public FeedTx(DB tx, boolean buildSecondaryIndices) {
// editedSinceSnapshot = tx.getAtomicBoolean("editedSinceSnapshot") == null ? tx.createAtomicBoolean("editedSinceSnapshot", false) : editedSinceSnapshot;
}

private static int toGtfsDate (LocalDate date) {
return date.getYear() * 10000 + date.getMonthValue() * 100 + date.getDayOfMonth();
landonreed marked this conversation as resolved.
Show resolved Hide resolved
}

public void commit () {
try {
// editedSinceSnapshot.set(true);
Expand Down

This file was deleted.

Loading