Skip to content

Commit

Permalink
Add Basic Frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed Jun 20, 2023
1 parent dce96bf commit 7afc2d4
Show file tree
Hide file tree
Showing 173 changed files with 27,691 additions and 77 deletions.
36 changes: 36 additions & 0 deletions .github/scripts/check-frontend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash -e

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
. "$SCRIPT_DIR/util.sh"

BASE="http://localhost:8080/fhir"

echo "checking index.html using the Accept header..."
HEADERS=$(curl -s -H 'Accept: text/html' -o /dev/null -D - "$BASE")
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2)

test "Content-Type header" "$CONTENT_TYPE_HEADER" "text/html"

echo "checking index.html using the _format query param..."
HEADERS=$(curl -s -o /dev/null -D - "$BASE?_format=html")
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2)

test "Content-Type header" "$CONTENT_TYPE_HEADER" "text/html"

echo "checking version.json..."
HEADERS=$(curl -s -H 'Accept: text/html' -o /dev/null -D - "$BASE/__frontend/version.json")
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2)

test "Content-Type header" "$CONTENT_TYPE_HEADER" "application/json"

echo "checking system-search using the Accept header..."
HEADERS=$(curl -s -H 'Accept: application/fhir+json' -o /dev/null -D - "$BASE")
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2)

test "Content-Type header" "$CONTENT_TYPE_HEADER" "application/fhir+json;charset=utf-8"

echo "checking system-search using the _format query param..."
HEADERS=$(curl -s -o /dev/null -D - "$BASE?_format=json")
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2)

test "Content-Type header" "$CONTENT_TYPE_HEADER" "application/fhir+json;charset=utf-8"
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,32 @@ jobs:
- name: Download Both Resources
run: test "2" = "$(curl -s http://localhost:8080/fhir/Binary | jq .total)"

frontend-test:
needs: build
runs-on: ubuntu-22.04

steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Download Blaze Image
uses: actions/download-artifact@v3
with:
name: blaze-image
path: /tmp

- name: Load Blaze Image
run: docker load --input /tmp/blaze.tar

- name: Run Blaze
run: docker run --name blaze -d -e JAVA_TOOL_OPTIONS=-Xmx2g -e ENABLE_FRONTEND=true -p 8080:8080 -v blaze-data:/app/data blaze:latest

- name: Wait for Blaze
run: .github/scripts/wait-for-url.sh http://localhost:8080/health

- name: Check Frontend
run: .github/scripts/check-frontend.sh

missing-resource-content-test:
needs: build
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -1592,6 +1618,7 @@ jobs:
- openid-auth-test
- doc-copy-data-test
- big-binary-test
- frontend-test
- missing-resource-content-test
- distributed-test
- jepsen-distributed-test
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ clean-root:

clean: $(MODULES) clean-root

uberjar: prep
build-frontend:
$(MAKE) -C modules/frontend build

uberjar: prep build-frontend
clojure -T:build uber

outdated:
Expand All @@ -35,4 +38,4 @@ deps-tree:
deps-list:
clojure -X:deps list

.PHONY: $(MODULES) lint-root lint prep test-root test test-coverage clean-root clean uberjar outdated deps-tree deps-list
.PHONY: $(MODULES) lint-root lint prep test-root test test-coverage clean-root clean build-frontend uberjar outdated deps-tree deps-list
8 changes: 7 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{:paths ["src" "resources"]

:deps
{blaze/db-resource-store-cassandra
{blaze/admin-api
{:local/root "modules/admin-api"}

blaze/db-resource-store-cassandra
{:local/root "modules/db-resource-store-cassandra"}

blaze/db-tx-log-kafka
{:local/root "modules/db-tx-log-kafka"}

blaze/frontend
{:local/root "modules/frontend"}

blaze/interaction
{:local/root "modules/interaction"}

Expand Down
3 changes: 3 additions & 0 deletions dev/blaze/dev/rocksdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@
:db (.getDbName status)
:cf (.getCfName status)})
(.getThreadList (Env/getDefault)))

(rocksdb/table-properties (index-kv-store) :resource-as-of-index)

)
29 changes: 29 additions & 0 deletions modules/admin-api/.clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{:lint-as
{blaze.admin-api-test/with-handler clojure.core/fn}

:linters
{:unsorted-required-namespaces
{:level :error}

:single-key-in
{:level :warning}

:keyword-binding
{:level :error}

:reduce-without-init
{:level :warning}

:warn-on-reflection
{:level :warning :warn-only-on-interop true}

:consistent-alias
{:aliases
{blaze.async.comp ac
blaze.db.kv.rocksdb rocksdb
clojure.spec.alpha s
integrant.core ig
ring.util.response ring
taoensso.timbre log}}}

:skip-comments true}
16 changes: 16 additions & 0 deletions modules/admin-api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
lint:
clj-kondo --lint src test deps.edn

prep:
clojure -X:deps prep

test: prep
clojure -M:test:kaocha --profile :ci

test-coverage: prep
clojure -M:test:coverage

clean:
rm -rf .clj-kondo/.cache .cpcache target

.PHONY: lint prep test test-coverage clean
37 changes: 37 additions & 0 deletions modules/admin-api/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{:deps
{blaze/async
{:local/root "../async"}

blaze/module-base
{:local/root "../module-base"}

blaze/rest-util
{:local/root "../rest-util"}

blaze/rocksdb
{:local/root "../rocksdb"}

blaze/spec
{:local/root "../spec"}}

:aliases
{:test
{:extra-paths ["test"]

:extra-deps
{blaze/test-util
{:local/root "../test-util"}}}

:kaocha
{:extra-deps
{lambdaisland/kaocha
{:mvn/version "1.71.1119"}}

:main-opts ["-m" "kaocha.runner"]}

:coverage
{:extra-deps
{cloverage/cloverage
{:mvn/version "1.2.4"}}

:main-opts ["-m" "cloverage.coverage" "--codecov" "-p" "src" "-s" "test"]}}}
56 changes: 56 additions & 0 deletions modules/admin-api/src/blaze/admin_api.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(ns blaze.admin-api
(:require
[blaze.async.comp :as ac]
[blaze.db.kv.rocksdb :as rocksdb]
[blaze.spec]
[clojure.spec.alpha :as s]
[integrant.core :as ig]
[reitit.ring]
[reitit.ring.spec]
[ring.util.response :as ring]
[taoensso.timbre :as log]))


(defn- rocksdb-column-families-handler [index-kv-store]
(fn [_]
(-> (ring/response
{:column-families (mapv name (rocksdb/column-families index-kv-store))})
(ac/completed-future))))


(defn- rocksdb-table-handler [index-kv-store]
(fn [{{:keys [column-family]} :path-params}]
(-> (ring/response {:tables (rocksdb/table-properties index-kv-store (keyword column-family))})
(ac/completed-future))))


(defn- router [{:keys [context-path index-kv-store] :or {context-path ""}}]
(reitit.ring/router
["/rocksdb"
{}
["/index"
{}
["/column-families"
{}
[""
{:get (rocksdb-column-families-handler index-kv-store)}]
["/{column-family}"
{}
["/tables"
{:get (rocksdb-table-handler index-kv-store)}]]]]]
{:path (str context-path "/__admin")
:syntax :bracket}))


(defmethod ig/pre-init-spec :blaze/admin-api [_]
(s/keys :req-un [:blaze/context-path :blaze.db/index-kv-store]))


(defmethod ig/init-key :blaze/admin-api
[_ context]
(log/info "Init Admin endpoint")
(reitit.ring/ring-handler
(router context)
(fn [{:keys [uri]}]
(-> (ring/not-found {:uri uri})
(ac/completed-future)))))
95 changes: 95 additions & 0 deletions modules/admin-api/test/blaze/admin_api_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
(ns blaze.admin-api-test
(:require
[blaze.admin-api]
[blaze.db.kv.rocksdb.protocols :as p]
[blaze.test-util :as tu :refer [given-thrown with-system]]
[clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]
[clojure.test :as test :refer [deftest testing]]
[integrant.core :as ig]
[juxt.iota :refer [given]]
[taoensso.timbre :as log]))


(st/instrument)
(log/set-level! :trace)


(test/use-fixtures :each tu/fixture)


(deftest init-test
(testing "nil config"
(given-thrown (ig/init {:blaze/admin-api nil})
:key := :blaze/admin-api
:reason := ::ig/build-failed-spec
[:explain ::s/problems 0 :pred] := `map?))

(testing "missing config"
(given-thrown (ig/init {:blaze/admin-api {}})
:key := :blaze/admin-api
:reason := ::ig/build-failed-spec
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :context-path))
[:explain ::s/problems 1 :pred] := `(fn ~'[%] (contains? ~'% :index-kv-store))))

(testing "invalid index-kv-store"
(given-thrown (ig/init {:blaze/admin-api {:index-kv-store ::invalid}})
:key := :blaze/admin-api
:reason := ::ig/build-failed-spec
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :context-path)))))


(defmethod ig/init-key ::rocksdb
[_ {:keys [column-families]}]
(reify p/Rocks
(-column-families [_]
(keys column-families))

(-table-properties [_ column-family]
(when (column-families column-family)
[{:name (str (name column-family) "/table-1")
:data-size 193338}]))))


(def config
{:blaze/admin-api
{:context-path "/fhir"
:index-kv-store (ig/ref :blaze.db/index-kv-store)}

[::rocksdb :blaze.db/index-kv-store]
{:column-families
{:column-family-1 {}
:column-family-2 {}}}})


(defmacro with-handler [[handler-binding] & body]
`(with-system [{handler# :blaze/admin-api} config]
(let [~handler-binding handler#]
~@body)))


(deftest rocksdb-column-families-test
(with-handler [handler]
(testing "success"
(given @(handler
{:request-method :get
:uri "/fhir/__admin/rocksdb/index/column-families"})
:status := 200
[:body :column-families] := ["column-family-1" "column-family-2"]))))


(deftest rocksdb-tables-test
(with-handler [handler]
(testing "not found"
(given @(handler
{:request-method :get
:uri "/fhir/__admin/foo"})
:status := 404))

(testing "success"
(given @(handler
{:request-method :get
:uri "/fhir/__admin/rocksdb/index/column-families/column-family-1/tables"})
:status := 200
[:body :tables 0 :name] := "column-family-1/table-1"
[:body :tables 0 :data-size] := 193338))))
5 changes: 5 additions & 0 deletions modules/admin-api/tests.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#kaocha/v1
#merge
[{}
#profile {:ci {:reporter kaocha.report/documentation
:color? false}}]
4 changes: 4 additions & 0 deletions modules/fhir-structure/test/blaze/fhir/spec_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns blaze.fhir.spec-test
(:require
[blaze.anomaly :as ba]
[blaze.fhir.spec :as fhir-spec]
[blaze.fhir.spec-spec]
[blaze.fhir.spec.generators :as fg]
Expand Down Expand Up @@ -199,6 +200,9 @@
[:fhir/issues 0 :fhir.issues/diagnostics] := "Error on value `{}`. Expected type is `Resource`."
[:fhir/issues 0 :fhir.issues/expression] := "entry[0].resource"))

(testing "missing resourceType"
(is (ba/anomaly? (fhir-spec/conform-json {}))))

(testing "empty patient resource"
(testing "gets type annotated"
(is (= :fhir/Patient
Expand Down
Loading

0 comments on commit 7afc2d4

Please sign in to comment.