-
Notifications
You must be signed in to change notification settings - Fork 7
added some stuff to adapters.md and minor formatting edits #17
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
Changes from 5 commits
a6f2a0c
cebb7bd
a13f8e0
9bea2ce
b6baefe
af41214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!-- | ||
|
||
- -> | ||
# Service Map | ||
|
||
## Welcome! | ||
|
@@ -12,16 +12,35 @@ They can be written in any language, and must simply respond to a set of HTTP en | |
## Basic Concept | ||
Here's a diagram illustrating the basic concept of Yacs and adapters: | ||
|
||
<!--  --> | ||
<!--  - -> | ||
======== | ||
DIAGRAM GOES HERE | ||
======== | ||
<!-- TODO: Make diagram --> | ||
<!-- | ||
When Yacs needs information that isn't stored in its database, it sends an HTTP request to the adapter that is responsible for that information. Then that adapter works its magic, and sends the information back in JSON format. This document is going to focus on the [`yaml-rpi`][yaml-rpi-adapter] adapter and use its code in examples. | ||
<!-- TODO: Make diagram --><!-- | ||
|
||
- -> | ||
When Yacs needs information that isn't stored in its database, it sends an HTTP request to the adapter that is responsible for that information. Then that adapter works its magic, and sends the information back in JSON format. This document is going to focus on the [`yaml-rpi`][yaml-rpi-adapter] adapter and use its code in examples. The document `app.rb` will also be edited for clarity to this: | ||
|
||
``` ruby | ||
require 'sinatra' | ||
require 'sinatra/json' | ||
require 'oj' | ||
require 'yaml' | ||
|
||
set :bind, '0.0.0.0' | ||
set :port, 4600 | ||
|
||
ENV['YAML_SOURCE'] ||= 'schools-and-subjects.yml' | ||
|
||
get "/:term_shortname" do | ||
file = open(ENV['YAML_SOURCE']) | ||
yaml_content = YAML.load(file) | ||
json yaml_content | ||
end | ||
``` | ||
|
||
## Data Source | ||
The first thing your adapter needs is a place to get data from. In the `yaml-rpi` adapter, that place is a file called `schools-and-subjects.yml`. | ||
The first thing your adapter needs is a place to get data from. In the `yaml-rpi` adapter, that place is a file called `schools-and-subjects.yml`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if this is the best example to start with. It is the simplest, but it is also the least useful. It is not typical that data will be coming from a config file, and I don't necessarily want to encourage people to use adapters that way. Although they can be used like this, they are intended to ingest dynamic data from some other source on the web. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, do you think this markdown should use a script in another language? There's quite a few ruby/sinatra specific parts for the adapters as far as I can tell. Maybe it'd be better to use python or pseudo-code in the toy example code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly, I don't think ruby is a bad choice here, we just need to find the right format for this guide. |
||
|
||
```yml | ||
|
||
|
@@ -41,15 +60,22 @@ schools: | |
|
||
``` | ||
|
||
Now that we have a place to get information from, we need to load it into the adapter. We do so with this line: | ||
Now that we have a place to get information from, we need to load it into the adapter. We do so with this line in `app.rb`: | ||
|
||
```ruby | ||
``` ruby | ||
|
||
# ... | ||
require 'yaml' | ||
|
||
ENV['YAML_SOURCE'] ||= 'schools-and-subjects.yml' | ||
|
||
# ... | ||
file = open(ENV['YAML_SOURCE']) | ||
yaml_content = YAML.load(file) | ||
# ... | ||
``` | ||
|
||
Here, `ENV` is just a container for the environment variables in Ruby, and `'YAML_SOURCE'` is the name of the environment variable. We're setting its value to the name of the file, `'schools-and-subjects.yml'`, and essentially that 'loads' it into the adapter. | ||
Here, `ENV` is just a container for the environment variables in Ruby, and `'YAML_SOURCE'` is the name of the environment variable. We're setting its value to the name of the file, `'schools-and-subjects.yml'`. Then, when the adapter is asked for information, it first opens a file at the location, then uses a function from the `'yaml'` package to convert the file's contents to a ruby object. | ||
|
||
## JSON API and REST | ||
Your adapter then needs to convert the data that it loaded into a format that Yacs can read - that's what the JSON API is for. This document will give a brief explanation of the API - a more in-depth explanation can be found [here][json-api]. | ||
|
@@ -68,17 +94,49 @@ The JSON API is based off of JavaScript Object Notation: | |
|
||
``` | ||
|
||
Notice that objects are surrounded by `{curly brackets}`, and both attributes and values are surrounded by `"double quotes"`. Each attribute-value pair is specified by a single line, with a colon separating attributes and values, and attribute-value pairs are separated by a comma. Note that spacing is irrelevant to the formatting of the document except in strings -- anything between double quotes must be on a single line. | ||
Objects are surrounded by `{curly brackets}`, and both attributes and values are surrounded by `"double quotes"`. Each attribute-value pair is specified by a single line, with a colon separating attributes and values, and attribute-value pairs are separated by a comma. Spacing is irrelevant to the formatting of the document except in strings -- anything between double quotes must be on a single line. Finally, there is no syntax for making comments. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's within the scope of this documentation to explain how JSON works. I'd rather just provide a link as a reference. |
||
|
||
In the `yaml-rpi` adapter, this is done through these lines in `app.rb`: | ||
|
||
```ruby | ||
|
||
In the `yaml-rpi` adapter, this is done through | ||
require 'sinatra/json' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While helpful for understanding this particular adapter's code, I think including such specific information about ruby distracts the reader from what is important. If I'm new to this project and want to write an adapter, I probably won't use ruby if I don't already know it. |
||
require 'oj' | ||
|
||
# ... | ||
json yaml_content | ||
|
||
``` | ||
|
||
`require 'sinatra/json'` and `require 'oj'` tell ruby to load the Sinatra package's JSON helper function and the Optimized JSON package respectively. Then when the adapter needs to convert the data in `yaml_content` to JSON, the `json` function from `'sinatra/json'` is called. | ||
|
||
|
||
## HTTP Protocol | ||
|
||
<!-- IDK what to do here, I don't really understand this part fully yet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just setting up the web server, and is very specific to Sinatra, the web framework we use in most of the adapters. |
||
|
||
- -> | ||
|
||
```ruby | ||
|
||
# ... | ||
require 'sinatra' | ||
|
||
set :bind, '0.0.0.0' | ||
set :port, 4600 | ||
|
||
# ... | ||
|
||
get "/:term_shortname" do | ||
# ... | ||
end | ||
|
||
``` | ||
|
||
## Implementation Agnostic | ||
Notice that the only parts of the adapter that actually interact with YACS itself are format of the data (JSON) and the data transfer protocol (HTTP). Since both of these systems are implementation agnostic, you can write your adapter in whatever language you want! As long as it responds to HTTP requests with a JSON object, it's good to go! | ||
|
||
[yacs-adapters]: https://github.com/YACS-RCOS/yacs/tree/master/adapters | ||
[yaml-rpi-adapter]: https://github.com/YACS-RCOS/yacs/tree/master/adapters/yaml-rpi | ||
[json-api]: http://jsonapi.org/format/ | ||
--> | ||
<!-- --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ This is a good place to start if you don't know where something lives, or want t | |
The above diagram shows how each of the services connect. | ||
For more in-depth information on how Yacs operates as a whole, see [overview](architecture/overview) | ||
|
||
### [core](https://github.com/yacs-rcos/yacs/blob/master/core) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all of these changes are in your other PR, can we remove them from here and vice versa? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open another PR with just adapter.md changes |
||
### [core][core-repo] | ||
|
||
Yacs is currently the largest service. | ||
To avoid confusion, we'll call this "Yacs Core", or just "Core". | ||
|
@@ -23,7 +23,7 @@ It provides a REST API for accessing and manually updating this data. | |
Yacs Core is also responsible for generating schedules, and computing section conflicts. | ||
It is a Rails 5 app, and uses PostgreSQL to store data. | ||
|
||
### [web](https://github.com/yacs-rcos/yacs/blob/master/web) | ||
### [web][web-repo] | ||
|
||
Yacs Web is the primary student-facing frontend for Yacs. | ||
It is written in Typescript with Angular 6. | ||
|
@@ -32,50 +32,61 @@ It provides the interface for browsing, searching, and selecting courses, as wel | |
It will also provide an interface for receiving notifications (planned). | ||
If you are a new contributor, this is probably the best place to look for work to do as well. | ||
|
||
### [admin](https://github.com/yacs-rcos/yacs-admin) | ||
### [admin][admin-repo] | ||
|
||
Yacs Admin is the administrative frontend for Yacs. | ||
It is an interface for administrators, instructors, and sysadmins to make manual updates to the Yacs database. | ||
In practice, it is typically used for correcting errors, updating course details, and managing non-catalog (special topics) courses. | ||
|
||
### [malg](https://github.com/yacs-rcos/yacs/blob/master/malg) | ||
### [malg][malg-repo] | ||
|
||
Yacs Malg is the 'secret sauce' that connects Yacs to your university. | ||
It pulls data from JSON data sources, and intelligently and configurably combines (amalgamates) it into a master graph. | ||
The graph serialized and stored in Redis for internal persistance, and every entity is written to a Kafka topic as well for further processing and storage. | ||
Malg polls each data source at regular intervals, and continually writes changes to Redis and Kafka. | ||
|
||
### [adapters](https://github.com/yacs-rcos/yacs/blob/master/adapters) | ||
### [adapters][adapters-repo] | ||
|
||
Yacs uses services called adapters to pull data from a university's systems, and transform that data into a form Yacs can ingest. | ||
Each data source has a corresponding adapter, which, when combined, provide a complete picture of a university's academic data. | ||
It is very easy to create new adapters - more information explaining them can be found on the [adapters documentation](https://yacs.io/#/architecture/adapters). | ||
They can be written in any language, and must simply respond to a set of http endpoints. | ||
|
||
### [users](https://github.com/yacs-rcos/yacs/blob/master/users) | ||
### [users][users-repo] | ||
|
||
Yacs Users is the user authentication server for Yacs. | ||
It is a full stack Rails 5 app, and uses devise for authentication. | ||
It also handles storing user data, and provides a REST API for accessing and modifying that data (planned). | ||
|
||
### [notifications](https://github.com/yacs-rcos/yacs/blob/master/notifications) | ||
### [notifications][notifications-repo] | ||
|
||
Yacs Notifications serves the streaming API for changes to Yacs objects. | ||
It allows clients to receive notifications regarding courses and sections they are interested in. | ||
|
||
### [docs](https://github.com/yacs-rcos/docs) | ||
### [docs][docs-repo] | ||
|
||
Docs is the repository for this documentation! | ||
It uses Docsify, and awesome static site generator that generates beautiful documentation from everyday Markdown files. | ||
Because we have a bunch of repos, documentation goes in here so it is easier to find, with the exception of each service's README. | ||
|
||
### [nginx](https://github.com/yacs-rcos/yacs-nginx) | ||
### [nginx][nginx-repo] | ||
|
||
The nginx configuration we use to deploy Yacs. | ||
It has reverse proxies for the external APIs and services the frontend builds. | ||
|
||
### [auth](https://github.com/yacs-rcos/yacs-auth) | ||
### [auth][auth-repo] | ||
|
||
Yacs Auth is a microservice authorization library. | ||
It contains our authorization logic and session management, which uses JSON Web Tokens (JWT) with Redis for session handling and validation. | ||
This library allows any service to authenticate a user and validate or invalidate their session, as long as that service is connected to the shared Redis instance. | ||
|
||
[core-repo]: https://github.com/yacs-rcos/yacs/blob/master/core | ||
[web-repo]: https://github.com/yacs-rcos/yacs/blob/master/web | ||
[admin-repo]: https://github.com/yacs-rcos/yacs-admin | ||
[malg-repo]: https://github.com/yacs-rcos/yacs/blob/master/malg | ||
[adapters-repo]: https://github.com/yacs-rcos/yacs/blob/master/adapters | ||
[users-repo]: https://github.com/yacs-rcos/yacs/blob/master/users | ||
[notifications-repo]: https://github.com/yacs-rcos/yacs/blob/master/notifications | ||
[docs-repo]: https://github.com/yacs-rcos/docs | ||
[nginx-repo]: https://github.com/yacs-rcos/yacs-nginx | ||
[auth-repo]: https://github.com/yacs-rcos/yacs-auth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't technically correct. Every adapter is polled on a fixed interval, and Yacs saves the combined result/