Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ad0d32b
updates to run the code locally
huangqun Oct 5, 2017
31e28ce
updates to run the services locally
huangqun Oct 6, 2017
9dfa9b3
update to use core.api 4.0.1-DEV
huangqun Oct 7, 2017
2a83d45
add appirio dev repo
huangqun Oct 19, 2017
68b59cb
Merge pull request #48 from appirio-tech/local-deploy
ajefts Oct 19, 2017
2c4a4cc
new review services for admin app
huangqun Oct 19, 2017
711d4ed
fix ReviewResourceTest
huangqun Oct 23, 2017
acdc912
Merge pull request #49 from appirio-tech/admin-app-review-services
ajefts Oct 31, 2017
13eaa46
update maven repo url
huangqun Nov 1, 2017
d21758d
Merge pull request #50 from appirio-tech/admin-app-review-services
ajefts Nov 1, 2017
57ca2ad
update pom.xml to use temp maven repo
huangqun Nov 1, 2017
50f259b
Merge pull request #51 from appirio-tech/admin-app-review-services
ajefts Nov 1, 2017
ec18c79
Add GET /reviewAuctions endpoint to swagger.yaml
ThomasKranitsas Nov 20, 2017
3058d26
Merge pull request #52 from appirio-tech/update-swagger
ThomasKranitsas Nov 20, 2017
8de5a57
Rename Auctions to Opportunities
ThomasKranitsas Nov 20, 2017
e9afeb1
Add /reviewOpportunities endpoint to fetch review opps
ThomasKranitsas Nov 30, 2017
625d9a1
Merge pull request #54 from appirio-tech/add-review-opps
ajefts Nov 30, 2017
faaf907
updated docker maintainer
ajefts Nov 30, 2017
c7aca50
Update deploy.sh
Gunasekar-K Dec 1, 2017
24c139f
Update deploy.sh
Gunasekar-K Dec 1, 2017
d60f9c3
Update deploy.sh
Gunasekar-K Dec 1, 2017
ba4ef4b
Update deploy.sh
Gunasekar-K Dec 1, 2017
102b36a
Update deploy.sh
Gunasekar-K Dec 1, 2017
6500e62
Update deploy.sh
Gunasekar-K Dec 1, 2017
ff77a97
Make challengeTypeId optional and show payments based on reviewer role
ThomasKranitsas Dec 2, 2017
723d140
Merge pull request #55 from appirio-tech/review-opps-fixes
ajefts Dec 4, 2017
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
177 changes: 143 additions & 34 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,49 +1,158 @@
# Review Microservice
A microservice for generic units of work (e.g., a challenge)
Microservice for supporting Topcoder Online Review platform.

## Getting Started
This microservice is using [dropwizard](dropwizard.io) as the REST API framework and implements the [v3 API spec](https://docs.google.com/a/appirio.com/presentation/d/15pucEI0MHj9y778EyaAWGh4MBH-I73i1-GS0ir7FhxE/edit#slide=id.g29c3ffcc3_020). If you are unfamiliar with dropwizard, take a look at their [Getting Started](http://dropwizard.io/getting-started.html) page.
# Prerequisities

### Building
We are using Maven 2 to build and building is as simple as `mvn package`. *Make sure you are using Java 8 for build and runtime*
- Java 8 with Maven 2+
- Docker

### Configuration
Configuration is managed through a yaml file. The `src/main/resources/review-service.yaml` file should contain the necessary configuration for you to run locally.
# Local Deployment

### Framework Stack
- dropwizard-core - core REST API
- dropwizard-auth - user authentication
- dropwizard-jdbi - database access
- dropwizard-testing - unit testing
- mysql-connector-java - mysql JDBC driver
- fest-assert-core, mockito-core - unit testing
- slf4j - logging
### Start Informix instance via Docker

### Database
We are using mysql RDS for the database. For development use, connect to the topcoder-dev instance. Database access should be limited to the DAO layer. We are using the [JDBI](http://jdbi.org/) framework for database access. Where possible we should use the [SQL Objects API](http://jdbi.org/sql_object_overview/) approach listed in the JDBI documentation.
- Set an IP for Docker by setting the environment variable `DOCKER_IP`. Recommended to set to `0.0.0.0`

For this service, the DAO is managed by `ReviewDAO`
- Command to set the environment variable `DOCKER_IP`

**We need to keep the data model clean and name properties of our representation (model) objects as the column names so we can use the automatic bean mapping facilities instead of needing to manually wire things together. Any deviation requires prior approval.**
```
export DOCKER_IP=0.0.0.0
```

- To run Informix locally, go to the `local` folder and execute the following command:

```
docker-compose up
```

### API Endpoint
The API endpoint for this service is `com.appirio.service.review.resources.ReviewResource` It contains the specific resource paths supported by this service. The root of the service is /v3/reviews. API methods should be annotated with the appropriate jax-rs annotations and the `@Timed` annotation for metrics. An example method is shown below.
If you should ever encounter the error:

```
[java] Caused by: com.topcoder.db.connectionfactory.DBConnectionException: error occurs while creating the connection.
You already have 20 connections at this
time. Any further connections
```
@GET
@Timed
public ApiResponse getReviews(@Auth AuthUser auth,
@APIQueryParam(repClass = Review.class) QueryParameter queryParameter)
logger.debug("getReviews, filter : " + queryParameter.getFilter().getFields());

return MetadataApiResponseFactory.createResponse(reviewManager.getReviews(auth, queryParameter,
new BaseAuthorizationContext(auth)));
}
Try to restart the informix database server as below:
```
#### log into the container based on the container name got in the previous step
docker exec -it local_informix bash

#### restart the database server
onmode -ky
oninit
```

### Inserting test records

- Test data is present in SQL file (`test_data.sql`) in `local` folder.

- Transfer the `test_data.sql` to docker environment by executing the following command

```
docker cp test_data.sql local_informix:/home/informix
```

- Insert the records in `tcs_catalog` database by executing the following command

```
docker exec -it local_informix dbaccess tcs_catalog test_data.sql
```

- Docker environment is ready to be used in our service.

### Configuration Variables
The configuration file `service/src/main/resources/review-service.yaml` contain the necessary configuration to run the microservice locally. Below configuration variables need to be set using environment variables.

|Name | Description |
|--------------------|:-----------------------------------------:|
|AUTH_DOMAIN | Authentication domain of JWT, Dont set unless you have valid tokens with given AUTH_DOMAIN, Defaulted to 'topcoder-dev.com' |
|IP | The IP of your docker container |
|OLTP_USER | The Informix OLTP user |
|OLTP_PW | The Informix OLTP user password |
|OLTP_URL | The JDBC URL of Informix OLTP database |
|DW_USER | The Informix DW user |
|DW_PW | The Informix DW user password |
|DW_URL | The JDBC URL of Informix DW database |
|TC_JWT_KEY | Secret used in JWT Service, Used for signature verification as well |

In Linux, Set the environment variables as

```
export AUTH_DOMAIN=...
export IP=...
export OLTP_USER=...
export OLTP_PW=...
export OLTP_URL=...
export DW_USER=...
export DW_PW=...
export DW_URL=...
```

### Working credentials for local deployment

```
export IP=0.0.0.0
export OLTP_USER=informix
export OLTP_PW=1nf0rm1x
export OLTP_URL=jdbc:informix-sqli://$IP:2021/tcs_catalog:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
export DW_USER=informix
export DW_PW=1nf0rm1x
export DW_URL=jdbc:informix-sqli://$IP:2021/common_dw:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
export TC_JWT_KEY=secret
```

### Set up Local Maven repository for Appirio Maven

- Since maven.appirio.net is not accessible, We need to set up a local maven repository with the zip file `temp-maven-repo-master.zip`

- Unzip the contents to any of the directory in your System. **In Linux, the directory should not be a mounted directory like pen drive, hard disk, etc..**

- Open `pom.xml` in `service` directory and replace the `<url>` of Local repository with `absolute path of the unzipped file`. E.g. If you have unzipped the files to `/home/user/temp-maven-repo-master`, then POM entry will look like

```
<repository>
<id>1_temp_appirio_maven_repo</id>
<name>Appirio Maven Local Repository</name>
<url>file:///home/user/temp-maven-repo-master</url>
</repository>
```

### Build Microservice

In the `service` folder of this project, run the following command to build the service.

```
mvn clean package
```

### Start Microservice

- Before starting please ensure that all environment variables listed above is set properly and docker is up and running.

- Then start the service using the following command in the 'service' folder:

```
java -jar ./target/review-microservice-*.jar server ./src/main/resources/review-service.yaml
```

### Verification

Though there are many endpoints, For starters, it's sufficient to verify two end points.

- Endpoint `/v3/scorecards` doesn't require Authentication

- Endpoint `/v3/reviews` require Authentication

Use the postman collection in `Postman` directory to verify the end points.

- **Ensure to import the postman environment before testing the endpoints**

- Request `Get list of all Scorecards` returns all scorecard templates present in the database

**Loaded test data has details for 3 submissions for a single competition reviewed by 2 reviewers**

Note the `TCAuth` parameter provided by the `ServiceAuthenticator` class will provide user auth information and is a required parameterfor all secured API calls.
You must set up `TC_JWT_KEY` environment variable, the sample value is `4WvoZLWhFPZ5jauw2+XCU+p772S4oBN25tNPyjHR`.
- Request `Get list of all reviews Reviewer1` return the reviews done by Reviewer 1.

### Testing
All API endpoint methods should have unit tests. For this service we are following the dropwizard testing recommendations as described [here](http://dropwizard.io/manual/testing.html)
- Request `Get list of all reviews Reviewer2` return the reviews done by Reviewer 2.

For manual API testing, the [postman chrome app](https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en) is useful.
**Note: Some of the fields in returned output will be NULL, It's expected. That's how the internal controllers and services are written**
5 changes: 3 additions & 2 deletions local/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
version: '2'
services:
informix:
container_name: local_informix
image: "appiriodevops/informix:1b3d4ef"
ports:
- "2021:2021"
kafka:
image: spotify/kafka
environment:
ADVERTISED_HOST: $DOCKER_IP
ADVERTISED_PORT: 9092
ADVERTISED_HOST: ${DOCKER_IP}
ADVERTISED_PORT: 2181
ports:
- "2181:2181"
- "9092:9092"
11 changes: 11 additions & 0 deletions local/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export IP=192.168.1.2
export OLTP_USER=informix
export OLTP_PW=1nf0rm1x
export OLTP_URL=jdbc:informix-sqli://$IP:2021/tcs_catalog:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
export DW_USER=informix
export DW_PW=1nf0rm1x
export DW_URL=jdbc:informix-sqli://$IP:2021/common_dw:INFORMIXSERVER=informixoltp_tcp;IFX_LOCK_MODE_WAIT=5;OPTCOMPIND=0;STMT_CACHE=1
export TC_JWT_KEY=secret


java -jar ../service/target/review-microservice-*.jar server ../service/src/main/resources/review-service.yaml
58 changes: 58 additions & 0 deletions local/test_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
database tcs_catalog;

/* Data for a project*/

insert into project(project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date)
values(1, 1, 1, 132456, current, 132456, current);

/* Data for 2 reviewers and 3 submitters based on the token provided */
insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(2, 4, 1, 13, 1234, 132456, current, 132456, current);

insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(3, 4, 1, 13, 1235, 132456, current, 132456, current);

insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(4, 1, 1, 13, 1200, 132456, current, 132456, current);

insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(5, 1, 1, 13, 1201, 132456, current, 132456, current);

insert into resource(resource_id, resource_role_id, project_id, project_phase_id, user_id, create_user, create_date, modify_user, modify_date) values(6, 1, 1, 13, 1202, 132456, current, 132456, current);

/* Data for 3 uploads */

insert into upload(upload_id, project_id, project_phase_id, resource_id, upload_type_id, upload_status_id, parameter, create_user, create_date, modify_user, modify_date) values(1, 1, 12, 4, 1, 1, 'someparam', 132456, current, 132456, current);

insert into upload(upload_id, project_id, project_phase_id, resource_id, upload_type_id, upload_status_id, parameter, create_user, create_date, modify_user, modify_date) values(2, 1, 12, 5, 1, 1, 'someparam', 132456, current, 132456, current);

insert into upload(upload_id, project_id, project_phase_id, resource_id, upload_type_id, upload_status_id, parameter, create_user, create_date, modify_user, modify_date) values(3, 1, 12, 6, 1, 1, 'someparam', 132456, current, 132456, current);


/* Data for 3 submission */

insert into submission(submission_id, upload_id, submission_status_id, submission_type_id, create_user, create_date, modify_user, modify_date)
values(1, 1, 1, 1, 132456, current, 132456, current);

insert into submission(submission_id, upload_id, submission_status_id, submission_type_id, create_user, create_date, modify_user, modify_date)
values(2, 2, 1, 1, 132456, current, 132456, current);

insert into submission(submission_id, upload_id, submission_status_id, submission_type_id, create_user, create_date, modify_user, modify_date)
values(3, 3, 1, 1, 132456, current, 132456, current);


/* 3 submissions for a single competition reviewed by 2 reviewers*/

insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
values(1, 2, 1, 13, 30000410, 1, 100, 95, 132456, current, 132456, current);

insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
values(2, 3, 1, 13, 30000410, 1, 100, 95, 132456, current, 132456, current);

insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
values(3, 2, 2, 13, 30000410, 1, 65, 55, 132456, current, 132456, current);

insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
values(4, 3, 2, 13, 30000410, 1, 70, 60, 132456, current, 132456, current);

insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
values(5, 2, 3, 13, 30000410, 1, 90, 87, 132456, current, 132456, current);

insert into review(review_id, resource_id, submission_id, project_phase_id, scorecard_id, committed, score, initial_score, create_user, create_date, modify_user, modify_date)
values(6, 3, 3, 13, 30000410, 1, 84.36, 78, 132456, current, 132456, current);
Loading