# OpenFlow
Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scalable NodeRed implementation.
Also the "backend" for [OpenRPA](https://github.com/open-rpa/OpenRPA)

Join rocket chat [#openrpa](https://rocket.openiap.io/)
or check out the [community forum](https://nn.openiap.io/)

Build to run on docker, how to setup docker is not supported on GitHub/slack

#### Quick start running openflow using npm on windows

[Install Chocolatey](https://chocolatey.org/install) 

open a command prompt as admin

Install rabbitmq ( answer yes to run the script )

```bash
choco install rabbitmq
```

Please ensure you can see rabbitmq as a service when you open the services.msc also make sure management got enabled ( a restart may help ). You can check this by going to [http://localhost:15672](http://localhost:15672)  ( if not, run `choco install rabbitmq --force` )

install mongodb ( answer yes to run the script )

```
choco install mongodb
```

Again make sure it got installed and is running when you open the services.msc ( if not, run `choco install mongodb --force` ) or install it manually by downloading [mongodb community](https://www.mongodb.com/try/download/community) edition

install nodejs LTS 14

```
choco install nodejs-lts
```

Make sure it works by running `node -v`  in a command prompt

install openflow command line

`npm i @openiap/openflow -g`

Go to the folder where you want to keep your config files,

```bash
mkdir c:\openflow
cd \openflow
```

install [pm2-windows-service](https://www.npmjs.com/package/pm2-windows-service)

```bash
npm i -g pm2-windows-service
pm2-service-install
```

then create a template configuration file using 
`openflow-cli --init`

open and edit openflow.env, if needed, then install the service using

`openflow-cli --install openflow`

then open a browser and visit [localhost.openiap.io](http://localhost.openiap.io) 

#### Quick start running openflow nodered using npm on windows

This require you to have openflow installed somewhere, or you can use our public openflow at [app.openiap.io](https://app.openiap.io) (noderedremote.env)

Create a user for the nodered in openflow, you will need the username and password for this user in the last step

[Install Chocolatey](https://chocolatey.org/install) 

open a command prompt as admin

install nodejs LTS 14

```
choco install nodejs-lts
```

install openflow-nodered command line
`npm i @openiap/nodered -g`

Go to the folder where you want to keep your config files,

```bash
mkdir c:\openflow
cd \openflow
```

install [pm2-windows-service](https://www.npmjs.com/package/pm2-windows-service)

```bash
npm i -g pm2-windows-service
pm2-service-install
```

then create a template configuration file using 
`openflow-nodered-cli --init`

this will create 2 environment files with an example of how to connect to a locally installed openflow or how to connect to [app.openiap.io](https://app.openiap.io)
So lets assume you want to run a remote openflow connected to [app.openiap.io](https://app.openiap.io) 

`openflow-nodered-cli --install noderedremote`

this will prompt you for a pre-created username and password, and then install a local service with the name noderedremote and start it

then open a browser and visit [localhost.openiap.io:1880](http://localhost.openiap.io:1880) 

#### Quick start running openflow using npm on linux

For now only tested on ubuntu 18LTS
Install NodeJS version 14 
Also you need to have an installation of  [mongoDB](https://www.mongodb.com/download-center/community) and [RabbitMQ](https://www.rabbitmq.com/download.html)
Importantent! You need to [enable management console](https://www.rabbitmq.com/management.html) in RabbitMQ 

Then to install and run OpenFlow, install the @openiap/openflow package 

`sudo npm i @openiap/openflow -g`

then create a template configuration file using 
`openflow-cli --init`

open and edit openflow.env, if needed, then install the service using

`sudo openflow-cli --install openflow`

then open a browser and visit [localhost.openiap.io](http://localhost.openiap.io) 

#### Quick start running openflow nodered using npm on linux

For now only tested on ubuntu 18LTS
Install NodeJS version 14
This require you to have openflow installed somewhere, or you can use our public openflow at [app.openiap.io](https://app.openiap.io) (noderedremote.env)

Create a user for the nodered in openflow, you will need the username and password for this user in the last step

Then install and run OpenFlow Nodered, install the @openiap/nodered package 
`sudo npm i @openiap/nodered -g`

then create a template configuration file using 
`openflow-nodered-cli --init`

this will create 2 environment files with an example of how to connect to a locally installed openflow or how to connect to [app.openiap.io](https://app.openiap.io)
So lets assume you want to run a remote openflow connected to [app.openiap.io](https://app.openiap.io) 

`sudo openflow-nodered-cli --install noderedremote`

this will prompt for the pre-created username and password, and then install a local service with the name noderedremote and start it

then open a browser and visit [localhost.openiap.io:1880](http://localhost.openiap.io:1880) 

#### Quick start using docker

To quickly get started with your own installation you can use one of these docker-compose files.
download the file you want
rename to docker-compose.yaml 
open a shell and cd to that folder you downloaded the file to, and type
docker-compose up
or
docker-compose up -d

[docker-compose-traefik.yml](https://github.com/open-rpa/openflow/blob/master/docker-compose-traefik.yml) is for people running docker ce/docker desktop or docker swarm

[docker-compose-toolbox.yml](https://github.com/open-rpa/openflow/blob/master/docker-compose-toolbox.yml) is for people running [docker toolbox](https://docs.docker.com/toolbox/toolbox_install_windows/) 

[docker-compose.yml](https://github.com/open-rpa/openflow/blob/master/docker-compose.yml) is for developers who don't want to install [mongoDB](https://www.mongodb.com/download-center/community)/[RabbitMQ](https://www.rabbitmq.com/download.html) or an easy way to run one instance while debugging the other.

Then you can access the API/web on [http://localhost.openiap.io](http://localhost.openiap.io) ( or [http://toolbox.openiap.io](http://toolbox.openiap.io) )
You can access nodered on [http://nodered1.localhost.openiap.io](http://nodered1.localhost.openiap.io) ( or [http://nodered1.toolbox.openiap.io](http://nodered1.toolbox.openiap.io) )
and RabbitMQ on  [http://mq.localhost.openiap.io](http://mq.localhost.openiap.io) ( or [http://mq.toolbox.openiap.io](http://mq.toolbox.openiap.io) )

The first username and password you try to login as, will be created and made admin

For help with running on [kubernetes](https://kubernetes.io/) or self hosting contact [OpenIAP](https://openiap.io/) for a support agreement

#### Quick start using helm to install on kubernetes

To quickly get started with your own installation on kubernetes, first install [traefik](https://doc.traefik.io/traefik/v1.7/user-guide/kubernetes/)

Each OpenFlow will have it's own namespace, and you create a value file for each instance/namespace
Create a file and call it demo1.yaml with this content

```yaml
# this will be the root domain name hence your openflow url will now be http://demo.mydomain.com 
domainsuffix: mydomain.com # this will be added to all domain names
domain: demo 
# if traefic is for https using websecure, the you can uncomment the below 2 lines
# you need to tell the name of the secret containing the certificate, I can recomend using kubed for replicating this
# protocol: https
# tlsSecret: wild.mydomain.com
openflow:
#  external_mongodb_url: mongodb+srv://user:pass@cluster0.gcp.mongodb.net?retryWrites=true&w=majority
rabbitmq:
  default_user: admin
  default_pass: supersecret
# if you are using mpongodb atlas, or has mongodb running somewhere else
# uncomment below line, and external_mongodb_url in openflow above
# mongodb:
#   enabled: false
```

First add the helm repo and  create a new namespace called demo1

``` sh
helm repo add openiap https://raw.githubusercontent.com/open-rpa/helm-repo/master/
helm repo update
kubectl create namespace demo1
```

The create the install using 

```sh
helm install openflow openiap/openflow -n demo1 --values ./demo1.yaml
```

If you late update your values file you can update your install using 

```sh
helm upgrade openflow openiap/openflow -n demo1 --values ./demo1.yaml
```

Read more about this at the [githu repo](https://github.com/open-rpa/helm-repo)

#### Developer setup

Install [VSCode](https://code.visualstudio.com/download), [NodeJS 12](https://nodejs.org/en/download/),  [mongoDB](https://www.mongodb.com/download-center/community) and [RabbitMQ](https://www.rabbitmq.com/download.html) 
You need to [enable management console](https://www.rabbitmq.com/management.html) in RabbitMQ 

Clone this repo into a folder, in a shell type

`git clone https://github.com/open-rpa/openflow.git`

go to the folder with openflow

`cd openflow`

Install gulp and typescript globally

`npm i gulp typescript browserify tsify -g`

install packages for openflow api/web

`npm i`

install packages for NodeRED by 

`cd OpenFlowNodeRED`
`npm i`

`cd ..`

Now open in VS code

`code OpenFlow.code-workspace`

at the top level create a folder called config and inside create a file called .env ( notice it starting with a dot)

and add this content to the file

```bash
nodered_id=nodered1
nodered_sa=nodered1
port=80
nodered_port=1880
nodered_domain_schema=$nodered_id$.localhost.openiap.io
tls_crt=
tls_key=
tls_ca=

 
 
NODE_ENV=development

saml_federation_metadata=http://localhost.openiap.io/issue/FederationMetadata/2007-06/FederationMetadata.xml
saml_issuer=uri:localhost.openiap.io
# saml_entrypoint=http://localhost.openiap.io/issue
# saml_baseurl=http://localhost.openiap.io:1880/

allow_personal_nodered=false
allow_user_registration=true
# mongodb_url=mongodb://localhost:27017
# mongodb_db=openflow

# api_bypass_perm_check=true
update_acl_based_on_groups=true
multi_tenant=false

websocket_max_package_count=1048576

api_ws_url=ws://localhost.openiap.io
domain=localhost.openiap.io
protocol=http
amqp_url=amqp://localhost
aes_secret=7TXsxf7cn9EkUqm5h4MEWGjzkxkNCk2K
auto_create_users=true
auto_create_domains=
skip_history_collections=audit,jslog
```
Lastly you need to allow powershell scripts to run, i don't know what is the recommended setting, i normally just go with bypass

`Set-ExecutionPolicy Bypass -Force`

Now you can run this by going to run ( Ctrl+Shit+D) and selecting OpenFlow in the dropdown box and press play button, select OpenFlowNodeRed in the dropdown and press play again

Lastly we need to start a background job that copies asserts to the dist folder, go to Terminal tab and add a new shelll, then type

`gulp`

You can now access openflow web on [http://localhost.openiap.io](http://localhost.openiap.io) and nodered on [http://localhost.openiap.io:1880](http://localhost.openiap.io:1880)

For further help or education contact [OpenIAP](https://openiap.io/) for a support agreement