Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trmidboe committed Dec 27, 2021
1 parent 8e19442 commit 33e9fc8
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 51 deletions.
59 changes: 31 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ÆGIS
See the [aegis-host](https://github.com/module-federation/MicroLib) repo for documentation and a working example of a federation server.
# ÆGIS

See the [aegis-host](https://github.com/module-federation/MicroLib) repo for documentation and a working example of a federation server.

<div align="left">
<a href="https://blog.federated-microservices.com" target="_blank">
Expand All @@ -9,45 +9,48 @@ See the [aegis-host](https://github.com/module-federation/MicroLib) repo for doc
</a>
</div>

## Consolidate your microservices

- for decreased footprint,
- better performance and
- simpler operations

## Consolidate your microservices
- for decreased footprint,
- better performance and
- simpler operations

_without loosing_

- deployment independence,
- language independence
- language independence
- or component independence (i.e. components remain decoupled)

## Or distribute your components

- dynamically and adaptively
- outside the datacenter and beyond the edge

_with_

- non-functional, boilerplate code done for you
* dynamically generated APIs and datasources
* transparent integration
* built-in, extensible, observable, self-forming, high speed service mesh
* autonomous self-administration (e.g. CA certs provisioned/renewed programmatically)
* exhaustive portability: Aegis can run as a server, cluster, or serverless function, in the datacenter, on the edge and beyond (phone, drone, arduino)
- dynamically generated APIs and datasources
- transparent integration
- built-in, extensible, observable, self-forming, high speed service mesh
- autonomous self-administration (e.g. CA certs provisioned/renewed programmatically)
- exhaustive portability: Aegis can run as a server, cluster, or serverless function, in the datacenter, on the edge and beyond (phone, drone, arduino)
- and capabilities that enhance the development experience
* comprehensive, rapid deployment (deploy in seconds to any compute primitive: serverless, container, etc)
* runtime binding and hot reload (e.g. add new functionality on the fly, switch from MongoDB to Etherium live)
* zero downtime, zero installation, independent deployment (even for components running in the same process together)
* Polyglot, portable, containerless, sandboxed modules run at near native speeds
* decentralized, scalable, highly composable, "tessellated" architecture
- comprehensive, rapid deployment (deploy in seconds to any compute primitive: serverless, container, etc)
- runtime binding and hot reload (e.g. add new functionality on the fly, switch from MongoDB to Etherium live)
- zero downtime, zero installation, independent deployment (even for components running in the same process together)
- Polyglot, portable, containerless, sandboxed modules run at near native speeds
- decentralized, scalable, highly composable, "tessellated" architecture

### And do it all without deployment automation

### And do it all without deployment automation.
You don't need that anymore.

----
---

## Using ÆGIS

### Install [<img src="https://github.com/tysonrm/cluster-rolling-restart/blob/main/npm-tile.png">](https://www.npmjs.com/package/@module-federation/aegis)

```shell
npm i @module-federation/aegis
```
Expand All @@ -59,7 +62,7 @@ git clone https://github.com/module-federation/aegis
cd aegis
yarn
yarn build
yarn link
yarn link

cd ..

Expand All @@ -72,17 +75,17 @@ yarn build
yarn start
yarn demo
```

[![Aegis Overview](https://res.cloudinary.com/marcomontalbano/image/upload/v1632364889/video_to_markdown/images/youtube--n2qqgi3fTto-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://youtu.be/jddhfLA_2k0 "Aegis Overview")

# Current work
# Work in progress

- More WebAssembly features
- Run on WasmEdge runtime
- Run on WasmEdge runtime
- Run in the browser
- Run on wasm3 (for microcontrollers)
- Built-in, pluggable, fast service mesh
- Support for streaming media and realtime AI inference
- Support for QUIC, NDI, WebRTC protocols
- Addt'l datasource adapters: Etherium, Solid Pod
- Support for MLOps
- Adaptive, Autonomous (Re)deployment based on AIOps
- Adaptive, autonomous (Re)deployment based on AIOps
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/aegis",
"version": "1.0.0-beta.84",
"version": "1.0.0-beta.85",
"module": "lib/index.js",
"main": "lib/index.js",
"repository": "[email protected]:module-federation/aegis.git",
Expand Down
16 changes: 8 additions & 8 deletions src/adapters/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
editModels,
listModels,
findModels,
removeModels,
loadModels,
listConfigs,
registerCacheEvents
removeModels,
loadModelSpecs,
registerEvents
} from '../../use-cases'

import postModelFactory from './post-model'
Expand All @@ -34,16 +34,16 @@ export const getConfig = () => getConfigFactory(listConfigs())

export const initCache = () => {
const label = '\ntime to load cache'
const models = loadModels()
const specs = loadModelSpecs()

async function load () {
async function loadModelInstances () {
console.time(label)
await Promise.all(models.map(async m => m.fn()))
await Promise.allSettled(specs.map(async m => m.fn()))
console.timeEnd(label)
registerCacheEvents()
}

return {
load
load: () => loadModelInstances().then(registerEvents)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/domain/datasource-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const defaultAdapter = process.env.DATASOURCE_ADAPTER || config.MEMORYADAPTER
const DefaultDataSource = adapters[defaultAdapter]

/**
* Creates or returns the dedicated datasource for the domain model.
* @todo handle all state same way
* @typedef {{getDataSource:function(string):import("./datasource").default,listDataSources:Map[]}} DataSourceFactory
* @type {DataSourceFactory}
Expand Down
8 changes: 8 additions & 0 deletions src/domain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ const deleteEvent = model => ({
model: model
})

/**
* Register the {@link ModelSpecification}: inject dependencies,
* bind adapters, register events
* @param {Model} model
* @param {{[x:string]:{[x:string]:Function}}} services
* @param {{[x: string]:Function}} adapters
* @param {boolean} isCached
*/
function register (model, services, adapters, isCached = false) {
const serviceAdapters = bindAdapters(model.ports, adapters, services)

Expand Down
20 changes: 10 additions & 10 deletions src/services/service-mesh/web-switch/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import os from 'os'
import WebSocket from 'ws'
import makeMdns from 'multicast-dns'
import mcastDns from 'multicast-dns'

const SERVICENAME = 'webswitch'
const HOSTNAME = 'webswitch.local'
Expand All @@ -30,10 +30,10 @@ let uplinkCallback
let broker
/**@type {import('../../../domain/model-factory').ModelFactory} */
let models
/** @type {WebSocket}*/
/** @type {WebSocket} */
let ws

if (!configRoot) console.error('web-switch', 'cannot access config file')
if (!configRoot) console.error(protocol, 'cannot access config file')

function getLocalAddress () {
const interfaces = os.networkInterfaces()
Expand All @@ -57,12 +57,12 @@ function getLocalAddress () {
* @returns {Promise<string>} url
*/
async function resolveServiceUrl () {
const mdns = makeMdns()
const mdns = mcastDns()
let url

return new Promise(async function (resolve) {
mdns.on('response', function (response) {
DEBUG && console.debug('got a response packet:', response)
DEBUG && console.debug(resolveServiceUrl.name, response)

const answer = response.answers.find(
a => a.name === SERVICENAME && a.type === 'SRV'
Expand All @@ -84,7 +84,7 @@ async function resolveServiceUrl () {

if (questions[0]) {
if (isSwitch || os.hostname === HOSTNAME) {
console.debug('answering question', HOSTNAME)
console.debug('answering for', HOSTNAME)
mdns.respond({
answers: [
{
Expand Down Expand Up @@ -219,8 +219,8 @@ function startHeartBeat (ws) {
ws.ping(0x9)
} else {
try {
broker.notify(TIMEOUTEVENT, 'server unresponsive', true)
console.error('mesh server unresponsive, trying new connection')
await broker.notify(TIMEOUTEVENT, 'server unresponsive', true)
console.error(receivedPong.resolve, 'no response, trying new conn')
clearInterval(intervalId)
await reconnect()
} catch (error) {
Expand Down Expand Up @@ -255,7 +255,7 @@ export async function subscribe (eventName, callback, options = {}) {
async function _connect () {
if (!ws) {
if (!serviceUrl) serviceUrl = await resolveServiceUrl()
console.info('connecting to ', serviceUrl)
console.info(_connect.name, 'connecting to ', serviceUrl)
ws = new WebSocket(serviceUrl)

ws.on('open', function () {
Expand All @@ -264,7 +264,7 @@ async function _connect () {
})

ws.on('error', function (error) {
console.error(ws.on, 'opening new conn after error', error)
console.error(_connect.name, 'opening new conn after error', error)
ws = null
})

Expand Down
4 changes: 2 additions & 2 deletions src/use-cases/add-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import domainEvents from '../domain/domain-events'
* @typedef {Object} dependencies injected dependencies
* @property {String} modelName - name of the domain model
* @property {import('../domain/model-factory').ModelFactory} models - model factory
* @property {import('../domain/datasource').default
* @property {import('../domain/datasource').default repository - model datasource adapter
* @property {import('../domain/event-broker').EventBroker} broker - application events, propagated to domain
* @property {...Function} handlers - event handlers can be registered by the domain
* @property {...import('../domain/index').eventHandler} handlers - {@link eventHandler} configured in the model spec.
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions src/use-cases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import EventBrokerSingleton from '../domain/event-broker'
import ModelFactory from '../domain'
import brokerEvents from './broker-events'

export function registerCacheEvents () {
export function registerEvents () {
brokerEvents(
EventBrokerSingleton.getInstance(),
DataSourceFactory,
Expand Down Expand Up @@ -47,6 +47,6 @@ export const editModels = () => make(makeEditModel)
export const listModels = () => make(makeListModels)
export const findModels = () => make(makeFindModel)
export const removeModels = () => make(makeRemoveModel)
export const loadModels = () => make(makeLoadModels)
export const loadModelSpecs = () => make(makeLoadModels)
export const listConfigs = () =>
makeListConfig({ models: ModelFactory, data: DataSourceFactory })

0 comments on commit 33e9fc8

Please sign in to comment.