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"] } )
or to deploy the full system (including the Logistics Wizard user interface) all at once, check out the Logistics Wizard Toolchain
-
If you do not already have a IBM Cloud account, sign up here
-
Download and install the Cloud Foundry CLI tool
-
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
-
cd
into this newly created directory -
Open the
manifest.yml
file and change thehost
value to something unique.
The host you choose will determinate the subdomain of your application's URL: <host>.mybluemix.net
-
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 ```
- Create a new Cloudant service
ibmcloud cf create-service cloudantNoSQLDB Lite logistics-wizard-erp-db
-
Push the app to IBM Cloud.
ibmcloud cf push
And voila! You now have your very own instance of simulator running on Bluemix.
- Get the code locally
git clone https://github.com/IBM-Cloud/logistics-wizard-erp.git
-
Change to the checkout directory
-
Get the application dependencies
npm install
- 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.
- Create the file server/datasources.local.json with the following content:
{
"db": {
"name": "db",
"connector": "memory",
"file": "in-memory-database.json"
}
}
- Start the application
npm start
The data is now persisted in in-memory-database.json.
- Create a new Cloudant service
cf create-service cloudantNoSQLDB Lite logistics-wizard-erp-db
- Create a set of credentials
cf create-service-key logistics-wizard-erp-db erp
- Retrieve the credentials
cf service-key logistics-wizard-erp-db erp
"url": "https://<username>:<password>@<host>/<database>"
-
Create a database named
logistics-wizard
in the Cloudant instance from the dashboard or withcurl -s -X PUT <url>/logistics-wizard
-
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
}
- 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.
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.
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. |
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