Class: AdminConnection

composer-admin. AdminConnection

This class creates an administration connection to a Fabric Composer runtime. The
connection can then be used to:


  • Deploy BusinessNetworkDefinitions

  • Undeploy BusinessNetworkDefinitions

  • Update BusinessNetworkDefinitions

  • Send a ping message to the runtime to ensure it is running and
    correctly configured.

  • Store a connection profile document in the connection profile store


new AdminConnection( [options])

Create an instance of the AdminConnection class.

Parameters:
Name Type Argument Description
options Object <optional>

an optional set of options to configure the instance.

Properties
Name Type Argument Description
fs Object <optional>

specify an fs implementation to use.

Source:

Methods


connect(connectionProfile, enrollmentID, enrollmentSecret, businessNetworkIdentifier)

Connects and logs in to the Hyperledger Fabric using a named connection
profile. The connection profile must exist in the profile store.

Parameters:
Name Type Description
connectionProfile string

The name of the connection profile

enrollmentID string

the enrollment ID of the user

enrollmentSecret string

the enrollment secret of the user

businessNetworkIdentifier string

the id of the network (for update) or null

Source:
Returns:

A promise that indicates the connection is complete

Type
Promise
Example
// Connect to Hyperledger Fabric
var adminConnection = new AdminConnection();
adminConnection.connect('testprofile', 'WebAppAdmin', 'DJY27pEnl16d')
.then(function(){
    // Connected.
})
.catch(function(error){
    // Add optional error handling here.
});

createProfile(connectionProfile, data)

Stores a connection profile into the profile store being used by this
AdminConnection.

Parameters:
Name Type Description
connectionProfile string

The name of the connection profile

data Object

The connection profile data

Source:
Returns:

A promise that indicates that the connection profile is deployed

Type
Promise
Example
// Create a connection profile
var adminConnection = new AdminConnection();
var adminOptions = {
    type: 'hlf',
    keyValStore: '/tmp/keyValStore',
    membershipServicesURL: 'grpc://membersrvc:7054',
    peerURL: 'grpc://vp0:7051',
    eventHubURL: 'grpc://vp0:7053'
};
return adminConnection.createProfile('testprofile', adminOptions)
.then(function(){
    // Created profile
})
.catch(function(error){
    // Add optional error handling here.
});

deleteProfile(connectionProfile)

Deletes the specified connection profile from the profile store being used by this
AdminConnection.

Parameters:
Name Type Description
connectionProfile string

The name of the connection profile

Source:
Returns:

A promise that indicates that the connection profile is deployed

Type
Promise
Example
// Delete a connection profile
var adminConnection = new AdminConnection();
return adminConnection.deleteProfile('testprofile')
.then(function(){
    // Deleted profile
})
.catch(function(error){
    // Add optional error handling here.
});

deploy(businessNetworkDefinition)

Deploys a new BusinessNetworkDefinition to the fabric. The connection must
be connected for this method to succeed.

Parameters:
Name Type Description
businessNetworkDefinition BusinessNetworkDefinition

The business network to deploy

Source:
Returns:

A promise that will be fufilled when the business network has been
deployed.

Type
Promise
Example
// Deploy a Business Network Definition
var adminConnection = new AdminConnection();
var businessNetworkDefinition = BusinessNetworkDefinition.fromArchive(myArchive);
return adminConnection.deploy(businessNetworkDefinition)
.then(function(){
    // Business network definition deployed
})
.catch(function(error){
    // Add optional error handling here.
});

disconnect()

Disconnects this connection.

Source:
Returns:

A promise that will be resolved when the connection is
terminated.

Type
Promise
Example
// Disconnect from a Business Network
var adminConnection = new AdminConnection();
return adminConnection.disconnect()
.then(function(){
    // Disconnected.
})
.catch(function(error){
    // Add optional error handling here.
});

getAllProfiles()

Retrieve all connection profiles from the profile store being used by this
AdminConnection.

Source:
Returns:

A promise that is resolved with the connection profile data.

Type
Promise
Example
// Retrieve all the connection profiles.
const adminConnection = new AdminConnection();
return adminConnection.getAllProfiles()
  .then((profiles) => {
    // Retrieved profiles
    for (let profile in profiles) {
      console.log(profile, profiles[profile]);
    }
  });

getProfile(connectionProfile)

Retrieve the specified connection profile from the profile store being
used by this AdminConnection.

Parameters:
Name Type Description
connectionProfile string

The name of the connection profile

Source:
Returns:

A promise that is resolved with the connection profile data.

Type
Promise
Example
// Retrieve the connection profile.
const adminConnection = new AdminConnection();
return adminConnection.getProfile('testprofile')
  .then((profile) => {
    // Retrieved profile
    console.log(profile);
  });

list()

List all of the deployed business networks. The connection must
be connected for this method to succeed.

Source:
Returns:

A promise that will be resolved with an array of
business network identifiers, or rejected with an error.

Type
Promise
Example
// List all of the deployed business networks.
var adminConnection = new AdminConnection();
return adminConnection.list()
.then((businessNetworks) => {
    // Connection has been tested
    return businessNetworks.forEach((businessNetwork) => {
      console.log('Deployed business network', businessNetwork);
    });
})
.catch(function(error){
    // Add optional error handling here.
});

ping()

Test the connection to the runtime and verify that the version of the
runtime is compatible with this level of the node.js module.

Source:
Returns:

A promise that will be fufilled when the connection has
been tested. The promise will be rejected if the version is incompatible.

Type
Promise
Example
// Test the connection to the runtime
var adminConnection = new AdminConnection();
return adminConnection.ping()
.then(function(){
    // Connection has been tested
})
.catch(function(error){
    // Add optional error handling here.
});

undeploy(businessNetworkIdentifier)

Undeploys a BusinessNetworkDefinition from the fabric. The business network will no
longer be able to process transactions.

Parameters:
Name Type Description
businessNetworkIdentifier string

The identifier of the network to undeploy

Source:
Returns:

A promise that will be fufilled when the business network has been
undeployed.

Type
Promise
Example
// Undeploy a Business Network Definition
var adminConnection = new AdminConnection();
return adminConnection.undeploy('identifier')
.then(function(){
    // Undeployed Business Network Definition
})
.catch(function(error){
    // Add optional error handling here.
})

update(businessNetworkDefinition)

Updates an existing BusinessNetworkDefinition on the fabric. The BusinessNetworkDefinition
must have been previously deployed.

Parameters:
Name Type Description
businessNetworkDefinition BusinessNetworkDefinition

The new BusinessNetworkDefinition

Source:
Returns:

A promise that will be fufilled when the business network has been
updated.

Type
Promise
Example
// Updates a Business Network Definition
var adminConnection = new AdminConnection();
var businessNetworkDefinition = BusinessNetworkDefinition.fromArchive(myArchive);
return adminConnection.update(businessNetworkDefinition)
.then(function(){
    // Business network definition updated
})
.catch(function(error){
    // Add optional error handling here.
});