Skip to content

Latest commit

 

History

History
232 lines (163 loc) · 7.23 KB

README-BASIC.md

File metadata and controls

232 lines (163 loc) · 7.23 KB

Basic configuration with the Logistics Wizard ERP simulator

In the basic configuration, the simulator runs as a Cloud Foundry app in IBM Cloud.

![Architecture](http://g.gravizo.com/g? digraph G { node [fontname = "helvetica"] rankdir=BT simulator -> database [label="CRUD operations"] others -> simulator [label=" Call ERP service"] {rank=same; simulator -> database [style=invis] } /* services on top / {rank=source; others } / styling */ simulator [shape=rect label="ERP service"] database [shape=circle width=1 fixedsize=true style=filled color="%234E96DB" fontcolor=white label="Database"] others [shape=rect style=filled color="%2324B643" fontcolor=white label="Other Services"] } )

Deploying the simulator automatically

Deploy to IBM Cloud

or to deploy the full system (including the Logistics Wizard user interface) all at once, check out the Logistics Wizard Toolchain

Running the simulator on IBM Cloud

  1. If you do not already have a IBM Cloud account, sign up here

  2. Download and install the Cloud Foundry CLI tool

  3. Clone the app and its submodules to your local environment from your terminal using the following command:

    git clone https://github.com/IBM-Cloud/logistics-wizard-erp.git
    
  4. cd into this newly created directory

  5. Open the manifest.yml file and change the host value to something unique.

The host you choose will determinate the subdomain of your application's URL: <host>.mybluemix.net

  1. Connect to IBM Cloud in the command line tool and follow the prompts to log in.

    ibmcloud api https://api.ng.bluemix.net
    

ibmcloud login ```

  1. Create a new Cloudant service
ibmcloud cf create-service cloudantNoSQLDB Lite logistics-wizard-erp-db
  1. Push the app to IBM Cloud.

    ibmcloud cf push
    

And voila! You now have your very own instance of simulator running on Bluemix.

Running the simulator locally

  1. Get the code locally
git clone https://github.com/IBM-Cloud/logistics-wizard-erp.git
  1. Change to the checkout directory

  2. Get the application dependencies

npm install
  1. Start the application
npm start

At that point the application runs with an in-memory database. You lose all changes when you stop the app. Let's configure a persistent storage.

Using a persistent in-memory database

  1. Create the file server/datasources.local.json with the following content:
{
  "db": {
    "name": "db",
    "connector": "memory",
    "file": "in-memory-database.json"
  }
}
  1. Start the application
npm start

The data is now persisted in in-memory-database.json.

Using Cloudant

  1. Create a new Cloudant service
cf create-service cloudantNoSQLDB Lite logistics-wizard-erp-db
  1. Create a set of credentials
cf create-service-key logistics-wizard-erp-db erp
  1. Retrieve the credentials
cf service-key logistics-wizard-erp-db erp
"url": "https://<username>:<password>@<host>/<database>"
  1. Create a database named logistics-wizard in the Cloudant instance from the dashboard or with

    curl -s -X PUT <url>/logistics-wizard
    
  2. Create the file server/datasources.local.json with the following content, replacing the placeholders with values extracted from the uri.

"db": {
  "name": "db",
  "connector": "cloudant",
  "url": "https://username:password@host",
  "database": "logistics-wizard",
  "plugin": "retry",
  "retryAttempts": 20,
  "retryTimeout": 1000
}
  1. Start the application
npm start

The data is now persisted in Cloudant. You can use the same structure for the databases.local.json if you work with your own Cloudant database.

Building an API with Loopback and Swagger

The ERP simulator uses Loopback for its implementation. LoopBack is a highly-extensible, open-source Node.js framework that enables you to:

  • Create dynamic end-to-end REST APIs with little or no coding.
  • Access data from major relational databases, MongoDB, SOAP and REST APIs.
  • Incorporate model relationships and access controls for complex APIs.
  • Use geolocation, file, and push services for mobile apps.
  • Easily create client apps using Android, iOS, and JavaScript SDKs.
  • Run your application on-premises or in the cloud.

From the Loopback model definition, we derived a Swagger specification, initially generated with slc loopback:export-api-def -o spec.yaml.

Swagger is a simple yet powerful representation of a RESTful API. The Swagger specification has been donated to the Open API Initiative as part of an effort to define a standard specification format for REST APIs.

To review the API specification, open the Swagger Editor.

Code Structure

To better understand some of the code below including Loopback tips, the blog post titled Build a smarter supply chain with LoopBack is worth a read.

File Description
Loopback models Contains JSON definitions of the object model and implementation of remote methods.
integrity.js A mixin to check foreign key constraints.
isolated.js A mixin to isolate data per demo environment.
seed/ Seed data loaded into the database at startup and when new demo environments are created.
server/boot/ Startup scripts including table creation, static data injection.
datasources.local.js Initializes data sources (database) from a local file or by reading the Cloud Foundry VCAP_SERVICES.
datasources.local.template.json Template file to define local data sources.
test/ Unit tests.

Testing

The unit tests use Mocha as test runner.

To run the unit tests (all .js under test), run

npm run test

The unit tests use a dedicated datasource definition file.

To run the tests and collect coverage data with istanbul, run

npm run localcoverage

and view the coverage report in coverage/index.html.

To run tests and post coverage results to coveralls, either through a continuous integration tool like Travis or through your own tool (by adding a .coveralls.yml file with a repo_token property as described here), run

npm run coverage