{"id":15344050,"url":"https://github.com/tarilabs/demo20220715contextlabel","last_synced_at":"2025-04-05T22:26:23.552Z","repository":{"id":49384487,"uuid":"514316228","full_name":"tarilabs/demo20220715contextlabel","owner":"tarilabs","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-29T09:23:06.000Z","size":655,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-12T04:15:58.927Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tarilabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-15T15:22:15.000Z","updated_at":"2023-01-31T02:56:42.000Z","dependencies_parsed_at":"2022-08-25T13:31:52.174Z","dependency_job_id":null,"html_url":"https://github.com/tarilabs/demo20220715contextlabel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarilabs%2Fdemo20220715contextlabel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarilabs%2Fdemo20220715contextlabel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarilabs%2Fdemo20220715contextlabel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarilabs%2Fdemo20220715contextlabel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarilabs","download_url":"https://codeload.github.com/tarilabs/demo20220715contextlabel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247409665,"owners_count":20934462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T10:53:41.648Z","updated_at":"2025-04-05T22:26:23.520Z","avatar_url":"https://github.com/tarilabs.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# demo20220715contextlabel Project\n\nTechnologies used in this demo: [Drools](https://www.drools.org/learn/video.html), [YaRD](https://github.com/kiegroup/yard/), [Kogito](https://kogito.kie.org/), [Quarkus](https://quarkus.io/), [cloudevents](https://cloudevents.io/), Apache Kafka, PostgreSQL, [hibernate-types](https://github.com/vladmihalcea/hibernate-types#readme), [quarkus-quinoa](https://quarkiverse.github.io/quarkiverse-docs/quarkus-quinoa/dev/), [PatternFly](https://www.patternfly.org/v4/).\n\nGoals:\n - Demo a Classification of cloudevent generic context based on YaRD rule definition with ad-hoc indexed searching of association of _hierarchical_ labels via PostgreSQL's `ltree` for any given context\n\nNon goals:\n - Full complete architectural solution; for example, wired Kafka as demonstrator \n - Fully implemented GUI (focusing on backend, and for the frontend [chabuduo](https://youtube.com/clip/UgkxeVe0fr81gBBZXzQ1LG2189Z1QrYspmXt) MVP working-PoC 🚀)\n\n## Requirements\n\n- openjdk 17\n- Apache Maven 3.8.6\n- Docker (for PostgreSQL and Kafka, Quarkus Dev Services)\n- NodeJS v18.6.0\n- place [draft GUI](https://github.com/tarilabs/demo20220715contextlabel-ui) as a sibling directory for Quarkus' Quinoa `quarkus:dev`\n\n## Overview\n\nA cloudevent is submitted to this application, for example:\n\n```json\n{\n  \"specversion\": \"1.0\",\n  \"id\": \"matteo-8eb9-43b2-9313-22133f2c747a\",\n  \"source\": \"example\",\n  \"type\": \"demo20220715contextlabel.demotype\",\n  \"data\": {\n    \"host\": \"basedidati.milano.local\",\n    \"diskPerc\": 70,\n    \"memPerc\": 50,\n    \"cpuPerc\": 20\n  }\n}\n```\n\nFor once a demo not involving Loan or Insurances ;) The data context of the cloud event pertains to some host which came under supervision due to resource load.\nWe now want to classify this context/case, using some labels.\nWe may have more than 1 label.\nEach label is hierarchical (`root.branch1.branch2.leaf`).\n\nUltimately, we might want to setup a labeling rule for who's on call, something ~like a Kie Drools YaRD rule definition of a decision table:\n\n```yaml\n    type: DecisionTable\n    inputs: ['.location', '.type']\n    rules:\n    - when: ['startswith(\"location.emea\")', '. == \"type.db\"']\n      then: '\"oncall.EMEA.dbadm\"'\n    - when: ['startswith(\"location.emea\") | not', '. == \"type.db\"']\n      then: '\"oncall.CORP.dbadm\"'\n    - when: ['true', '. == \"type.nas\"']\n      then: '\"oncall.CORP.it\"'\n```\n\nFor example, a cloudevent context may be labeled as follows:\n - `type.db`\n - `location.emea.italy.milan`\n - `oncall.EMEA.dbadm`\n\nFor the PostgreSQL DDL we currently have:\n```\n                       Table \"public.cecase\"\n Column  |          Type          | Collation | Nullable | Default \n---------+------------------------+-----------+----------+---------\n id      | bigint                 |           | not null | \n ceuuid  | character varying(255) |           |          | \n context | jsonb                  |           |          | \n mytag   | ltree[]                |           |          | \nIndexes:\n    \"cecase_pkey\" PRIMARY KEY, btree (id)\n    \"mytag_gist_idx\" gist (mytag)\n    \"mytag_idx\" btree (mytag)\n```\n\nPlease notice taking advantage of PostgreSQL's `jsonb` for storing the original cloudevent context, and `ltree[]` for searching ad-hoc indexed the hiearachical labels.\n\nThis is extremely helpful to setup queries making use of `\u003c@` and `~` operator for PostgreSQL which performs on `ltree`, showcased below.\n\nAs the data flows to the application, we can use this provisional GUI which uses the backend REST API(s) made on Quarkus:\n\n![](screenshot.listall.png)\n\nIn the screenshot above, you can access all the records from the table, where the labels have been applied by the rule definition.\n\nWe can browse by, having at least one label having the specified parent with a query like\n```sql\nSELECT * FROM cecase WHERE mytag \u003c@ 'oncall.CORP'\n```\n\nfor example if we want all the records having at least a label for the `oncall.CORP` rooting:\n\n![](screenshot.searchparent.png)\n\nWe can browse by, having at least one label having the specified `ltree` query like\n```sql\nSELECT * FROM cecase WHERE mytag ~ `*.emea.*`\n```\n\nfor example if we want all the records having at least a label for the `*.emea.*` (a branch named `emea` in any point in the hieararchical label):\n\n![](screenshot.searchmatching.png)\n\n## dev notes\n\n```\ndocker ps\ndocker exec -it \u003cid\u003e sh\npsql -U hibernate default\n\\d\n```\n\n```\ndefault=# SELECT * FROM cecase WHERE mytag ~ '*.eu.*';\n id | ceuuid |          context           |               mytag               \n----+--------+----------------------------+-----------------------------------\n  1 | test1  | {\"host\": \"milan.archivio\"} | {location.eu.italy.milan,type.db}\n(1 row)\n\ndefault=# SELECT * FROM cecase WHERE mytag \u003c@ 'location.eu';\n id | ceuuid |          context           |               mytag               \n----+--------+----------------------------+-----------------------------------\n  1 | test1  | {\"host\": \"milan.archivio\"} | {location.eu.italy.milan,type.db}\n(1 row)\n```\n\n\u003c!--\n\nThis project uses Quarkus, the Supersonic Subatomic Java Framework.\n\nIf you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .\n\n## Running the application in dev mode\n\nYou can run your application in dev mode that enables live coding using:\n```shell script\n./mvnw compile quarkus:dev\n```\n\n\u003e **_NOTE:_**  Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.\n\n## Packaging and running the application\n\nThe application can be packaged using:\n```shell script\n./mvnw package\n```\nIt produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory.\nBe aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory.\n\nThe application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`.\n\nIf you want to build an _über-jar_, execute the following command:\n```shell script\n./mvnw package -Dquarkus.package.type=uber-jar\n```\n\nThe application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`.\n\n## Creating a native executable\n\nYou can create a native executable using: \n```shell script\n./mvnw package -Pnative\n```\n\nOr, if you don't have GraalVM installed, you can run the native executable build in a container using: \n```shell script\n./mvnw package -Pnative -Dquarkus.native.container-build=true\n```\n\nYou can then execute your native executable with: `./target/demo20220715contextlabel-1.0.0-SNAPSHOT-runner`\n\nIf you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.\n\n## Related Guides\n\n- SmallRye OpenAPI ([guide](https://quarkus.io/guides/openapi-swaggerui)): Document your REST APIs with OpenAPI - comes with Swagger UI\n- Hibernate ORM with Panache ([guide](https://quarkus.io/guides/hibernate-orm-panache)): Simplify your persistence code for Hibernate ORM via the active record or the repository pattern\n\n## Provided Code\n\n### RESTEasy JAX-RS\n\nEasily start your RESTful Web Services\n\n[Related guide section...](https://quarkus.io/guides/getting-started#the-jax-rs-resources)\n\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarilabs%2Fdemo20220715contextlabel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarilabs%2Fdemo20220715contextlabel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarilabs%2Fdemo20220715contextlabel/lists"}