|
| 1 | +# Purpose of this Document |
| 2 | + |
| 3 | +The purpose of this document is to describe how to setup your development environment and run the submission system locally. |
| 4 | + |
| 5 | +# Overview |
| 6 | + |
| 7 | +The submission system uses multiple AWS services and Topcoder APIs to handle member submissions, we have a solution to execute all those services using mocks and fake versions of the service locally. |
| 8 | + |
| 9 | +We will be using Docker and docker-compose to run or mock up the following services: |
| 10 | + |
| 11 | +1. File microservice and S3: Used to upload and download submission files; |
| 12 | +2. DynamoDB: Main submission datastore; |
| 13 | +3. Informix: Legacy datastore, data is update in Informix to allow legacy applications to work with the submissions; |
| 14 | +4. NFS: legacy file storage; |
| 15 | +5. Challenge microservice: api to interact with challenge information; |
| 16 | +6. Member microservice: api to interact with member information; |
| 17 | +7. SQS: queueing service used to send and receive submission process requests; |
| 18 | +8. Kafka: queueing service used to send process failure notifications; |
| 19 | +9. Submissions UI: web page used to upload submissions; |
| 20 | + |
| 21 | +We will execute the following services directly, from an IDE or from your command line, since these are the services we will be modifying: |
| 22 | + |
| 23 | +1. Submission microservice: API used by the UI to initiate and finalize submissions; |
| 24 | +2. Submission processor: processes the submissions, which includes validating files, generating watermarked images, resizing images, generating consolidated zip files for download, updating Informix, and more. |
| 25 | + |
| 26 | +# Pre-requisites |
| 27 | + |
| 28 | +To prepare your environment to run the submission system, please start by installing these pre-requisites: |
| 29 | + |
| 30 | +* Docker: https://docs.docker.com/engine/installation/ |
| 31 | +* Docker-compose: https://docs.docker.com/compose/install/ |
| 32 | +* Windows/Mac OS X: |
| 33 | + * Docker Toolbox: https://www.docker.com/products/docker-toolbox |
| 34 | +* Java 1.8; |
| 35 | +* Your favorite IDE (our team uses Eclipse and Intellij); |
| 36 | +* The submission-system.zip file, unzipped to a local folder. Henceforth in this document, we will call this folder submission-system. |
| 37 | +* (Optional but recommended) aws cli: http://docs.aws.amazon.com/cli/latest/userguide/installing.html |
| 38 | + * This will allow you to view data in the mongodb database, messages in sqs, etc. |
| 39 | + |
| 40 | +# Local Configuration |
| 41 | + |
| 42 | +## Hosts |
| 43 | + |
| 44 | +Update your localhost entry in your hosts file (/etc/hosts) to map local.topcoder-dev.com: |
| 45 | + |
| 46 | + 127.0.0.1 localhost local.topcoder-dev.com |
| 47 | + |
| 48 | +Windows: |
| 49 | +C:\Windows\System32\drivers\etc\hosts |
| 50 | + |
| 51 | + 192.168.99.100 localhost local.topcoder-dev.com |
| 52 | + |
| 53 | +Mac OS X: |
| 54 | +/etc/hosts |
| 55 | + |
| 56 | + 192.168.99.100 localhost local.topcoder-dev.com |
| 57 | + |
| 58 | +## AWS credentials |
| 59 | + |
| 60 | +We will use fake AWS credentials to access the services, they will be loaded from your local AWS credentials folder, (~/.aws/). These credentials need to be consistent. |
| 61 | + |
| 62 | +If you already have a ~/.aws folder, please make a backup of the contents so you can restore your system to the previous configuration once you are done working on the submissions system. |
| 63 | + |
| 64 | +Create a ~/.aws folder, and in this folder create the following files: |
| 65 | + |
| 66 | +~/.aws/config with the following content: |
| 67 | + |
| 68 | + [default] |
| 69 | + output = json |
| 70 | + region = us-east-1 |
| 71 | + |
| 72 | +~/.aws/credentials with the following content |
| 73 | + |
| 74 | + [default] |
| 75 | + aws_access_key_id = key |
| 76 | + aws_secret_access_key = secret |
| 77 | + |
| 78 | +## Environment Configs |
| 79 | + |
| 80 | +Inside the submission-system folder, you will find a env.sh file. This file contains local environment configurations, open it and edit the configurations in there according to your environment: |
| 81 | + |
| 82 | + # The IP address of the computer running the submission system |
| 83 | + export IP=192.168.1.65 |
| 84 | + |
| 85 | +Windows/Mac OS X: |
| 86 | + |
| 87 | + # The IP address of the computer running the submission system |
| 88 | + export IP=192.168.99.100 |
| 89 | + |
| 90 | +# Starting the Local Services |
| 91 | + |
| 92 | +Export the env file configurations by issuing the following command inside the submission-system folder: |
| 93 | + |
| 94 | + source env.sh |
| 95 | + |
| 96 | +Inside the submission-system folder, issue the following command: |
| 97 | + |
| 98 | + docker-compose up submissions |
| 99 | + |
| 100 | +The first time you execute this command will cause all the required docker images to be downloaded to your local environment, this is a large download and it could take some time. Subsequent executions will be much faster. |
| 101 | + |
| 102 | +Once you see the following message, all services are up: |
| 103 | + |
| 104 | + submissions_1 | webpack: bundle is now VALID. |
| 105 | + |
| 106 | +At this point you should be able to connect to: |
| 107 | + |
| 108 | +* DynamoDB on localhost:7777; |
| 109 | +* Informix on localhost:2021; |
| 110 | + * User: informix |
| 111 | + * Password: 1nf0rm1x |
| 112 | + * Server: informixoltp_tcp |
| 113 | + * Jdbc url: jdbc:informix-sqli://localhost:2021/tcs_catalog:INFORMIXSERVER=informixoltp_tcp; |
| 114 | +* SQS on localhost:4568; |
| 115 | +* Kafka on localhost:9092 |
| 116 | +* Zookeeper on localhost:2181; |
| 117 | +* Frontend on http://local.topcoder-dev.com:3000/ |
| 118 | + |
| 119 | +To stop the local services: |
| 120 | + |
| 121 | + docker-compose down |
| 122 | + |
| 123 | +Note that when shutting down the containers will be deleted, the next time you start the services you will start with a clean slate, i.e. all the data will be reset to the initial state, and any submissions that you did while testing will be lost. |
| 124 | + |
| 125 | +# Building the Submission System |
| 126 | + |
| 127 | +At this point you could use your favorite IDE to do the next tasks. We will take a command line based approach here, which should provide all details and parameters necessary to do the same through an IDE. |
| 128 | + |
| 129 | +## Build ap-supply-library |
| 130 | + |
| 131 | +Common classes for all member facing services |
| 132 | + |
| 133 | +Unzip it the ap-supply-library folder, cd into it and: |
| 134 | + |
| 135 | + mvn clean compile install |
| 136 | + |
| 137 | +## Build ap-submission-library |
| 138 | + |
| 139 | +Common classes for the submissions system, such as models, service clients, utilities, etc. |
| 140 | + |
| 141 | +Unzip it the ap-submission-library folder, cd into it and: |
| 142 | + |
| 143 | + mvn clean compile install |
| 144 | + |
| 145 | +## Build ap-submission-microservice |
| 146 | + |
| 147 | +Submission API |
| 148 | + |
| 149 | +Unzip it the ap-submission-microservice/service folder, cd into it and: |
| 150 | + |
| 151 | + mvn clean compile package |
| 152 | + |
| 153 | +## Build ap-submission-processor |
| 154 | + |
| 155 | +Processor of submissions. |
| 156 | + |
| 157 | +Unzip it the ap-submission-processor/service folder, cd into it and: |
| 158 | + |
| 159 | + mvn clean compile package |
| 160 | + |
| 161 | +# Executing the Submission Service |
| 162 | + |
| 163 | +cd into the ap-submission-service/service, you will find a run.sh file in there containing all environment variables and the startup command to run the service locally: |
| 164 | + |
| 165 | + export AUTH_DOMAIN=topcoder-dev.com |
| 166 | + export DYNAMODB_ENDPOINT=http://localhost:7777 |
| 167 | + export FILE_SERVICE_ENDPOINT=http://localhost/v3/ |
| 168 | + export CHALLENGE_SERVICE_ENDPOINT=http://localhost/v3/ |
| 169 | + export IDENTITY_SERVICE_ENDPOINT=http://localhost/v3/ |
| 170 | + export SQS_URL=http://localhost:4568/submissions |
| 171 | + java -Ddw.server.applicationConnectors[0].port=8180 -Ddw.server.adminConnectors[0].port=8181 -jar target/submission-service-1.0.1-SNAPSHOT.jar server src/main/resources/config.yml |
| 172 | + |
| 173 | +To execute the service: |
| 174 | + |
| 175 | + sh run.sh |
| 176 | + |
| 177 | +# Executing the Submission Processor |
| 178 | + |
| 179 | +cd into the ap-submission-processor/service folder, in there you will find a run.sh file which contains all environment variables and the startup command to run the processor: |
| 180 | + |
| 181 | + SQS_URL=http://localhost:4568/submissions |
| 182 | + API_URL=http://localhost/v3 |
| 183 | + DYNAMODB_URL=http://localhost:7777 |
| 184 | + ZOOKEEPER_HOSTS_LIST=localhost:2181 |
| 185 | + java -Ddw.server.applicationConnectors[0].port=8280 -Ddw.server.adminConnectors[0].port=8281 -jar target/ap-submission-processor-1.0-SNAPSHOT.jar server src/main/resources/config.yml |
| 186 | + |
| 187 | +# Accessing the Submission UI |
| 188 | + |
| 189 | +Once the system is up and running, we can access the submission user interface to do a submission, however the system requires authentication, and we’ll have to fake it by setting some cookies and local storage values. |
| 190 | + |
| 191 | +Open your browser and navigate to: http://local.topcoder-dev.com:3000 |
| 192 | + |
| 193 | +You should see a login screen. Open the browser’s javascript console, paste and execute the the following code: |
| 194 | + |
| 195 | + document.cookie="tcsso=ey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v4zIMFV-D8F3JA"'); |
| 198 | + |
| 199 | +This browser now has the fake authentication, and we can go to the submission UI: http://local.topcoder-dev.com:3000/challenges/11/submit/file/ |
| 200 | +Note the challenge id there is 11, that is the only challenge that is setup in Informix to allow submissions, if you would like to use other challenges you will have to create resource and phase records in Informix, however, using challenge 11 should be sufficient for our purposes. |
| 201 | + |
| 202 | +You should now see a series of fields that can be populated by the submitter, the only required fields are the files at the top, and the “I UNDERSTAND AND AGREE” checkbox at the bottom: |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | +The submission zip is the representation of a design submission, it should be a simple zip file containing images. Any valid png, jpg, gif, or bpm files are allowed. You can download some images, take a few screenshots and create a submission zip file containing those images. The folder structure inside this submission zip doesn’t matter. This file needs to have valid images because those are processed, resized, watermarked, etc. Non image files in the submission.zip should be ignored. |
| 207 | + |
| 208 | +The source zip file contains the source files for the submission, such as a photoshop project. The contents of this file doesn’t impact the process, you could simply have a zip file with just one file inside, or even use the submission zip itself, it doesn’t matter, as long as it is a valid zip. |
| 209 | + |
| 210 | +The preview image is a cover image for the submission, any valid png or jpg file can be submitted as the preview. |
| 211 | + |
| 212 | +Select your 3 files, scroll to the bottom, check the “AGREE” box, and click the submit button, you should see the upload happening, and the process logs flowing in the submission processor console. |
| 213 | + |
| 214 | +If you see a message in the console saying “SUCCESSFUL NOTIFICATION SENT”, it means the processor finished successfully, otherwise you would see the exceptions in the log. |
| 215 | + |
| 216 | +# Known Issues |
| 217 | + |
| 218 | +* Local SQS sometimes stops working, messages don’t get delivered from the submission service to the submission processor. The best way to fix this issue is just to restart the local services with docker-compose down / docker-compose up submissions; |
| 219 | + |
| 220 | +# Happy coding :) |
0 commit comments