Skip to content

Commit

Permalink
add registry service
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyaoi committed Nov 11, 2018
1 parent b864ef0 commit 38a4eeb
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 8 deletions.
3 changes: 2 additions & 1 deletion discovery/src/controller/index.ts
@@ -1,3 +1,4 @@
export { default as system } from './system';
export { default as package } from './package';
export { default as pretrained } from './pretrained';
export { default as pretrained } from './pretrained';
export { default as registry } from './registry';
2 changes: 1 addition & 1 deletion discovery/src/controller/package.ts
Expand Up @@ -4,7 +4,7 @@ import { ImportPackageRequest } from './entity';
export default class PackageController {
public static async importPackage (ctx: Context) {
const toImportPackage: Package = new Package();

console.log(toImportPackage);
}
}
15 changes: 15 additions & 0 deletions discovery/src/controller/registry.ts
@@ -0,0 +1,15 @@
import { Context } from 'koa';
import { addRegistry } from '../dynamo/action';

export default class RegistryController {
public static async putRegistry (ctx: Context) {
const body = ctx.request.body;
addRegistry(body.name, body.urlPrefix);
ctx.status = 200;
ctx.body = {
'code': 200,
'desc': 'success',
'req': body
};
}
}
16 changes: 14 additions & 2 deletions discovery/src/dynamo/action.ts
@@ -1,5 +1,5 @@
import mapper from './dynamo';
import { Package, Pretrained } from './entity';
import { Package, Pretrained, Registry } from './entity';
import { Guid } from 'guid-typescript';
import { isSymbol } from 'util';

Expand Down Expand Up @@ -54,8 +54,20 @@ async function getPretrained () {
return results;
}

async function addRegistry (name: string, urlPrefix: string) {
const toAddRegistry = Object.assign(new Registry, {
id: Guid.create(),
name: name,
urlPrefix: urlPrefix,
});
mapper.put(toAddRegistry).then(objectSaved => {
console.log(objectSaved);
});
}

export {
putPretrained,
putPackage,
getPretrained
getPretrained,
addRegistry
};
18 changes: 17 additions & 1 deletion discovery/src/dynamo/entity.ts
Expand Up @@ -38,7 +38,23 @@ class Pretrained {
name: string;
}

@table('cvpm-registry')
class Registry {
@hashKey()
id: string;

@rangeKey({defaultProvider: () => new Date()})
createdAt: Date;

@attribute()
name: string;

@attribute()
urlPrefix: string;
}

export {
Package,
Pretrained
Pretrained,
Registry
};
2 changes: 1 addition & 1 deletion discovery/src/logging.ts
Expand Up @@ -43,7 +43,7 @@ export function logger(winstonInstance: any) {
new Logsene({
token: process.env.LOGSENE_TOKEN,
type: 'discovery',
level:'error',
level: 'error',
})
]
});
Expand Down
4 changes: 4 additions & 0 deletions discovery/src/routes.ts
Expand Up @@ -5,8 +5,12 @@ import controller = require('./controller');
const router = new Router();

router.get('/system/status', controller.system.getSystemStatus);

router.post('/packages', controller.package.importPackage);

router.put('/pretrained', controller.pretrained.importPretrained);
router.get('/pretrained', controller.pretrained.getAllPretrained);

router.put('/registry', controller.registry.putRegistry);

export { router };
2 changes: 1 addition & 1 deletion discovery/src/server.ts
@@ -1,6 +1,6 @@
import * as cors from '@koa/cors';
import * as Koa from 'koa';
import * as bodyParser from 'koa-bodyparser';
import bodyParser from 'koa-bodyparser-ts';
import * as helmet from 'koa-helmet';
import * as winston from 'winston';

Expand Down
2 changes: 1 addition & 1 deletion discovery/tsconfig.json
Expand Up @@ -10,7 +10,7 @@
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"typeRoots": [
"node_modules/koa-bodyparser",
"node_modules/koa-bodyparser-ts",
"node_modules/**/*",
"node_modules/@types"
],
Expand Down

0 comments on commit 38a4eeb

Please sign in to comment.