Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Get samples from github (#146)
Browse files Browse the repository at this point in the history
Added a service to be able to retrieve sample networks from github
  • Loading branch information
cazfletch authored Feb 10, 2017
1 parent 1c1b760 commit 07e0924
Show file tree
Hide file tree
Showing 12 changed files with 464 additions and 446 deletions.
60 changes: 47 additions & 13 deletions packages/composer-connector-server/lib/connectorserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const BusinessNetworkDefinition = require('composer-common').BusinessNetworkDefi
const Logger = require('composer-common').Logger;
const realSerializerr = require('serializerr');
const uuid = require('uuid');
const exec = require('child_process').exec;

const LOG = Logger.getLog('ConnectorServer');

Expand All @@ -27,7 +28,7 @@ const LOG = Logger.getLog('ConnectorServer');
* @param {Error} error The error to serialize with serializerr.
* @return {Object} The error serialized by serializerr.
*/
function serializerr(error) {
function serializerr (error) {
if (error instanceof Error) {
return realSerializerr(error);
} else {
Expand All @@ -47,7 +48,7 @@ class ConnectorServer {
* @param {ConnectionProfileManager} connectionProfileManager The connection profile manager to use.
* @param {Socket} socket The connected socket to use for communicating with the client.
*/
constructor(connectionProfileStore, connectionProfileManager, socket) {
constructor (connectionProfileStore, connectionProfileManager, socket) {
const method = 'constructor';
LOG.entry(method, connectionProfileStore, connectionProfileManager, socket);
this.connectionProfileStore = connectionProfileStore;
Expand Down Expand Up @@ -76,7 +77,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionManagerConnect(connectionProfile, businessNetworkIdentifier, connectionOptions, callback) {
connectionManagerConnect (connectionProfile, businessNetworkIdentifier, connectionOptions, callback) {
const method = 'connectionManagerConnect';
LOG.entry(method, connectionProfile, businessNetworkIdentifier, connectionOptions);
return this.connectionProfileStore.load(connectionProfile, connectionOptions)
Expand Down Expand Up @@ -111,7 +112,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionDisconnect(connectionID, callback) {
connectionDisconnect (connectionID, callback) {
const method = 'connectionDisconnect';
LOG.entry(method, connectionID);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -142,7 +143,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionLogin(connectionID, enrollmentID, enrollmentSecret, callback) {
connectionLogin (connectionID, enrollmentID, enrollmentSecret, callback) {
const method = 'connectionLogin';
LOG.entry(method, connectionID, enrollmentID, enrollmentSecret);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -176,7 +177,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionDeploy(connectionID, securityContextID, force, businessNetworkBase64, callback) {
connectionDeploy (connectionID, securityContextID, force, businessNetworkBase64, callback) {
const method = 'connectionDeploy';
LOG.entry(method, connectionID, securityContextID, force, businessNetworkBase64);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -219,7 +220,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionUpdate(connectionID, securityContextID, businessNetworkBase64, callback) {
connectionUpdate (connectionID, securityContextID, businessNetworkBase64, callback) {
const method = 'connectionUpdate';
LOG.entry(method, connectionID, securityContextID, businessNetworkBase64);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -262,7 +263,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionUndeploy(connectionID, securityContextID, businessNetworkIdentifier, callback) {
connectionUndeploy (connectionID, securityContextID, businessNetworkIdentifier, callback) {
const method = 'connectionUndeploy';
LOG.entry(method, connectionID, securityContextID, businessNetworkIdentifier);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -300,7 +301,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionPing(connectionID, securityContextID, callback) {
connectionPing (connectionID, securityContextID, callback) {
const method = 'connectionPing';
LOG.entry(method, connectionID, securityContextID);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -340,7 +341,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionQueryChainCode(connectionID, securityContextID, functionName, args, callback) {
connectionQueryChainCode (connectionID, securityContextID, functionName, args, callback) {
const method = 'connectionQueryChainCode';
LOG.entry(method, connectionID, securityContextID, functionName, args);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -380,7 +381,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionInvokeChainCode(connectionID, securityContextID, functionName, args, callback) {
connectionInvokeChainCode (connectionID, securityContextID, functionName, args, callback) {
const method = 'connectionInvokeChainCode';
LOG.entry(method, connectionID, securityContextID, functionName, args);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -420,7 +421,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionCreateIdentity(connectionID, securityContextID, userID, options, callback) {
connectionCreateIdentity (connectionID, securityContextID, userID, options, callback) {
const method = 'connectionCreateIdentity';
LOG.entry(method, connectionID, securityContextID, userID, options);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -458,7 +459,7 @@ class ConnectorServer {
* @param {function} callback The callback to call when complete.
* @return {Promise} A promise that is resolved when complete.
*/
connectionList(connectionID, securityContextID, callback) {
connectionList (connectionID, securityContextID, callback) {
const method = 'connectionList';
LOG.entry(method, connectionID, securityContextID);
let connection = this.connections[connectionID];
Expand Down Expand Up @@ -489,6 +490,39 @@ class ConnectorServer {
});
}

/**
* Run npm view to get the details of a npm module
* @param {string} moduleName The name of the module
* @param {function} callback The callback to call when complete
* @return {Promise} A promise that is resolved when complete.
*/
getNpmInfo (moduleName, callback) {
const method = 'getNpmInfo';
LOG.entry(method, moduleName);

let child = exec('npm view ' + moduleName,
function (error, stdout, stderr) {
if (error !== null) {
LOG.error(error);
LOG.exit(method, null);
return callback(error);
} else {
try {
let output = stdout.replace(/\n/g, '');
let sortOfParsed = JSON.stringify(eval('(' + output + ')'));
let result = JSON.parse(sortOfParsed);
LOG.exit(method, result);
return callback(null, result);
} catch (error) {
LOG.error(error);
}
}
});

LOG.exit(method, null);
return child;
}

}

module.exports = ConnectorServer;
3 changes: 2 additions & 1 deletion packages/composer-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"express": "^4.14.0",
"is-docker": "^1.1.0",
"opener": "^1.4.2",
"socket.io": "^1.7.2"
"socket.io": "^1.7.2",
"octokat": "^0.6.2"
},
"devDependencies": {
"composer-admin": "^0.4.2",
Expand Down
6 changes: 2 additions & 4 deletions packages/composer-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { ConnectionProfileService } from './connectionprofile.service';
import { WalletService } from './wallet.service';
import { IdentityService } from './identity.service';
import { NotificationService } from './notification.service';
import { SampleService } from './sample.service';
import { InitializationService } from './initialization.service';
import { AddIdentityComponent } from './addidentity';
import { BusyComponent } from './busy';
import { ErrorComponent } from './error';
import { ResetComponent } from './reset';
import { SampleComponent } from './sample';
import { SampleBusinessNetworkService } from "./samplebusinessnetwork.service";

const LZString = require('lz-string');

Expand Down Expand Up @@ -70,9 +70,7 @@ export class AppComponent {
private walletService: WalletService,
private identityService: IdentityService,
private notificationService: NotificationService,
private sampleService: SampleService,
private initializationService: InitializationService
) {
private initializationService: InitializationService) {

}

Expand Down
6 changes: 3 additions & 3 deletions packages/composer-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import { ConnectionProfileService } from './connectionprofile.service';
import { WalletService } from './wallet.service';
import { IdentityService } from './identity.service';
import { NotificationService } from './notification.service';
import { SampleService } from './sample.service';
import { InitializationService } from './initialization.service';
import { SampleBusinessNetworkService } from "./samplebusinessnetwork.service";

// Application wide providers
const APP_PROVIDERS = [
Expand Down Expand Up @@ -105,8 +105,8 @@ type StoreType = {
WalletService,
IdentityService,
NotificationService,
SampleService,
InitializationService
InitializationService,
SampleBusinessNetworkService
]
})
export class AppModule {
Expand Down
1 change: 0 additions & 1 deletion packages/composer-ui/src/app/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';

import { AdminService } from '../admin.service';
import { ClientService } from '../client.service';
import { SampleService } from '../sample.service';
import { InitializationService } from '../initialization.service';

import { AclFile, BusinessNetworkDefinition, ModelFile } from 'composer-common';
Expand Down
27 changes: 15 additions & 12 deletions packages/composer-ui/src/app/initialization.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Injectable } from '@angular/core';
import {Injectable} from '@angular/core';

import { AdminService } from './admin.service';
import { ClientService } from './client.service';
import { SampleService } from './sample.service';
import {AdminService} from './admin.service';
import {ClientService} from './client.service';
import {SampleBusinessNetworkService} from './samplebusinessnetwork.service';

const fabricComposerOwner = 'fabric-composer';
const fabricComposerRepository = 'sample-networks';

@Injectable()
export class InitializationService {

private initializingPromise: Promise<any> = null;
private initialized = false;

constructor(
private adminService: AdminService,
private clientService: ClientService,
private sampleService: SampleService
) {
constructor(private adminService: AdminService,
private clientService: ClientService,
private sampleBusinessNetworkService: SampleBusinessNetworkService) {

}

Expand All @@ -30,8 +31,10 @@ export class InitializationService {
})
.then(() => {
if (this.adminService.isInitialDeploy()) {
let sampleName = this.sampleService.getDefaultSample();
return this.sampleService.deploySample(sampleName);
return this.sampleBusinessNetworkService.getSampleNetworkInfo(fabricComposerOwner, fabricComposerRepository, 'packages/CarAuction-Network/')
.then((info) => {
return this.sampleBusinessNetworkService.deploySample(fabricComposerOwner, fabricComposerRepository, info);
})
}
})
.then(() => {
Expand All @@ -46,7 +49,7 @@ export class InitializationService {
this.adminService.errorStatus$.next(error);
this.initialized = false;
this.initializingPromise = null;
})
});
return this.initializingPromise;
}

Expand Down
16 changes: 0 additions & 16 deletions packages/composer-ui/src/app/sample.service.spec.ts

This file was deleted.

Loading

0 comments on commit 07e0924

Please sign in to comment.