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

Commit

Permalink
Make web runtime use single db
Browse files Browse the repository at this point in the history
Updated web runtime so that only one db is used.
This fixes the problem of left over databases when local storage is
cleared after a version change

contributes to hyperledger/composer#3873

Signed-off-by: Caroline Church <caroline.church@uk.ibm.com>
  • Loading branch information
Caroline Church committed May 29, 2018
1 parent 485ea63 commit b237b9a
Show file tree
Hide file tree
Showing 35 changed files with 2,090 additions and 1,189 deletions.
12 changes: 12 additions & 0 deletions packages/composer-connector-embedded/lib/embeddedconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ class EmbeddedConnection extends Connection {
return null;
}

/**
* Undeploy a business network definition.
* @param {SecurityContext} securityContext The participant's security context.
* @param {String} networkName Name of the business network to remove
* @async
*/
async undeploy(securityContext, networkName) {
await this.dataService.removeAllData();
delete businessNetworks[networkName];
delete chaincodes[networkName];
}

/**
* Get the native API for this connection. The native API returned is specific
* to the underlying blockchain platform, and may throw an error if there is no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,15 @@ describe('EmbeddedConnection', () => {

});

describe('#undeploy', () => {
it('should remove prevoiusly installed business network', async () => {
await connection.install(mockSecurityContext, businessNetworkDefinition);
await connection.undeploy(mockSecurityContext, businessNetworkDefinition.getName());
await connection.install(mockSecurityContext, businessNetworkDefinition)
.should.not.be.rejected;
});
});

describe('#getNativeAPI', () => {

it('should throw as not supported', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-connector-web/lib/webconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class WebConnection extends Connection {
* @async
*/
async undeploy(securityContext, networkName) {
await WebDataService.newNetworkDataService(networkName, true).destroy();
await WebDataService.newNetworkDataService(networkName, true).removeAllData();
const chaincodeStore = await this.getChaincodeStore();
await chaincodeStore.removeNetwork(networkName);
this.savedNetwork = null;
Expand Down
4 changes: 2 additions & 2 deletions packages/composer-playground/.istanbul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ instrumentation:
check:
global:
statements: 99.76
branches: 98.65
functions: 98.83
branches: 98.66
functions: 98.82
lines: 99.8
7 changes: 3 additions & 4 deletions packages/composer-playground/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
/* tslint:disable:use-host-property-decorator*/
/* tslint:disable:no-input-rename*/
/* tslint:disable:member-ordering*/
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { BehaviorSubject, Subject } from 'rxjs/Rx';
import { Directive, Input, Injectable } from '@angular/core';
import { Directive, Injectable, Input } from '@angular/core';
import { AppComponent } from './app.component';
import { ClientService } from './services/client.service';
import { InitializationService } from './services/initialization.service';
import { IdentityCardService } from './services/identity-card.service';
import { LocalStorageService } from 'angular-2-local-storage';
import { AlertService } from './basic-modals/alert.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ActivatedRoute, Router, NavigationEnd, NavigationStart } from '@angular/router';
import { ActivatedRoute, NavigationEnd, NavigationStart, Router } from '@angular/router';
import { BusinessNetworkConnection } from 'composer-client';
import { AdminService } from './services/admin.service';
import { AboutService } from './services/about.service';
Expand Down Expand Up @@ -66,7 +66,6 @@ class RouterStub {
}

set eventParams(event) {
console.log('I AM A CHICKEN');
let nav;
if (event.nav === 'end') {
nav = new NavigationEnd(0, event.url, event.urlAfterRedirects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
/* tslint:disable:no-var-requires */
/* tslint:disable:max-classes-per-file */
/* tslint:disable:object-literal-key-quotes */
import { ComponentFixture, TestBed, fakeAsync, tick, async } from '@angular/core/testing';
import { EventEmitter } from '@angular/core';
import { FormsModule, Validators } from '@angular/forms';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { ConnectionProfileComponent } from './connection-profile.component';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ConnectionProfileService } from '../services/connectionprofile.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
/* tslint:disable:no-unused-expression */
/* tslint:disable:no-var-requires */
/* tslint:disable:max-classes-per-file */
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { Directive, Input, Component } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { Directive, Input } from '@angular/core';
import { FormsModule } from '@angular/forms';
import * as sinon from 'sinon';

Expand All @@ -28,7 +28,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { IssueIdentityComponent } from './issue-identity.component';
import { AlertService } from '../../basic-modals/alert.service';
import { ClientService } from '../../services/client.service';
import { BusinessNetworkConnection, ParticipantRegistry } from 'composer-client';
import { BusinessNetworkConnection } from 'composer-client';
import { Resource } from 'composer-common';

@Directive({
Expand Down Expand Up @@ -127,7 +127,6 @@ describe('IssueIdentityComponent', () => {
component['loadParticipants']();

let expected = ['Emperor', 'King', 'Macaroni'];
console.log('PARTICIPANT FQIs', component['participantFQIs']);
component['participantFQIs'].should.deep.equal(expected);
}));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
/* tslint:disable:use-host-property-decorator*/
/* tslint:disable:no-input-rename*/
/* tslint:disable:member-ordering*/
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { Input, Component, Output, EventEmitter } from '@angular/core';
import { Router, NavigationEnd, NavigationStart, ActivatedRoute } from '@angular/router';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ActivatedRoute, NavigationEnd, NavigationStart, Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

import { BehaviorSubject } from 'rxjs/Rx';
Expand All @@ -32,10 +32,9 @@ import { AlertService } from '../basic-modals/alert.service';
import { ConfigService } from '../services/config.service';
import { Config } from '../services/config/configStructure.service';
import { SampleBusinessNetworkService } from '../services/samplebusinessnetwork.service';
import { BusinessNetworkDefinition } from 'composer-common';
import { BusinessNetworkDefinition, IdCard } from 'composer-common';

import { DrawerService, DrawerDismissReasons } from '../common/drawer';
import { IdCard } from 'composer-common';
import { DrawerDismissReasons, DrawerService } from '../common/drawer';
import { LoginComponent } from './login.component';

import * as fileSaver from 'file-saver';
Expand Down Expand Up @@ -764,6 +763,10 @@ describe(`LoginComponent`, () => {
mockIdentityCardService.deleteIdentityCard.should.have.been.calledWith('myCardRef');
loadIdentityCardsStub.should.have.been.called;

mockAlertService.busyStatus$.next.should.have.been.calledWith({
title: 'Undeploying business network',
force: true
});
mockAlertService.successStatus$.next.should.have.been.called;
mockAlertService.errorStatus$.next.should.not.have.been.called;
}));
Expand Down
36 changes: 22 additions & 14 deletions packages/composer-playground/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { IdentityService } from '../services/identity.service';
import { ClientService } from '../services/client.service';
import { InitializationService } from '../services/initialization.service';
Expand All @@ -22,8 +22,8 @@ import { ConnectConfirmComponent } from '../basic-modals/connect-confirm/connect
import { IdentityCardService } from '../services/identity-card.service';
import { ConfigService } from '../services/config.service';
import { Config } from '../services/config/configStructure.service';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
import { DrawerService, DrawerDismissReasons } from '../common/drawer';
import { ModalDismissReasons, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { DrawerDismissReasons, DrawerService } from '../common/drawer';
import { ImportIdentityComponent } from './import-identity';

import { IdCard } from 'composer-common';
Expand Down Expand Up @@ -89,16 +89,19 @@ export class LoginComponent implements OnInit {

handleRouteChange() {
switch (this.route.snapshot.fragment) {
case 'deploy': this.deployNetwork(decodeURIComponent(this.route.snapshot.queryParams['ref']));
break;
case 'create-card': this.createIdCard();
break;
default: if (this.route.snapshot.fragment || Object.keys(this.route.snapshot.queryParams).length > 0) {
this.goLoginMain();
} else {
this.closeSubView();
}
break;
case 'deploy':
this.deployNetwork(decodeURIComponent(this.route.snapshot.queryParams['ref']));
break;
case 'create-card':
this.createIdCard();
break;
default:
if (this.route.snapshot.fragment || Object.keys(this.route.snapshot.queryParams).length > 0) {
this.goLoginMain();
} else {
this.closeSubView();
}
break;
}
}

Expand Down Expand Up @@ -351,8 +354,12 @@ export class LoginComponent implements OnInit {
let deletePromise: Promise<void>;
let cards = this.identityCardService.getAllCardsForBusinessNetwork(card.getBusinessNetworkName(), this.identityCardService.getQualifiedProfileName(card.getConnectionProfile()));
if (card.getConnectionProfile()['x-type'] === 'web' && cards.size === 1) {
deletePromise = this.adminService.connect(cardRef, card, true)
deletePromise = this.adminService.connect(cardRef, card, true)
.then(() => {
this.alertService.busyStatus$.next({
title: 'Undeploying business network',
force: true
});
return this.adminService.undeploy(card.getBusinessNetworkName());
});
} else {
Expand All @@ -363,6 +370,7 @@ export class LoginComponent implements OnInit {
.then(() => {
return this.identityCardService.deleteIdentityCard(cardRef)
.then(() => {
this.alertService.busyStatus$.next(null);
this.alertService.successStatus$.next({
title: 'ID Card Removed',
text: 'The ID card was successfully removed from My Wallet.',
Expand Down
26 changes: 14 additions & 12 deletions packages/composer-playground/src/app/services/admin.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
/* tslint:disable:no-unused-expression */
/* tslint:disable:no-var-requires */
/* tslint:disable:max-classes-per-file */
import { TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { fakeAsync, inject, TestBed, tick } from '@angular/core/testing';
import { AdminService } from './admin.service';
import { IdCard } from 'composer-common';
import { BusinessNetworkCardStore, BusinessNetworkDefinition, IdCard } from 'composer-common';

import * as sinon from 'sinon';
import * as chai from 'chai';

let should = chai.should();

import { AlertService } from '../basic-modals/alert.service';
import { BusinessNetworkDefinition, BusinessNetworkCardStore } from 'composer-common';
import { AdminConnection } from 'composer-admin';
import { BusinessNetworkCardStoreService } from './cardStores/businessnetworkcardstore.service';

let should = chai.should();

describe('AdminService', () => {

let sandbox;
Expand Down Expand Up @@ -94,9 +92,9 @@ describe('AdminService', () => {
beforeEach(() => {
mockIdCard = new IdCard({userName: 'banana', businessNetwork: 'myNetwork'}, {
'x-type': 'web',
'name': 'myProfile'
'name': '$default'
});
mockIdCard1 = new IdCard({userName: 'banana'}, {'x-type': 'web', 'name': 'myProfile'});
mockIdCard1 = new IdCard({userName: 'banana'}, {'x-type': 'hlfv1', 'name': 'myProfile'});
});

it('should return if connected', fakeAsync(inject([AdminService], (service: AdminService) => {
Expand Down Expand Up @@ -131,7 +129,8 @@ describe('AdminService', () => {

alertMock.busyStatus$.next.should.have.been.calledWith({
title: 'Connecting to Business Network myNetwork',
text: 'using connection profile myProfile'
text: 'using connection profile web',
force: true
});

mockGetAdminConnection.should.have.been.called;
Expand All @@ -153,7 +152,8 @@ describe('AdminService', () => {

alertMock.busyStatus$.next.should.have.been.calledWith({
title: 'Connecting without a business network',
text: 'using connection profile myProfile'
text: 'using connection profile myProfile',
force: true
});

mockGetAdminConnection.should.have.been.called;
Expand All @@ -177,7 +177,8 @@ describe('AdminService', () => {

alertMock.busyStatus$.next.should.have.been.calledWith({
title: 'Connecting to Business Network myNetwork',
text: 'using connection profile myProfile'
text: 'using connection profile web',
force: true
});

mockGetAdminConnection.should.have.been.called;
Expand Down Expand Up @@ -205,7 +206,8 @@ describe('AdminService', () => {

alertMock.busyStatus$.next.should.have.been.calledWith({
title: 'Connecting to Business Network myNetwork',
text: 'using connection profile myProfile'
text: 'using connection profile web',
force: true
});

mockGetAdminConnection.should.have.been.called;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { AlertService } from '../basic-modals/alert.service';
import { BusinessNetworkCardStoreService } from './cardStores/businessnetworkcardstore.service';

import { AdminConnection } from 'composer-admin';
import { ConnectionProfileManager, Logger, BusinessNetworkDefinition, IdCard } from 'composer-common';

import { BusinessNetworkDefinition, ConnectionProfileManager, IdCard } from 'composer-common';
import ProxyConnectionManager = require('composer-connector-proxy');
import WebConnectionManager = require('composer-connector-web');

Expand Down Expand Up @@ -61,9 +60,11 @@ export class AdminService {

console.log('Establishing admin connection ...');

const connectionProfileName = card.getConnectionProfile()['x-type'] === 'web' ? 'web' : card.getConnectionProfile().name;
this.alertService.busyStatus$.next({
title: card.getBusinessNetworkName() ? 'Connecting to Business Network ' + card.getBusinessNetworkName() : 'Connecting without a business network',
text: 'using connection profile ' + card.getConnectionProfile().name
text: 'using connection profile ' + connectionProfileName,
force: true
});

this.connectingPromise = this.getAdminConnection().connect(cardName)
Expand Down
Loading

0 comments on commit b237b9a

Please sign in to comment.