From bc5d8584cd37be5cd1adbda26bbb51e6757feac0 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Fri, 8 Mar 2024 16:51:41 +0100 Subject: [PATCH 01/13] v2.0 --- basis/starter.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/basis/starter.sh b/basis/starter.sh index 6f2a13c..1d912f7 100755 --- a/basis/starter.sh +++ b/basis/starter.sh @@ -38,7 +38,7 @@ if [ -z $ARG1 ] || [ "$ARG1" == "help" ]; then echo "./starter.sh deploy oke - Deploy APP and UI on OKE (OKE mode)" echo echo "--- KUBECTL -----------------------------------------------------------------------" - echo ". ./env.sh - Set kubeconfig to connect to Kubernetes" + echo "./starter.sh env - Set kubeconfig to connect to Kubernetes" echo "kubectl get pods - Example of a command to check the PODs" exit fi @@ -85,6 +85,9 @@ elif [ "$ARG1" == "deploy" ]; then echo "Unknow command: $ARG1 $ARG2" exit 1 fi +elif [ "$ARG1" == "env" ]; then + export PS1="[\u@\h \W]\e[103m\$\e(B\e[m " + bash --rcfile ./env.sh else echo "Unknow command: $ARG1" exit 1 From 779f842c6bbc2e5af83aee6cea59587eeed52a61 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Sun, 10 Mar 2024 07:40:59 +0100 Subject: [PATCH 02/13] v2.0 --- basis/bin/auto_env.sh | 5 ++- basis/bin/shared_bash_function.sh | 7 ++++ basis/starter.sh | 54 +++++++++++++++++++------------ 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/basis/bin/auto_env.sh b/basis/bin/auto_env.sh index 5320226..43d56c3 100755 --- a/basis/bin/auto_env.sh +++ b/basis/bin/auto_env.sh @@ -7,7 +7,7 @@ if [ "$TF_VAR_instance_shape" == "VM.Standard.A1.Flex" ]; then if [ "$TF_VAR_deploy_type" == "kubernetes" ] || [ "$TF_VAR_deploy_type" == "container_instance" ] || [ "$TF_VAR_deploy_type" == "function" ]; then MISMATCH_PLATFORM="ERROR: ARM (Ampere) build using Containers (Kubernetes / Cointainer Instance / Function) needs to run on ARM processor" DESIRED_PLATFORM="ARM (aarch64)" - fi + fi fi elif [ `arch` != "x86_64" ]; then if [ "$TF_VAR_deploy_type" == "kubernetes" ] || [ "$TF_VAR_deploy_type" == "container_instance" ] || [ "$TF_VAR_deploy_type" == "function" ]; then @@ -61,6 +61,9 @@ if [ "$1" == "-no-auto" ]; then return fi +# Change the prompt +export PS1="[\e[0;3m\${TF_VAR_prefix}\e(B\e[m \u@\h \W]$ " + # Silent mode (default is not silent) if [ "$1" == "-silent" ]; then SILENT_MODE=true diff --git a/basis/bin/shared_bash_function.sh b/basis/bin/shared_bash_function.sh index 7156bbe..7747258 100755 --- a/basis/bin/shared_bash_function.sh +++ b/basis/bin/shared_bash_function.sh @@ -510,6 +510,13 @@ certificate_dir_before_terraform() { echo "ERROR: compute: certificate_dir_before_terraform: missing variables TF_VAR_certificate_dir" exit 1 fi + elif [ "$TF_VAR_deploy_type" == "kubernetes" ]; then + if [ "$TF_VAR_tls" == "new_http_01" ]; then + echo "New Certificate will be created after the deployment." + else + echo "ERROR: kubernetes: certificate_dir_before_terraform: missing variables TF_VAR_certificate_dir" + exit 1 + fi elif [ "$TF_VAR_certificate_ocid" == "" ] && [ "$TF_VAR_certificate_dir" != "" ] ; then certificate_create elif [ "$TF_VAR_certificate_ocid" != "" ]; then diff --git a/basis/starter.sh b/basis/starter.sh index 1d912f7..7856b0e 100755 --- a/basis/starter.sh +++ b/basis/starter.sh @@ -9,43 +9,56 @@ export ARG2=$2 export ARG3=$3 if [ -z $ARG1 ] || [ "$ARG1" == "help" ]; then - echo "Help:" + echo "--- HELP -------------------------------------------------------------------------------------" + echo "https://www.ocistarter.com/" + echo "https://www.ocistarter.com/help (tutorial + how to customize)" echo - echo "--- BUILD -------------------------------------------------------------------------" - echo "./starter.sh build - Build all" - echo "./starter.sh build app - Build the application" - echo "./starter.sh build ui - Build the user interface" + echo "--- BUILD ------------------------------------------------------------------------------------" + echo "./starter.sh build - Build and deploy" + echo "./starter.sh build app - Build the application (APP)" + echo "./starter.sh build ui - Build the user interface (UI)" echo - echo "--- DESTROY -----------------------------------------------------------------------" + echo "--- DESTROY ----------------------------------------------------------------------------------" echo "./starter.sh destroy - Destroy all" echo - echo "--- SSH ---------------------------------------------------------------------------" - echo "./starter.sh ssh compute - SSH to compute (Compute mode)" + echo "--- SSH --------------------------------------------------------------------------------------" + echo "./starter.sh ssh compute - SSH to compute (Deployment: Compute)" echo "./starter.sh ssh bastion - SSH to bastion" - echo "./starter.sh ssh db_node - SSH to DB_NODE (OCI Oracle Base DB)" + echo "./starter.sh ssh db_node - SSH to DB_NODE (Database: Oracle DB)" echo - echo "--- TERRAFORM (or RESOURCE MANAGER ) ----------------------------------------------" + echo "--- TERRAFORM (or RESOURCE MANAGER ) ---------------------------------------------------------" echo "./starter.sh terraform plan - Plan" echo "./starter.sh terraform apply - Apply" echo "./starter.sh terraform destroy - Destroy" echo - echo "--- GENERATE ----------------------------------------------------------------------" + echo "--- GENERATE ---------------------------------------------------------------------------------" echo "./starter.sh generate auth_token - Create OCI Auth Token (ex: docker login)" echo - echo "--- DEPLOY ------------------------------------------------------------------------" + echo "--- DEPLOY -----------------------------------------------------------------------------------" echo "./starter.sh deploy bastion - Deploy the bastion (+create DB tables)" - echo "./starter.sh deploy compute - Deploy APP and UI on Compute (Compute mode)" - echo "./starter.sh deploy oke - Deploy APP and UI on OKE (OKE mode)" + echo "./starter.sh deploy compute - Deploy APP and UI on Compute (Deployment: Compute)" + echo "./starter.sh deploy oke - Deploy APP and UI on OKE (Deployment: Kubernetes)" echo - echo "--- KUBECTL -----------------------------------------------------------------------" + echo "--- KUBECTL ----------------------------------------------------------------------------------" echo "./starter.sh env - Set kubeconfig to connect to Kubernetes" echo "kubectl get pods - Example of a command to check the PODs" + echo exit fi if [ "$ARG1" == "build" ]; then - # Show the log and save it in target/build.log - bin/build_all.sh ${@:2} 2>&1 | tee $TARGET_DIR/build.log + if [ "$ARG2" == "" ]; then + # Show the log and save it in target/build.log + bin/build_all.sh ${@:2} 2>&1 | tee $TARGET_DIR/build.log + elif [ "$ARG2" == "app" ]; then + src/app/build_app.sh ${@:2} + elif [ "$ARG2" == "ui" ]; then + src/ui/build_ui.sh ${@:2} + else + echo "Unknow command: $ARG1 $ARG2" + fi + + elif [ "$ARG1" == "destroy" ]; then bin/destroy_all.sh ${@:2} 2>&1 | tee $TARGET_DIR/destroy.log elif [ "$ARG1" == "ssh" ]; then @@ -60,11 +73,11 @@ elif [ "$ARG1" == "ssh" ]; then fi elif [ "$ARG1" == "terraform" ]; then if [ "$ARG2" == "plan" ]; then - src/terraform/plan.sh $ARG3 + src/terraform/plan.sh ${@:2} elif [ "$ARG2" == "apply" ]; then - src/terraform/apply.sh $ARG3 + src/terraform/apply.sh ${@:2} elif [ "$ARG2" == "destroy" ]; then - src/terraform/destroy.sh $ARG3 + src/terraform/destroy.sh ${@:2} else echo "Unknow command: $ARG1 $ARG2" fi @@ -86,7 +99,6 @@ elif [ "$ARG1" == "deploy" ]; then exit 1 fi elif [ "$ARG1" == "env" ]; then - export PS1="[\u@\h \W]\e[103m\$\e(B\e[m " bash --rcfile ./env.sh else echo "Unknow command: $ARG1" From 0d810243a64dbe3307ad83b0df3f2c1836f7aeaa Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Sun, 10 Mar 2024 14:19:18 +0100 Subject: [PATCH 03/13] v2.0 --- basis/bin/shared_infra_as_code.sh | 10 +++++----- option/oke/oke_destroy.sh | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/basis/bin/shared_infra_as_code.sh b/basis/bin/shared_infra_as_code.sh index c2d347d..11adda5 100755 --- a/basis/bin/shared_infra_as_code.sh +++ b/basis/bin/shared_infra_as_code.sh @@ -56,9 +56,9 @@ resource_manager_create_or_update() { VAR_FILE_PATH=$TARGET_DIR/resource_manager_variables.json if [ -f $TARGET_DIR/resource_manager_stackid ]; then echo "Stack exists already ( file target/resource_manager_stackid found )" - BACKUP_POSTFIX=`date '+%Y%m%d-%H%M%S'` - mv $ZIP_FILE_PATH $ZIP_FILE_PATH.$BACKUP_POSTFIX - mv $VAR_FILE_PATH $VAR_FILE_PATH.$BACKUP_POSTFIX + DATE_POSTFIX=`date '+%Y%m%d-%H%M%S'` + mv $ZIP_FILE_PATH $ZIP_FILE_PATH.$DATE_POSTFIX + mv $VAR_FILE_PATH $VAR_FILE_PATH.$DATE_POSTFIX fi if [ -f $ZIP_FILE_PATH ]; then @@ -77,9 +77,9 @@ resource_manager_create_or_update() { cat $TARGET_DIR/tf_var.sh | sed "s/export TF_VAR_/\"/g" | sed "s/=\"/\": \"/g" | sed ':a;N;$!ba;s/\"\n/\", /g' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/$/}/'>> $VAR_FILE_PATH if [ -f $TARGET_DIR/resource_manager_stackid ]; then - if cmp -s $ZIP_FILE_PATH $ZIP_FILE_PATH.$BACKUP_POSTFIX; then + if cmp -s $ZIP_FILE_PATH $ZIP_FILE_PATH.$DATE_POSTFIX; then rs_echo "Zip files are identical" - if cmp -s $VAR_FILE_PATH $VAR_FILE_PATH.$BACKUP_POSTFIX; then + if cmp -s $VAR_FILE_PATH $VAR_FILE_PATH.$DATE_POSTFIX; then rs_echo "Var files are identical" exit else diff --git a/option/oke/oke_destroy.sh b/option/oke/oke_destroy.sh index e82e0aa..2a274af 100755 --- a/option/oke/oke_destroy.sh +++ b/option/oke/oke_destroy.sh @@ -37,4 +37,5 @@ helm uninstall ingress-nginx --namespace ingress-nginx # kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml # Rename kubeconfig. Avoid to reuse if a new OKE is created for the same directory. -mv kubeconfig_starter kubeconfig_starter.destroyed \ No newline at end of file +DATE_POSTFIX=`date '+%Y%m%d-%H%M%S'` +mv $KUBECONFIG $KUBECONFIG.${DATE_POSTFIX} \ No newline at end of file From 6558e483d3e205bde45e1721515e3d1a837638c1 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Sun, 10 Mar 2024 14:37:51 +0100 Subject: [PATCH 04/13] v2.0 --- test_suite/test_suite_shared.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test_suite/test_suite_shared.sh b/test_suite/test_suite_shared.sh index 69b796f..ec7348e 100755 --- a/test_suite/test_suite_shared.sh +++ b/test_suite/test_suite_shared.sh @@ -164,6 +164,8 @@ build_option() { NAME=${NAME}-rm fi NAME=${NAME/_/-} + NAME=${NAME/_/-} + NAME=${NAME/_/-} start_test $NAME if [ "$TEST_ERROR_ONLY" != "" ]; then if grep -q "$TEST_DIR" $TEST_HOME/error_rerun.sh; then @@ -207,7 +209,7 @@ build_option() { -fnapp_ocid $TF_VAR_fnapp_ocid > ${TEST_DIR}.log 2>&1 else ./oci_starter.sh \ - -prefix tsone \ + -prefix $NAME \ -deploy $OPTION_DEPLOY \ -ui $OPTION_UI \ -language $OPTION_LANG \ From e1787178018d8aaadfefe163b3b31daf4487df1d Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Sun, 10 Mar 2024 17:40:46 +0100 Subject: [PATCH 05/13] v2.0 --- basis/bin/shared_bash_function.sh | 4 ++-- test_suite/test_suite_shared.sh | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/basis/bin/shared_bash_function.sh b/basis/bin/shared_bash_function.sh index 7747258..0055671 100755 --- a/basis/bin/shared_bash_function.sh +++ b/basis/bin/shared_bash_function.sh @@ -273,7 +273,7 @@ get_ui_url() { elif [ "$TF_VAR_deploy_type" == "kubernetes" ]; then export TF_VAR_ingress_ip=`kubectl get service -n ingress-nginx ingress-nginx-controller -o jsonpath="{.status.loadBalancer.ingress[0].ip}"` export UI_URL=http://${TF_VAR_ingress_ip}/${TF_VAR_prefix} - if [ "$TF_VAR_tls" != "" ] && [ "$TF_VAR_certificate_ocid" != "" ]; then + if [ "$TF_VAR_tls" != "" ] && [ "$TF_VAR_dns_name" != "" ]; then export UI_HTTP=$UI_URL export UI_URL=https://${TF_VAR_dns_name}/${TF_VAR_prefix} fi @@ -522,7 +522,7 @@ certificate_dir_before_terraform() { elif [ "$TF_VAR_certificate_ocid" != "" ]; then certificate_validity else - error_exit "certificate_dir_before_terraform: missing variables TF_VAR_certificate_ocid or TF_VAR_certificate_dir" + error_exit "certificate_dir_before_terraform: missin:g variables TF_VAR_certificate_ocid or TF_VAR_certificate_dir" fi } diff --git a/test_suite/test_suite_shared.sh b/test_suite/test_suite_shared.sh index ec7348e..fc8734e 100755 --- a/test_suite/test_suite_shared.sh +++ b/test_suite/test_suite_shared.sh @@ -15,6 +15,7 @@ OPTION_SHAPE=amd OPTION_INFRA_AS_CODE=terraform_local OPTION_JAVA_FRAMEWORK=springboot OPTION_JAVA_VM=jdk +OPTION_TSONE_ID=0 # No color for terraforms logs export nocolorarg=1 @@ -208,8 +209,10 @@ build_option() { -bastion_ocid $TF_VAR_bastion_ocid \ -fnapp_ocid $TF_VAR_fnapp_ocid > ${TEST_DIR}.log 2>&1 else + # Unique name to allow more generations of TLS certificates. The prefix is used as hostname for TLS http_01. + OPTION_TSONE_ID=$((OPTION_TSONEID+1)) ./oci_starter.sh \ - -prefix $NAME \ + -prefix tsone${OPTION_TSONE_ID} \ -deploy $OPTION_DEPLOY \ -ui $OPTION_UI \ -language $OPTION_LANG \ From 36989d52844efd5d56c244ab4f9f9954626df70c Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 11 Mar 2024 11:35:37 +0100 Subject: [PATCH 06/13] v2.0 --- basis/bin/shared_bash_function.sh | 2 +- .../me/opc/mp/database/DeptResource.j2.java | 2 ++ .../java/com/example/demo/RacController.java | 2 +- option/src/j2_macro/dotnet.j2_macro | 22 +++---------------- option/src/j2_macro/node.j2_macro | 13 ++++------- 5 files changed, 11 insertions(+), 30 deletions(-) diff --git a/basis/bin/shared_bash_function.sh b/basis/bin/shared_bash_function.sh index 0055671..8300d25 100755 --- a/basis/bin/shared_bash_function.sh +++ b/basis/bin/shared_bash_function.sh @@ -522,7 +522,7 @@ certificate_dir_before_terraform() { elif [ "$TF_VAR_certificate_ocid" != "" ]; then certificate_validity else - error_exit "certificate_dir_before_terraform: missin:g variables TF_VAR_certificate_ocid or TF_VAR_certificate_dir" + error_exit "certificate_dir_before_terraform: missing variables TF_VAR_certificate_ocid or TF_VAR_certificate_dir" fi } diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java index e17afbb..32482b3 100644 --- a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java +++ b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java @@ -1,3 +1,5 @@ +# https://blogs.oracle.com/nosql/post/getting-started-accessing-oracle-nosql-database-using-jakarta-nosql +# {% import "java.j2_macro" as m with context %} package me.opc.mp.database; diff --git a/option/src/app/java_springboot_rac/src/main/java/com/example/demo/RacController.java b/option/src/app/java_springboot_rac/src/main/java/com/example/demo/RacController.java index 535ed83..ed01376 100644 --- a/option/src/app/java_springboot_rac/src/main/java/com/example/demo/RacController.java +++ b/option/src/app/java_springboot_rac/src/main/java/com/example/demo/RacController.java @@ -40,7 +40,7 @@ public void run() { } @Autowired - public RacController(DbProperties aProperties) throws SQLException { + public RacController() throws SQLException { resetConnectionPool("jtac"); } diff --git a/option/src/j2_macro/dotnet.j2_macro b/option/src/j2_macro/dotnet.j2_macro index e40b14d..b460995 100644 --- a/option/src/j2_macro/dotnet.j2_macro +++ b/option/src/j2_macro/dotnet.j2_macro @@ -96,29 +96,13 @@ using Oracle.NoSQL.SDK; } {%- elif db_family == "nosql" %} List a = new List(); - /* - var client = new NoSQLClient( new NoSQLConfig{ - Endpoint=Environment.GetEnvironmentVariable("TF_VAR_nosql_endpoint"), - Compartment=Environment.GetEnvironmentVariable("TF_VAR_compartment_ocid"), - {%- if deploy_type in ["compute", "kubernetes", "instance_pool"] %} - AuthorizationProvider=IAMAuthorizationProvider.CreateWithInstancePrincipal() - {%- else %} - AuthorizationProvider=IAMAuthorizationProvider.CreateWithResourcePrincipal() - {%- endif %} - }); - */ try { - var options = new QueryOptions(); - do { - var task = Task.Run(() => client.QueryAsync("select deptno, dname, loc from dept", options)); - task.Wait(); - var result = task.Result; - foreach(var row in result.Rows) { + await foreach(var result in client.GetQueryAsyncEnumerable("select deptno, dname, loc from dept")) + { + foreach(var row of result.Rows) { a.Add( new Dept{ deptno = row.GetValueAtIndex(0).AsInt32.ToString(), dname = row.GetValueAtIndex(1).AsString, loc = row.GetValueAtIndex(2).AsString } ); } - options.ContinuationKey = result.ContinuationKey; } - while(options.ContinuationKey != null); } catch(Exception ex) { Console.WriteLine(ex.Message); diff --git a/option/src/j2_macro/node.j2_macro b/option/src/j2_macro/node.j2_macro index bec61e0..be39a4c 100644 --- a/option/src/j2_macro/node.j2_macro +++ b/option/src/j2_macro/node.j2_macro @@ -120,16 +120,11 @@ function createClient() { {%- endmacro -%} {% macro nosql() -%} + // See https://oracle.github.io/nosql-node-sdk/pages/tables.html let rows = []; - const opt = {}; - do { - const result = await client.query('SELECT deptno, dname, loc FROM dept', opt); + for await(let result of client.queryIterable('SELECT deptno, dname, loc FROM dept')) { for(let row of result.rows) { rows.push( row ); - } - opt.continuationKey = result.continuationKey; - } while(opt.continuationKey); - + } + } {%- endmacro -%} - - From ff73fe478ba78b91d554f23e7d83791690b960d3 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 11 Mar 2024 12:13:51 +0100 Subject: [PATCH 07/13] v2.0 --- option/src/app/dotnet/src/Controllers/DeptController.j2.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/option/src/app/dotnet/src/Controllers/DeptController.j2.cs b/option/src/app/dotnet/src/Controllers/DeptController.j2.cs index c2f0cff..9143ada 100644 --- a/option/src/app/dotnet/src/Controllers/DeptController.j2.cs +++ b/option/src/app/dotnet/src/Controllers/DeptController.j2.cs @@ -19,7 +19,11 @@ public DeptController(ILogger logger) } [Route("dept")] + {%- if db_family == "nosql" %} + public async Task> Get() + {%- else %} public IEnumerable Get() + {%- endif %} { {{ m.dept() }} return a.ToArray(); From 7fbc730c9c7d66e40d1301b552e91b6105aba2b8 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 11 Mar 2024 12:14:24 +0100 Subject: [PATCH 08/13] v2.0 --- option/src/j2_macro/dotnet.j2_macro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/option/src/j2_macro/dotnet.j2_macro b/option/src/j2_macro/dotnet.j2_macro index b460995..aa9f54d 100644 --- a/option/src/j2_macro/dotnet.j2_macro +++ b/option/src/j2_macro/dotnet.j2_macro @@ -99,7 +99,7 @@ using Oracle.NoSQL.SDK; try { await foreach(var result in client.GetQueryAsyncEnumerable("select deptno, dname, loc from dept")) { - foreach(var row of result.Rows) { + foreach(var row in result.Rows) { a.Add( new Dept{ deptno = row.GetValueAtIndex(0).AsInt32.ToString(), dname = row.GetValueAtIndex(1).AsString, loc = row.GetValueAtIndex(2).AsString } ); } } From 492e2155f162fe7f28edd9519ee8713dc45f77b7 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 11 Mar 2024 21:09:36 +0100 Subject: [PATCH 09/13] v2.0 --- option/src/app/java_helidon/pom.j2.xml | 2 +- .../me/opc/mp/database/DeptResource.j2.java | 33 ------------- .../main/java/me/opc/mp/database/Dept.java | 10 ++-- .../me/opc/mp/database/DeptRepository.java | 0 .../me/opc/mp/database/DeptResource.j2.java | 48 +++++++++++++++++++ .../opc/mp/database/FieldAccessStrategy.java | 0 .../src/main/resources/application.yaml | 0 option/src/j2_macro/java.j2_macro | 14 ++++++ 8 files changed, 66 insertions(+), 41 deletions(-) delete mode 100644 option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java rename option/src/app/{java_helidon4_nosql => java_helidon_nosql}/src/main/java/me/opc/mp/database/Dept.java (55%) rename option/src/app/{java_helidon4_nosql => java_helidon_nosql}/src/main/java/me/opc/mp/database/DeptRepository.java (100%) create mode 100644 option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java rename option/src/app/{java_helidon4_nosql => java_helidon_nosql}/src/main/java/me/opc/mp/database/FieldAccessStrategy.java (100%) rename option/src/app/{java_helidon4_nosql => java_helidon_nosql}/src/main/resources/application.yaml (100%) diff --git a/option/src/app/java_helidon/pom.j2.xml b/option/src/app/java_helidon/pom.j2.xml index 8ce0fc2..f8fea04 100644 --- a/option/src/app/java_helidon/pom.j2.xml +++ b/option/src/app/java_helidon/pom.j2.xml @@ -6,7 +6,7 @@ io.helidon.applications helidon-mp - 3.1.0 + 3.2.6 me.opc-helidon diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java deleted file mode 100644 index 32482b3..0000000 --- a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java +++ /dev/null @@ -1,33 +0,0 @@ -# https://blogs.oracle.com/nosql/post/getting-started-accessing-oracle-nosql-database-using-jakarta-nosql -# -{% import "java.j2_macro" as m with context %} -package me.opc.mp.database; - -import jakarta.persistence.*; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; -import jakarta.inject.*; -{{ m.import() }} - -/** - * Dept Table - */ -@Path("/") -public class DeptResource { - @Inject - private DeptRepository deptRepository; - - @GET - @Path("dept") - @Produces(MediaType.APPLICATION_JSON) - public List getDept() throws Exception { - return deptRepository.findAll().toList(); - } - - @GET - @Path("info") - @Produces(MediaType.TEXT_PLAIN) - public String getInfo() { - return "Java - Helidon - {{ dbName }}"; - } -} diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/Dept.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/Dept.java similarity index 55% rename from option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/Dept.java rename to option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/Dept.java index 973a545..06e60cd 100644 --- a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/Dept.java +++ b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/Dept.java @@ -5,11 +5,7 @@ @Entity @JsonbVisibility(FieldAccessStrategy.class) -public class Dept { - @Id - private int deptno; - @Column - private String dname; - @Column - private String loc; +public record Dept (@Id int deptno, + @Column String dname, + @Column String loc) { } \ No newline at end of file diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptRepository.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptRepository.java similarity index 100% rename from option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptRepository.java rename to option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptRepository.java diff --git a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java new file mode 100644 index 0000000..70e7f38 --- /dev/null +++ b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java @@ -0,0 +1,48 @@ +# https://blogs.oracle.com/nosql/post/getting-started-accessing-oracle-nosql-database-using-jakarta-nosql +# +{% import "java.j2_macro" as m with context %} +package me.opc.mp.database; + +import jakarta.persistence.*; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; +import jakarta.inject.*; +import jakarta.annotation.*; +import jakarta.enterprise.*; +{{ m.import() }} + +/** + * Dept Table + */ +@Path("/") +public class DeptResource { + @Inject + private DeptRepository repository; + + @PostConstruct + private void init() { + try { + System.out.println("Insert row " + repository.save(new Dept(10, "ACCOUNTING", "BRUSSELS"))); + System.out.println("Insert row " + repository.save(new Dept(20, "RESEARCH", "SPRING NOSQL"))); + System.out.println("Insert row " + repository.save(new Dept(30, "SALES", "ROME"))); + System.out.println("Insert row " + repository.save(new Dept(40, "OPERATIONS", "MADRID"))); + } catch (Exception e ) { + System.err.println("Init Exception:" + e.getMessage()); + e.printStackTrace(); + } + } + + @GET + @Path("dept") + @Produces(MediaType.APPLICATION_JSON) + public List getDept() throws Exception { + return repository.findAll().toList(); + } + + @GET + @Path("info") + @Produces(MediaType.TEXT_PLAIN) + public String getInfo() { + return "Java - Helidon - {{ dbName }}"; + } +} diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java similarity index 100% rename from option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java rename to option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java diff --git a/option/src/app/java_helidon4_nosql/src/main/resources/application.yaml b/option/src/app/java_helidon_nosql/src/main/resources/application.yaml similarity index 100% rename from option/src/app/java_helidon4_nosql/src/main/resources/application.yaml rename to option/src/app/java_helidon_nosql/src/main/resources/application.yaml diff --git a/option/src/j2_macro/java.j2_macro b/option/src/j2_macro/java.j2_macro index 18d0782..d33c49a 100644 --- a/option/src/j2_macro/java.j2_macro +++ b/option/src/j2_macro/java.j2_macro @@ -28,6 +28,20 @@ import javax.json.*; com.oracle.nosql.sdk spring-data-oracle-nosql 2.0.0 + + {%- elif java_framework == "helidon" %} + + io.helidon.microprofile.openapi + helidon-microprofile-openapi + + + jakarta.json.bind + jakarta.json.bind-api + + + org.eclipse.jnosql.databases + jnosql-oracle-nosql + 1.1.0 {%- endif %} {%- elif db_family_type == "sql" %} From 4a4417ce16358968e012014e6dedc69e01b75180 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 11 Mar 2024 21:16:53 +0100 Subject: [PATCH 10/13] v2.0 --- .../src/main/java/me/opc/mp/database/DeptResource.j2.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java index 70e7f38..c82634c 100644 --- a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java +++ b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java @@ -1,5 +1,3 @@ -# https://blogs.oracle.com/nosql/post/getting-started-accessing-oracle-nosql-database-using-jakarta-nosql -# {% import "java.j2_macro" as m with context %} package me.opc.mp.database; From 367dbfc7f19b08dc736cfbcb059311ebba2a1836 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 11 Mar 2024 21:58:33 +0100 Subject: [PATCH 11/13] v2.0 --- .../microprofile-config.properties.j2.tmpl | 19 +++++++++---------- .../me/opc/mp/database/DeptResource.j2.java | 1 - 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl b/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl index f1daa98..0ee8716 100644 --- a/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl +++ b/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl @@ -5,9 +5,6 @@ server.host=0.0.0.0 # Change the following to true to enable the optional MicroProfile Metrics REST.request metrics metrics.rest-request.enabled=false -# Application properties. This is the default greeting -app.greeting=Hello - # Datasource properties {%- if db_family != "none" %} {%- if db_family == "oracle" %} @@ -17,15 +14,11 @@ javax.sql.DataSource.ds1.dataSourceClassName=com.mysql.cj.jdbc.MysqlDataSource {%- elif db_family == "psql" %} javax.sql.DataSource.ds1.dataSourceClassName=org.postgresql.ds.PGSimpleDataSource {%- endif %} -javax.sql.DataSource.ds1.dataSource.url=##JDBC_URL## -javax.sql.DataSource.ds1.dataSource.user=##DB_USER## -javax.sql.DataSource.ds1.dataSource.password=##DB_PASSWORD## -{%- endif %} {%- if db_family == "nosql" %} # Oracle NoSQL Connection -jnosql.keyvalue.database=dept -jnosql.document.database=dept +jnosql.keyvalue.database=deptjee +jnosql.document.database=deptjee jnosql.oracle.nosql.table.read.limit=10 jnosql.oracle.nosql.table.write.limit=10 jnosql.oracle.nosql.table.storage.gb=1 @@ -35,5 +28,11 @@ jnosql.oracle.nosql.compartment=${TF_VAR_compartment_ocid} jnosql.oracle.nosql.deployment=CLOUD_INSTANCE_PRINCIPAL {%- else %} jnosql.oracle.nosql.deployment=CLOUD_RESOURCE_PRINCIPAL -{%- endif %} {%- endif %} +{%- else %} +javax.sql.DataSource.ds1.dataSource.url=##JDBC_URL## +javax.sql.DataSource.ds1.dataSource.user=##DB_USER## +javax.sql.DataSource.ds1.dataSource.password=##DB_PASSWORD## +{%- endif %} +{%- endif %} + diff --git a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java index c82634c..08664c3 100644 --- a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java +++ b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java @@ -6,7 +6,6 @@ import jakarta.ws.rs.core.MediaType; import jakarta.inject.*; import jakarta.annotation.*; -import jakarta.enterprise.*; {{ m.import() }} /** From 53738fe349d64a4fcfb2adfb441b71e24df5f7cb Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Tue, 12 Mar 2024 15:40:03 +0100 Subject: [PATCH 12/13] v2.0 --- .../main/java/me/opc/mp/database/DeptResource.j2.java | 2 +- .../src/main/resources/application.yaml | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 option/src/app/java_helidon_nosql/src/main/resources/application.yaml diff --git a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java index 08664c3..13721d9 100644 --- a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java +++ b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java @@ -20,7 +20,7 @@ public class DeptResource { private void init() { try { System.out.println("Insert row " + repository.save(new Dept(10, "ACCOUNTING", "BRUSSELS"))); - System.out.println("Insert row " + repository.save(new Dept(20, "RESEARCH", "SPRING NOSQL"))); + System.out.println("Insert row " + repository.save(new Dept(20, "RESEARCH", "JAKARTA NOSQL"))); System.out.println("Insert row " + repository.save(new Dept(30, "SALES", "ROME"))); System.out.println("Insert row " + repository.save(new Dept(40, "OPERATIONS", "MADRID"))); } catch (Exception e ) { diff --git a/option/src/app/java_helidon_nosql/src/main/resources/application.yaml b/option/src/app/java_helidon_nosql/src/main/resources/application.yaml deleted file mode 100644 index 5852e27..0000000 --- a/option/src/app/java_helidon_nosql/src/main/resources/application.yaml +++ /dev/null @@ -1,9 +0,0 @@ -# Oracle NoSQL Configuration -jnosql: - keyvalue: - database: beers - document: - database: beers - oracle: - nosql: - host: http://localhost:8080 \ No newline at end of file From e3304b0604df548d8cbdbfc3dfc62d318980c0b5 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Tue, 12 Mar 2024 17:25:04 +0100 Subject: [PATCH 13/13] v2.0 --- .../java/me/opc/mp/database/package-info.java | 2 -- .../opc/mp/database/FieldAccessStrategy.java | 18 ------------------ 2 files changed, 20 deletions(-) delete mode 100644 option/src/app/java_helidon/src/main/java/me/opc/mp/database/package-info.java delete mode 100644 option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java diff --git a/option/src/app/java_helidon/src/main/java/me/opc/mp/database/package-info.java b/option/src/app/java_helidon/src/main/java/me/opc/mp/database/package-info.java deleted file mode 100644 index 2706152..0000000 --- a/option/src/app/java_helidon/src/main/java/me/opc/mp/database/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ - -package me.opc.mp.database; diff --git a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java b/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java deleted file mode 100644 index c0d3ff3..0000000 --- a/option/src/app/java_helidon_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.opc.mp.database; - -import jakarta.json.bind.config.PropertyVisibilityStrategy; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -public class FieldAccessStrategy implements PropertyVisibilityStrategy { - @Override - public boolean isVisible(Field field) { - return true; - } - - @Override - public boolean isVisible(Method method) { - return true; - } -} \ No newline at end of file