Skip to content

Commit

Permalink
upate packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperstore committed Mar 30, 2018
2 parents 761e81f + e2ffb30 commit 16fd6a5
Show file tree
Hide file tree
Showing 29 changed files with 346 additions and 340 deletions.
63 changes: 11 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vulcain-corejs",
"version": "2.0.0-beta939",
"version": "2.0.0-beta952",
"description": "Vulcain micro-service framework",
"main": "lib/src/index.js",
"scripts": {
Expand All @@ -23,33 +23,33 @@
"license": "Apache-2.0",
"typings": "lib/src/index.d.ts",
"devDependencies": {
"@types/amqplib": "^0.5.6",
"@types/amqplib": "^0.5.7",
"@types/chai": "^4.1.0",
"@types/fast-stats": "0.0.29",
"@types/jsonwebtoken": "^7.2.5",
"@types/mocha": "^2.2.46",
"@types/mocha": "^5.0.0",
"@types/mongodb": "^3.0.9",
"chai": "^4.1.2",
"mocha": "^5.0.0",
"mocha": "^5.0.4",
"tslint": "^5.9.1",
"typescript": "^2.6.2"
"typescript": "^2.7.2"
},
"dependencies": {
"amqplib": "^0.5.2",
"fast-stats": "0.0.3",
"graphql": "^0.13.2",
"jaeger-client": "^3.7.0",
"jsonwebtoken": "^8.1.0",
"moment": "^2.20.1",
"mongodb": "^2.2.34",
"graphql": "^0.13.1",
"jaeger-client": "^3.10.0",
"jsonwebtoken": "^8.2.0",
"moment": "^2.21.0",
"mongodb": "^3.0.4",
"prom-client": "^11.0.0",
"reflect-metadata": "^0.1.3",
"router": "^1.3.2",
"rxjs": "^5.5.6",
"swagger-ui-dist": "^3.9.0",
"rxjs": "^5.5.7",
"swagger-ui-dist": "^3.12.1",
"unirest": "^0.5.0",
"uuid": "^3.0.1",
"validator": "^9.2.0",
"validator": "^9.4.1",
"zipkin": "^0.12.0",
"zipkin-transport-http": "^0.12.0"
}
Expand Down
72 changes: 42 additions & 30 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ActionHandler } from './pipeline/handlers/action/annotations';
import { GraphQLActionHandler } from './graphql/graphQLHandler';
import { GraphQLAdapter } from "./graphql/graphQLAdapter";
import { HystrixSSEStream as hystrixStream } from './commands/http/hystrixSSEStream';
import { HandlerProcessor } from '.';

const vulcainExecutablePath = __dirname;
const applicationPath = Path.dirname(module.parent.parent.filename);
Expand All @@ -38,6 +39,7 @@ const applicationPath = Path.dirname(module.parent.parent.filename);
*/
export class Application {
private _domain: Domain;
private _initialized = false;

public useMongoProvider(address: string) {
this.container.useMongoProvider(address);
Expand Down Expand Up @@ -93,20 +95,28 @@ export class Application {
throw new Error("Domain name is required.");
}

Service.defaultDomainName = this.domainName;
Service.setDomainName(this.domainName);
this._container = this._container || new Container();
this.container.registerHTTPEndpoint("GET", Conventions.instance.defaultHystrixPath, hystrixStream.getHandler());
}

private async init() {

/**
* Only use it for testing. Used start instead
*/
public async init() {
if (this._initialized)
return;

this._initialized = true;
await DynamicConfiguration.init().startPolling();

Service.log.info(null, () => "Starting application");

this._container.injectInstance(this, DefaultServiceNames.Application);
this._domain = new Domain(this.domainName, this._container);
this._container.injectInstance(this._domain, DefaultServiceNames.Domain);

this.container.registerHTTPEndpoint("GET", Conventions.instance.defaultHystrixPath, hystrixStream.getHandler());

process.on('unhandledRejection', (reason, p) => {
Service.log.info(null, () => `Unhandled Rejection at ${p} reason ${reason}")`);
});
Expand All @@ -124,6 +134,32 @@ export class Application {
commandBus.stopReception();
}
});

let local = new LocalAdapter();
let eventBus = this.container.get<IEventBusAdapter>(DefaultServiceNames.EventBusAdapter, true);
if (!eventBus) {
this.container.injectInstance(local, DefaultServiceNames.EventBusAdapter);
eventBus = local;
}
let commandBus = this.container.get<IActionBusAdapter>(DefaultServiceNames.ActionBusAdapter, true);
if (!commandBus) {
this.container.injectInstance(local, DefaultServiceNames.ActionBusAdapter);
commandBus = local;
}

this.registerComponents();
Preloader.instance.runPreloads(this.container, this._domain);

await eventBus.open();
await commandBus.open();

let scopes = this.container.get<ScopesDescriptor>(DefaultServiceNames.ScopesDescriptor);
this.defineScopeDescriptions(scopes);

let descriptors = this.container.get<ServiceDescriptors>(DefaultServiceNames.ServiceDescriptors);
descriptors.getDescriptions(); // ensures handlers table is created

this.container.injectSingleton(HandlerProcessor, DefaultServiceNames.HandlerProcessor );
}

/**
Expand Down Expand Up @@ -151,30 +187,6 @@ export class Application {
try {
await this.init();

let local = new LocalAdapter();
let eventBus = this.container.get<IEventBusAdapter>(DefaultServiceNames.EventBusAdapter, true);
if (!eventBus) {
this.container.injectInstance(local, DefaultServiceNames.EventBusAdapter);
eventBus = local;
}
let commandBus = this.container.get<IActionBusAdapter>(DefaultServiceNames.ActionBusAdapter, true);
if (!commandBus) {
this.container.injectInstance(local, DefaultServiceNames.ActionBusAdapter);
commandBus = local;
}

this.registerComponents();
Preloader.instance.runPreloads(this.container, this._domain);

await eventBus.open();
await commandBus.open();

let scopes = this.container.get<ScopesDescriptor>(DefaultServiceNames.ScopesDescriptor);
this.defineScopeDescriptions(scopes);

let descriptors = this.container.get<ServiceDescriptors>(DefaultServiceNames.ServiceDescriptors);
descriptors.getDescriptions(); // ensures handlers table is created

let server = new VulcainServer(this.domain.name, this._container);
server.start(port);
}
Expand Down
30 changes: 14 additions & 16 deletions src/bus/localAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
import { IActionBusAdapter, IEventBusAdapter } from '../bus/busAdapter';
import { EventData } from "./messageBus";
import { RequestData } from "../pipeline/common";
import * as RX from 'rxjs';

export
class LocalAdapter implements IActionBusAdapter, IEventBusAdapter {
private eventHandler: (event: EventData) => void;
private commandHandler: (event: RequestData) => void;
private eventQueue: RX.Subject<EventData>;
private taskQueue: RX.Subject<RequestData>;

open() {
this.eventQueue = new RX.Subject<EventData>();
this.taskQueue = new RX.Subject<RequestData>();
return Promise.resolve();
}

stopReception() { }
stopReception() {
this.eventQueue = null;
this.taskQueue = null;
}

sendEvent(domain: string, event: EventData) {
// console.log("Event: %j", event);
let self = this;
self.eventHandler && setTimeout(function () {
self.eventHandler(event);
}, (1));
this.eventQueue && this.eventQueue.next(event);
}

consumeEvents(domain: string, handler: (event: EventData) => void, queueName?:string) {
this.eventHandler = handler;
consumeEvents(domain: string, handler: (event: EventData) => void, queueName?: string) {
this.eventQueue && this.eventQueue.subscribe(handler);
}

publishTask(domain: string, serviceId: string, command: RequestData) {
let self = this;
self.commandHandler && setTimeout(function () {
// console.log("Running task: %j", command);
self.commandHandler(command);
}, (1));
this.taskQueue && this.taskQueue.next(command);
}

consumeTask(domain: string, serviceId: string, handler: (event: RequestData) => void) {
this.commandHandler = handler;
this.taskQueue && this.taskQueue.subscribe(handler);
}
}
4 changes: 2 additions & 2 deletions src/bus/messageBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export interface EventData extends RequestData {
source: string;
error?: string;
userContext: UserContextData;
startedAt: string;
completedAt?: string;
startedAt: number;
completedAt?: number;
status: string;
}

Expand Down
2 changes: 2 additions & 0 deletions src/commands/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class HystrixCommand {

let result;

this.command.context.logInfo(() => `Executing command ${this.properties.commandName} with properties ${JSON.stringify(this.properties)}`);

// Execution
this.hystrixMetrics.incrementExecutionCount();
let recordTotalTime = true;
Expand Down
4 changes: 4 additions & 0 deletions src/configurations/properties/chainedPropertyValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ export class ChainedDynamicProperty<T> extends DynamicProperty<T> {
v = this._activeProperty.value;
return v || this.defaultValue;
}

public toJSON(key: string) {
return key ? String(this.value) : this.name + "=" + String(this.value);
}
}
4 changes: 4 additions & 0 deletions src/configurations/properties/dynamicProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ export class DynamicProperty<T> implements IDynamicProperty<T>, IUpdatableProper
this._propertyChanged = null;
this.removed = true;
}

public toJSON(key: string) {
return key ? String(this.value) : this.name + "=" + String(this.value);
}
}
3 changes: 1 addition & 2 deletions src/configurations/sources/httpConfigurationSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AbstractRemoteSource } from "./abstractRemoteSource";
import { Service } from "../../globals/system";

const rest = require('unirest');
const moment = require('moment');

export class HttpConfigurationSource extends AbstractRemoteSource {
protected lastUpdate: string;
Expand Down Expand Up @@ -49,7 +48,7 @@ export class HttpConfigurationSource extends AbstractRemoteSource {
values = new Map<string, ConfigurationItem>();
let data = response.body;
data.value && data.value.forEach(cfg => values.set(cfg.key, cfg));
self.lastUpdate = moment.utc().format();
self.lastUpdate = Service.nowAsString();
self.mergeChanges(values);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/configurations/sources/vulcainConfigurationSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { HttpConfigurationSource } from './httpConfigurationSource';
import { DataSource } from '../abstractions';
import { Service } from '../../globals/system';
const rest = require('unirest');
const moment = require('moment');

export class VulcainConfigurationSource extends HttpConfigurationSource {

Expand Down
Loading

0 comments on commit 16fd6a5

Please sign in to comment.