Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,468 changes: 78 additions & 1,390 deletions README.org

Large diffs are not rendered by default.

1,320 changes: 1,320 additions & 0 deletions arch/00_index.org

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions arch/01_getting_started.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#+TITLE: 1. Getting Started

Prev: [[file:00_index.org][0. Architecture Overview]] | Next: [[file:02_building_wasm.org][2. Building WebAssembly]]

*** Prerequisites

+ OpenJDK 17
+ [[https://github.com/babashka/babashka#installation][Babashka]]
+ [[https://clojure.org/guides/install_clojure][Clojure]]
+ Postgres (>=12)

*** Emacs/CIDER Setup

1. Pull down the repository (~git clone git@gitlab.com:sig-gis/behave-polylith~)
1. Pull down the submodules (~git submodule update --init --remote~)
1. Follow the Datomic Setup (see below)
1. Start the Datomic Transactor (see below)
1. Open ~development/user.cljs~ in Emacs
1. Start the CIDER nREPL ~cider-jack-in-clj&cljs~
1. Choose ~figwheel-main~ and ~dev~ for the front-end build.
1. Open ~http://localhost:8080~ in your browser.

*** Datomic Setup

**** Download & Setup Datomic Pro
#+BEGIN_SRC bash
mkdir -p ~/.datomic
cd ~/.datomic
curl -O https://datomic-pro-downloads.s3.amazonaws.com/1.0.7075/datomic-pro-1.0.7075.zip
unzip *.zip
ln -s $PWD/datomic-pro-1.0.7075 $PWD/current
echo 'export PATH="$HOME/.datomic/current/bin:$PATH"' >> ~/.bashrc # Or ~/.zshrc
#+END_SRC

**** Setting up PostgreSQL for Datomic

Be sure that PostgreSQL is running on port 5432.

#+BEGIN_SRC bash
cd /bases/datomic_store/sql/
psql -U postgres -f 01_setup.sql # Creates the Datomic DB, User
psql -U datomic datomic -f 02_tables.sql # Sets up the KV table
#+END_SRC

**** Running the Transactor
#+BEGIN_SRC bash
bb transactor
#+END_SRC

**** Running the Datomic Console
#+BEGIN_SRC bash
bb console --port <port>
#+END_SRC

Then visit [[http://localhost:8000/browse][localhost:8000/browse]]

**** Restoring CMS using a backup file

#+begin_src sh
bb restore --file <datomic-2024-##-##.dump>
#+end_src

*** Building the Behave UberJAR

1. Navigate to ~projects/behave~. All paths described here will use this directory as root.

2. Add/edit the ~resources/config.edn~ for your deployment. Below is
an example file:

#+BEGIN_SRC clojure
;; resources/config.edn
{:database {:config {:store {:backend :file
:path "~/.behave/db"}}}
:site {:title "BehavePlus 7"
:description "Wildfire Analysis toolkit."}
:server {:http-port 8007
:mode "prod"}
:vms {:secret-token "<vms-secret-token>"}}
#+END_SRC

3. Compile ClojureScript

#+BEGIN_SRC bash
bb build-js
#+END_SRC

4. Build the UberJAR

#+BEGIN_SRC bash
bb uber
#+END_SRC

5. Congratulations! You're now the owner of an UberJAR. (i.e. ~target/behave7-YYYY.MM.DD-####.jar~)
64 changes: 64 additions & 0 deletions arch/02_building_wasm.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#+TITLE: 3. Building WebAssembly

Prev: [[file:01_getting_started.org][1. Getting Started]] | Next: [[file:03_vms_guide.org][3. VMS Guide]]

** Behave-Lib

The "behave-lib" directory includes the build process for generating a WASM file using c++ code from
"behave-mirror" and "include" directories. Here's Checklist for when new c++ code needs to be
transcribed into wasm and be available via the Behave CMS.

*** Create new WASM file
**** Updating Hatchet's idl output and copying to behave.idl

- [ ] Run the pair of header files (i.e. surface.h and SIGSurface.h) through Hatchet (see Hatchet README).
- [ ] Replace/Edit text
- [ ] "std_string" with "[Const] DOMString"
- [ ] "string" with [Const] DOMString
- [ ] Any type ref to other classes with "[Ref] SIG<module>"
- [ ] Add [Const] to beginning of function in behave.idl for any functions in header file ending in const.
- [ ] Copy missing functions to the SIG<module> interface in "behave-lib/include/idl/behave.idl"
- [ ] Add new enums in "behave-lib/include/idl/behave.idl"
- [ ] For each enum in behave.idl there should be an enum entry in "src/cljs/behave/lib/enums.cljs"

**** Updating CLJS file in Behave with Hatchet's output.

- [ ] Add missing functions from hatchet's output cljs file to "behave/src/cljs/behave/lib/<model>.cljs"
- [ ] Add this to the end of the file

#+begin_src clojure
(def ^:export ns-public-fns (update-keys (ns-publics 'behave.lib.ignite) name))
#+end_src

**** Updating enums.cpp

- [ ] Add mapping for new enums in "behave-lib/include/cpp/emscripten/enums.cpp"

**** Updating behave_extern.js

- [ ] Update behave_extern.js with functions from cljs file

**** Create new WASM file

- [ ] In "behave-lib" run

#+begin_src sh
make install
#+end_src

**** Import EDN files from hatchet into CMS

- [ ] Both edn files have been created through hatchet (i.e. surface.edn and SIGSurface.edn)
- [ ] Run a modified version of the code block below for the module that needs updating

#+begin_src clojure
(ns cms-import)
;; Combine edn files from hatchet
(cms-import {:behave-file "path/to/hatchet/output/surface.edn"
:sig-adapter-file "path/to/hatchet/output/SIGSurface.edn"
:out-file-name "SIGSurface.edn"
:from-key :Surface
:to-key :SIGSurface})

(add-export-file-to-conn "./cms-exports/SIGSurface.edn" conn)
#+end_src
Loading