-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
289 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# Marble | ||
|
||
## Fallback | ||
|
||
On init, if a `fallback` file is specified, squirrel load content as first state. Allows restart without an available ETCD cluster. | ||
|
||
- If `fallback` is specified | ||
|
||
``` | ||
-A| | ||
``` | ||
|
||
A is the content of fallback file wrapped in `GET` action. | ||
|
||
```JSON | ||
{ | ||
"action": "GET", | ||
"node": { | ||
"key": "/", | ||
"dir": true, | ||
"nodes": [] | ||
} | ||
} | ||
``` | ||
|
||
- If `fallback` isn't specified | ||
|
||
``` | ||
| | ||
``` | ||
|
||
- If `fallback` file doesn't exists | ||
|
||
``` | ||
| | ||
``` | ||
|
||
## Fetcher | ||
|
||
On init, squirrel fetch ETCD until success. | ||
|
||
``` | ||
-A| | ||
``` | ||
|
||
A is the content of ETCD wrapped in `GET` action. | ||
|
||
```JSON | ||
{ | ||
"action": "GET", | ||
"node": { | ||
"key": "/", | ||
"dir": true, | ||
"nodes": [] | ||
} | ||
} | ||
``` | ||
|
||
On error, retry until is success. | ||
|
||
## Watcher | ||
|
||
Watch modification on ETCD cluster. | ||
|
||
``` | ||
-A-B-C- | ||
``` | ||
|
||
A B C are actions. | ||
|
||
`SET` action: | ||
```JSON | ||
{ | ||
"action": "set", | ||
"node": { | ||
"key": "/foo", | ||
"value": "foo", | ||
"modifiedIndex": 1438, | ||
"createdIndex": 1438 | ||
}, | ||
"prevNode": { | ||
"key": "/foo", | ||
"value": "bar", | ||
"modifiedIndex": 1437, | ||
"createdIndex": 1437 | ||
} | ||
} | ||
``` | ||
|
||
`DELETE` action: | ||
```JSON | ||
{ | ||
"action": "delete", | ||
"node": { | ||
"key": "/foo", | ||
"modifiedIndex": 1435, | ||
"createdIndex": 1434 | ||
}, | ||
"prevNode": { | ||
"key": "/foo", | ||
"value": "bar", | ||
"modifiedIndex": 1434, | ||
"createdIndex": 1434 | ||
} | ||
} | ||
``` | ||
|
||
`RESYNC` action (server cleared and outdated the index) | ||
```JSON | ||
{ | ||
"action": "resync" | ||
} | ||
``` | ||
|
||
## ETCD | ||
|
||
Combine `fallback`, `fetcher` and `watcher` observable. | ||
|
||
``` | ||
-A| // fallback | ||
-B| // fetcher | ||
--C-D-E- // watcher | ||
-ABC-D-E- | ||
``` | ||
|
||
## Combiner | ||
|
||
Aggregate ETCD's events to rebuild representation of ETCD content. | ||
|
||
``` | ||
-a-b-c- // ETCD's events | ||
------ | ||
\ \ \ | ||
A \ C | ||
B | ||
-A---BC // ConcatAll | ||
``` | ||
|
||
A & C are `SET` or `GET` events. | ||
B is a `RESYNC` event which is tranform to `fetch` observable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,9 @@ $ npm test | |
``` | ||
|
||
Please note that test use an actual etcd service | ||
|
||
|
||
|
||
|
||
## [Marble](./MARBLE.md) | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,12 @@ | ||
import {Observable} from 'rxjs'; | ||
import {parseAction} from './parser'; | ||
import createDebug from 'debug'; | ||
const debug = createDebug('squirrel:etcd'); | ||
|
||
const createFetch$ = (client, cwd) => { | ||
debug(`fetch: ${cwd}`); | ||
const list = Observable.bindNodeCallback( | ||
cb => client.get(cwd, {recursive: true}, (err, data) => cb(err, data)) | ||
); | ||
|
||
return Observable.of(1) | ||
.flatMap(() => list()) | ||
.retry(Infinity) | ||
.map(parseAction); | ||
}; | ||
|
||
const createWatcher$ = watcher => { | ||
const set$ = Observable.fromEvent(watcher, 'set'); | ||
const delete$ = Observable.fromEvent(watcher, 'delete'); | ||
const reSync$ = Observable.fromEvent(watcher, 'resync'); | ||
|
||
return Observable.merge(set$, delete$, reSync$) | ||
.map(parseAction); | ||
}; | ||
import createWatcher$ from './watch'; | ||
import createResync$ from './resync'; | ||
|
||
const createEtcd$ = (client, watcher, cwd) => { | ||
const watcher$ = createWatcher$(watcher); | ||
|
||
const events$ = watcher$.startWith({ | ||
const events$ = createWatcher$(watcher).startWith({ | ||
action: 'resync' | ||
}).flatMap(action => { | ||
if (action.action === 'resync') { | ||
debug('watcher: resync'); | ||
return createFetch$(client, cwd); | ||
} | ||
return Observable.of(action); | ||
}); | ||
|
||
return events$; | ||
return createResync$(client, cwd, events$); | ||
}; | ||
|
||
export { | ||
createFetch$, | ||
createWatcher$, | ||
createEtcd$ | ||
}; | ||
export default createEtcd$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {Observable} from 'rxjs'; | ||
import {parseAction} from './parse'; | ||
import createDebug from 'debug'; | ||
const debug = createDebug('squirrel:etcd'); | ||
|
||
const createFetch$ = (client, cwd) => { | ||
debug(`fetch: ${cwd}`); | ||
const list = Observable.bindNodeCallback( | ||
cb => client.get(cwd, {recursive: true}, (err, data) => cb(err, data)) | ||
); | ||
|
||
return Observable.of(1) | ||
.flatMap(() => list()) | ||
.retry(Infinity) | ||
.map(parseAction); | ||
}; | ||
|
||
export default createFetch$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Observable} from 'rxjs'; | ||
import createFetcher$ from './fetch'; | ||
import createDebug from 'debug'; | ||
const debug = createDebug('squirrel:etcd'); | ||
|
||
const createResync$ = (client, cwd, events$) => | ||
events$.flatMap(action => { | ||
if (action.action === 'resync') { | ||
debug('watcher: resync'); | ||
return createFetcher$(client, cwd); | ||
} | ||
return Observable.of(action); | ||
}); | ||
|
||
export default createResync$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.