Image Infection - Final Specifications
Overview
This is the full specification of what you have to have compleated for the final presentation. In this we are descirbing the minimum functionality that will need to be present on the tile and canvas servers to allow us to run the final project on Tuesday Dec. 12.
Full Tile Server API Specification
The following is the full set of routes that must be implemented on your tile server. These routes are to be used by the canvas server and other tile servers to work with your tile server. You must correctly implement all of these routes.
@app.route('/registered', methods=["PUT"])
# puts a json with
# authToken : auth token from the server
# approved : true or false
# voteToken : auth token for voting if approved is true
# xloc : int //tile location
# yloc : int // tile location
# 401 Unauthorized if auth token does not match
# otherwise return 200 "success"
@app.route('/image', methods=["GET"])
# returns the PNG image that was approved
# returns 404 if there is no approved image
@app.route('/tile', methods=["GET"])
# returns the PNG of your tile this must be of tilesize x tilesize dim
# returns 404 if there is no approved image
@app.route('/votes', methods=["GET"])
# returns a json containing the following
# votes : int // the number of votes that the tile has
@app.route('/votes', methods=["PUT"])
# accepts a json with the follwing
# authToken : auth token from the tile server
# votes : the new number of votes you have this is an absolute
# seq : this is a increasing count of number of changes
# 401 Unauthorized if auth token does not match
# 409 Conflict if the seq is smaller than the last seq you recieved
# 200 otherwise and update stored seq and votes
@app.route('/update', methods=["PUT"])
# accepts a json with the following
# authToken : auth token from the tile server
# neighbors : an array of urls of your neighbors
# 401 Unauthorized if auth token does not match
# 200 otherwise and checks neighbors for votes and updates image to the winner
You will also need to add to your tile server an interface using routes to allow you to accomplish the following tasks.
-
Register your tile server with a canvas server
-
Select an image to register for your tile server
-
Vote for a tile of your choice on the canvas server you are registered with
-
Get the status of your tile server including at least if you image has been approved and the location of your tile in the whole canvas.
You may want more interface than that but that represents the minimum required interface you must implement for your tile server.
The update interface
There is only one new route in this API from what you have already finished in weeks 1 and 2. The new interface is
PUT /update
which will be used by the canvas to tell tile services to update based on their current votes. This put request will post a json with two fields authToken
and neighbors
which looks like the following.
{
"authToken": "a5630ec7-165f-4d0a-9f17-7da3cb5fcc50",
"neighbors": ["http://127.0.0.1:34001/", "http://127.0.0.1:34002/", "http://127.0.0.1:34003/"]
}
In the above example you see what might be a reasonable set to be getting for your testing. This would tell your tile server that it has three neighbors running on localhost pots 34001, 34002, and 34003.
When a tile server recives this request it must do the following.
-
Verify if the
authToken
is the token that it provided to the canvas server when it registered. If it is not it will return an HTTP/401 “Unauthorized” and do nothng else. -
If the
authToken
is correct the tile server will conect to each neighbor to get their votes and update as neeed.
The update process works as follows. If there are no neighbors that have more votes than the tile server the tile server does nothing. If on the other hand at least one neighbor has more votes than the tile server the tile server will select one of the neighbors with the most votes and gets the full image from that neighbor to update their image and tile PNGs to the new ones.
Full Canvas Server API Specification
The production canvas server will implement the following public interface and you can depend on it. There will be other interfaces implemented for grading and presentation but this is the set that are guaranteed to be present.
@app.route('/registerClient/<clientID>', methods=["PUT"])
# this puts a json with the following
# token : auth token for the server
# url : "http://server:port/"
# author : "Your Name"
# if clientID is in use return 415 "ClientID already exists"
# post json with microservice ip and port
# otherwise return 200 "success" and json with
# xdim : int // in tiles
# ydim : int // in tiles
# tilesize : int
@app.route('/registerImage/<clientID>', methods=["POST"])
# post png image of correct size
# 500 "Image size invalid" if image does not match required size
# 416 "ClientID not registered" if client was not registered
# otherwise return 200 "success"
@app.route('/vote/<clientID>', methods=["PUT"])
# this puts a json with the following
# voteToken : auth token for the server
# xloc : x location of the tile
# yloc : y location of the tile
# 401 Unauthorized if your voteToken is not correct
# returns 200 "success" if vote acceped
@app.route('/canvas', methods=["GET"])
# returns a PNG of the whole canvas
The only new route in the full api is GET /canvas
which provides direct access to the current canvas image.