From f51ddc9796793f1dae0ff93d3fd1de48470e9462 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 19 Oct 2015 22:50:48 +0200 Subject: [PATCH] Extracted launcher code into cms/launcher/... libraries. (mostly to help new project based on ROC CMS). Renamed and simplified the roc cms server launcher, and the related cms execution. Updated cms.ini and extract blocks related management into blocks.ini. Added debug clauses for cms sqlite3 storage. --- examples/demo/demo-safe.ecf | 47 +++---- examples/demo/site/config/blocks.ini | 38 ++++++ examples/demo/site/config/cms.ini | 20 +-- ...erver_execution.e => demo_cms_execution.e} | 29 ++-- examples/demo/src/demo_cms_server.e | 18 +++ launcher/README.txt | 10 ++ launcher/any-safe.ecf | 18 +++ launcher/any.ecf | 19 +++ launcher/any/application_launcher.e | 19 +++ launcher/any/application_launcher_i.e | 127 ++++++++++++++++++ launcher/cgi-safe.ecf | 15 +++ launcher/default/application_launcher.e | 19 +++ launcher/default/application_launcher_i.e | 26 ++++ launcher/libfcgi-safe.ecf | 15 +++ launcher/libfcgi.ecf | 16 +++ .../roc_cms_launcher.e | 21 ++- launcher/standalone-safe.ecf | 16 +++ launcher/standalone.ecf | 17 +++ library/persistence/sqlite3/sqlite3-safe.ecf | 17 +-- .../sqlite3/src/cms_storage_sqlite3.e | 74 ++++++---- 20 files changed, 476 insertions(+), 105 deletions(-) create mode 100644 examples/demo/site/config/blocks.ini rename examples/demo/src/{ewf_roc_server_execution.e => demo_cms_execution.e} (80%) create mode 100644 examples/demo/src/demo_cms_server.e create mode 100644 launcher/README.txt create mode 100644 launcher/any-safe.ecf create mode 100644 launcher/any.ecf create mode 100644 launcher/any/application_launcher.e create mode 100644 launcher/any/application_launcher_i.e create mode 100644 launcher/cgi-safe.ecf create mode 100644 launcher/default/application_launcher.e create mode 100644 launcher/default/application_launcher_i.e create mode 100644 launcher/libfcgi-safe.ecf create mode 100644 launcher/libfcgi.ecf rename examples/demo/src/ewf_roc_server.e => launcher/roc_cms_launcher.e (74%) create mode 100644 launcher/standalone-safe.ecf create mode 100644 launcher/standalone.ecf diff --git a/examples/demo/demo-safe.ecf b/examples/demo/demo-safe.ecf index 522d166..c61f4c4 100644 --- a/examples/demo/demo-safe.ecf +++ b/examples/demo/demo-safe.ecf @@ -1,7 +1,8 @@ - + Example/demo for Eiffel ROC CMS library + /EIFGENs$ /CVS$ @@ -12,7 +13,12 @@ - + + + + @@ -24,35 +30,31 @@ - - - + + + - - - - - - + - - - + @@ -64,25 +66,14 @@ - - - - - - - - - - + - - - + diff --git a/examples/demo/site/config/blocks.ini b/examples/demo/site/config/blocks.ini new file mode 100644 index 0000000..deb55b7 --- /dev/null +++ b/examples/demo/site/config/blocks.ini @@ -0,0 +1,38 @@ +### Blocks settings + +#navigation.region=sidebar_first +#navigation.condition=is_front +management.conditions[]=path:admin* +management.conditions[]=is_front + +#Feeds +feed.news.weight=3 +feed.news.region=feed_news +feed.news.region=content +feed.news.condition= +feed.forum.weight=2 +feed.forum.region=feed_forum +feed.forum.region= +feed.forum.condition= +feed.forum.options[size]=15 + +#Updates +recent_changes.region=content +recent_changes.condition=is_front +recent_changes.title=Updates +recent_changes.options[size]=3 + +#Aliases +&aliases[foo]=management +&aliases[bar]=feed.forum + +foo.region=content +foo.condition=is_front +foo.weight=-10 + +bar.region=content +bar.condition=is_front +bar.title=Bar + + + diff --git a/examples/demo/site/config/cms.ini b/examples/demo/site/config/cms.ini index 157d916..14ecba6 100644 --- a/examples/demo/site/config/cms.ini +++ b/examples/demo/site/config/cms.ini @@ -21,28 +21,10 @@ output=@stderr # for each module, this can be overwritten with # module_name= on or off *=all -admin=on -auth=on -basic_auth=on -blog=on -debug=on -demo=on -node=on -oauth20=on -openid=on [blocks] -#navigation.region=sidebar_first -feed.news.region=feed_news -feed.news.condition=is_front - -feed.forum.region=feed_forum -feed.forum.condition=is_front - -#management.condition=is_front -#navigation.condition=is_front +@include=blocks.ini [admin] # CMS Installation, are accessible by "all", "none" or uppon "permission". (default is none) -installation_access=permission installation_access=all diff --git a/examples/demo/src/ewf_roc_server_execution.e b/examples/demo/src/demo_cms_execution.e similarity index 80% rename from examples/demo/src/ewf_roc_server_execution.e rename to examples/demo/src/demo_cms_execution.e index cbd008d..9006b56 100644 --- a/examples/demo/src/ewf_roc_server_execution.e +++ b/examples/demo/src/demo_cms_execution.e @@ -1,31 +1,21 @@ note - description: "Summary description for {EWF_ROC_SERVER_EXECUTION}." + description: "[ + CMS Execution for the demo server. + ]" date: "$Date$" revision: "$Revision$" class - EWF_ROC_SERVER_EXECUTION + DEMO_CMS_EXECUTION inherit CMS_EXECUTION - redefine - initialize - end - - REFACTORING_HELPER - - SHARED_LOGGER create make feature {NONE} -- Initialization - initialize - do - Precursor - end - initial_cms_setup: CMS_DEFAULT_SETUP -- CMS setup. local @@ -39,18 +29,17 @@ feature {NONE} -- Initialization create Result.make (l_env) end -feature -- CMS setup +feature -- CMS storage setup_storage (a_setup: CMS_SETUP) do - debug ("refactor_fixme") - to_implement ("To implement custom storage") - end --- a_setup.storage_drivers.force (create {CMS_STORAGE_STORE_MYSQL_BUILDER}.make, "mysql") a_setup.storage_drivers.force (create {CMS_STORAGE_SQLITE3_BUILDER}.make, "sqlite3") - a_setup.storage_drivers.force (create {CMS_STORAGE_STORE_ODBC_BUILDER}.make, "odbc") +-- a_setup.storage_drivers.force (create {CMS_STORAGE_STORE_MYSQL_BUILDER}.make, "mysql") +-- a_setup.storage_drivers.force (create {CMS_STORAGE_STORE_ODBC_BUILDER}.make, "odbc") end +feature -- CMS modules + setup_modules (a_setup: CMS_SETUP) -- Setup additional modules. local diff --git a/examples/demo/src/demo_cms_server.e b/examples/demo/src/demo_cms_server.e new file mode 100644 index 0000000..1e50b91 --- /dev/null +++ b/examples/demo/src/demo_cms_server.e @@ -0,0 +1,18 @@ +note + description: "[ + DEMO application server. + ]" + date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $" + revision: "$Revision: 96596 $" + +class + DEMO_CMS_SERVER + +inherit + ROC_CMS_LAUNCHER [DEMO_CMS_EXECUTION] + +create + make_and_launch + +end + diff --git a/launcher/README.txt b/launcher/README.txt new file mode 100644 index 0000000..b63b6e1 --- /dev/null +++ b/launcher/README.txt @@ -0,0 +1,10 @@ +Collection of ROC CMS launcher ready to use. + +- Include any-safe.ecf to use any of cgi, libfcgi or standalone connector. +- Include standalone-safe.ecf to use standalone connector. +- Include libfcgi-safe.ecf to use libfcgi connector. +- Include cgi-safe.ecf to use cgi connector. + +In application, the root class need to inherit from ROC_CMS_LAUNCHER with adapted CMS_EXECUTION +descendant. + diff --git a/launcher/any-safe.ecf b/launcher/any-safe.ecf new file mode 100644 index 0000000..4a7326a --- /dev/null +++ b/launcher/any-safe.ecf @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/launcher/any.ecf b/launcher/any.ecf new file mode 100644 index 0000000..9983098 --- /dev/null +++ b/launcher/any.ecf @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + diff --git a/launcher/any/application_launcher.e b/launcher/any/application_launcher.e new file mode 100644 index 0000000..bb184d0 --- /dev/null +++ b/launcher/any/application_launcher.e @@ -0,0 +1,19 @@ +note + description: "[ + Effective class for APPLICATION_LAUNCHER_I + + You can put modification in this class + ]" + date: "$Date: 2013-06-12 13:55:42 +0200 (mer., 12 juin 2013) $" + revision: "$Revision: 36 $" + +class + APPLICATION_LAUNCHER [G -> WSF_EXECUTION create make end] + +inherit + APPLICATION_LAUNCHER_I [G] + +feature -- Custom + +end + diff --git a/launcher/any/application_launcher_i.e b/launcher/any/application_launcher_i.e new file mode 100644 index 0000000..026d12f --- /dev/null +++ b/launcher/any/application_launcher_i.e @@ -0,0 +1,127 @@ +note + description: "[ + Specific application launcher + + DO NOT EDIT THIS CLASS + + you can customize APPLICATION_LAUNCHER + ]" + date: "$Date: 2013-06-12 13:55:42 +0200 (mer., 12 juin 2013) $" + revision: "$Revision: 36 $" + +deferred class + APPLICATION_LAUNCHER_I [G -> WSF_EXECUTION create make end] + +inherit + SHARED_EXECUTION_ENVIRONMENT + +feature -- Execution + + launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + nature: like launcher_nature + do + nature := launcher_nature + if nature = Void then + launch_standalone (opts) + elseif nature = nature_standalone then + launch_standalone (opts) + elseif nature = nature_nino then + launch_nino (opts) + elseif nature = nature_cgi then + launch_cgi (opts) + elseif nature = nature_libfcgi then + launch_libfcgi (opts) + else + -- bye bye + (create {EXCEPTIONS}).die (-1) + end + end + +feature {NONE} -- Access + + launcher_nature: detachable READABLE_STRING_8 + -- Initialize the launcher nature + -- either cgi, libfcgi, or nino. + --| We could extend with more connector if needed. + --| and we could use WSF_DEFAULT_SERVICE_LAUNCHER to configure this at compilation time. + local + p: PATH + ext: detachable READABLE_STRING_32 + do + create p.make_from_string (execution_environment.arguments.command_name) + if attached p.entry as l_entry then + ext := l_entry.extension + end + if ext /= Void then + if ext.same_string (nature_standalone) then + Result := nature_standalone + end + if ext.same_string (nature_nino) then + Result := nature_nino + end + if ext.same_string (nature_cgi) then + Result := nature_cgi + end + if ext.same_string (nature_libfcgi) or else ext.same_string ("fcgi") then + Result := nature_libfcgi + end + end + Result := default_nature + end + +feature {NONE} -- standalone + + nature_standalone: STRING = "standalone" + + launch_standalone (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_STANDALONE_SERVICE_LAUNCHER [G] + do + create launcher.make_and_launch (opts) + end + +feature {NONE} -- nino + + nature_nino: STRING = "nino" + + launch_nino (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_NINO_SERVICE_LAUNCHER [G] + do + create launcher.make_and_launch (opts) + end + +feature {NONE} -- cgi + + nature_cgi: STRING = "cgi" + + launch_cgi (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_CGI_SERVICE_LAUNCHER [G] + do + create launcher.make_and_launch (opts) + end + +feature {NONE} -- libfcgi + + nature_libfcgi: STRING = "libfcgi" + + launch_libfcgi (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_LIBFCGI_SERVICE_LAUNCHER [G] + do + create launcher.make_and_launch (opts) + end + +feature -- Default + + default_nature: STRING + do + Result := nature_standalone + end + + +end + + diff --git a/launcher/cgi-safe.ecf b/launcher/cgi-safe.ecf new file mode 100644 index 0000000..678960d --- /dev/null +++ b/launcher/cgi-safe.ecf @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/launcher/default/application_launcher.e b/launcher/default/application_launcher.e new file mode 100644 index 0000000..bb184d0 --- /dev/null +++ b/launcher/default/application_launcher.e @@ -0,0 +1,19 @@ +note + description: "[ + Effective class for APPLICATION_LAUNCHER_I + + You can put modification in this class + ]" + date: "$Date: 2013-06-12 13:55:42 +0200 (mer., 12 juin 2013) $" + revision: "$Revision: 36 $" + +class + APPLICATION_LAUNCHER [G -> WSF_EXECUTION create make end] + +inherit + APPLICATION_LAUNCHER_I [G] + +feature -- Custom + +end + diff --git a/launcher/default/application_launcher_i.e b/launcher/default/application_launcher_i.e new file mode 100644 index 0000000..4d91129 --- /dev/null +++ b/launcher/default/application_launcher_i.e @@ -0,0 +1,26 @@ +note + description: "[ + Specific application launcher + + DO NOT EDIT THIS CLASS + + you can customize APPLICATION_LAUNCHER + ]" + date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $" + revision: "$Revision: 96596 $" + +deferred class + APPLICATION_LAUNCHER_I [G -> WSF_EXECUTION create make end] + +feature -- Execution + + launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_DEFAULT_SERVICE_LAUNCHER [G] + do + create launcher.make_and_launch (opts) + end + +end + + diff --git a/launcher/libfcgi-safe.ecf b/launcher/libfcgi-safe.ecf new file mode 100644 index 0000000..2e8fd5b --- /dev/null +++ b/launcher/libfcgi-safe.ecf @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/launcher/libfcgi.ecf b/launcher/libfcgi.ecf new file mode 100644 index 0000000..71a51e6 --- /dev/null +++ b/launcher/libfcgi.ecf @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/examples/demo/src/ewf_roc_server.e b/launcher/roc_cms_launcher.e similarity index 74% rename from examples/demo/src/ewf_roc_server.e rename to launcher/roc_cms_launcher.e index 1bfdcab..e3de748 100644 --- a/examples/demo/src/ewf_roc_server.e +++ b/launcher/roc_cms_launcher.e @@ -1,12 +1,12 @@ note description: "[ - application service + Reusable ROC CMS launcher. ]" date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $" revision: "$Revision: 96596 $" class - EWF_ROC_SERVER + ROC_CMS_LAUNCHER [G -> CMS_EXECUTION create make end] inherit WSF_LAUNCHABLE_SERVICE @@ -37,16 +37,27 @@ feature {NONE} -- Initialization -- Initialize current service. local env: CMS_ENVIRONMENT + l_app_name: detachable READABLE_STRING_32 do Precursor - create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} service_options.make_from_file ("demo.ini") create env.make_default + l_app_name := optional_application_name + if l_app_name = Void then + l_app_name := env.name + end + create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} service_options.make_from_file (l_app_name + ".ini") initialize_logger (env) end + optional_application_name: detachable READABLE_STRING_32 + -- Optional application name. + --| Redefine if needed. + do + end + feature {NONE} -- Launch operation - launcher: APPLICATION_LAUNCHER [EWF_ROC_SERVER_EXECUTION] + launcher: APPLICATION_LAUNCHER [G] launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) local @@ -70,7 +81,7 @@ feature {NONE} -- Launch operation l_message.append ("%N%N") end else - l_message.append ("The application crash without available information") + l_message.append ("The application crashed without information.") l_message.append ("%N%N") end -- send email shutdown diff --git a/launcher/standalone-safe.ecf b/launcher/standalone-safe.ecf new file mode 100644 index 0000000..092b77a --- /dev/null +++ b/launcher/standalone-safe.ecf @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/launcher/standalone.ecf b/launcher/standalone.ecf new file mode 100644 index 0000000..f9aa378 --- /dev/null +++ b/launcher/standalone.ecf @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/library/persistence/sqlite3/sqlite3-safe.ecf b/library/persistence/sqlite3/sqlite3-safe.ecf index d8b07c3..566217e 100644 --- a/library/persistence/sqlite3/sqlite3-safe.ecf +++ b/library/persistence/sqlite3/sqlite3-safe.ecf @@ -1,32 +1,33 @@ - + + - - + + + - + /old$ /EIFGENs$ /CVS$ /.svn$ - /old$ diff --git a/library/persistence/sqlite3/src/cms_storage_sqlite3.e b/library/persistence/sqlite3/src/cms_storage_sqlite3.e index 27e81f2..4c53138 100644 --- a/library/persistence/sqlite3/src/cms_storage_sqlite3.e +++ b/library/persistence/sqlite3/src/cms_storage_sqlite3.e @@ -75,6 +75,9 @@ feature -- Execution sqlite.begin_transaction (False) end transaction_depth := transaction_depth + 1 + debug ("roc_storage") + print ("# sql_begin_transaction (depth="+ transaction_depth.out +").%N") + end end sql_rollback_transaction @@ -84,6 +87,9 @@ feature -- Execution sqlite.rollback end transaction_depth := transaction_depth - 1 + debug ("roc_storage") + print ("# sql_rollback_transaction (depth="+ transaction_depth.out +").%N") + end end sql_commit_transaction @@ -93,12 +99,18 @@ feature -- Execution sqlite.commit end transaction_depth := transaction_depth - 1 + debug ("roc_storage") + print ("# sql_commit_transaction (depth="+ transaction_depth.out +").%N") + end end sql_post_execution -- Post database execution. -- note: execute after each `sql_query' and `sql_change'. do + debug ("roc_storage") + print ("# sql_post_execution.%N") + end -- FIXME if sqlite.has_error then write_critical_log (generator + ".post_execution Error occurred!") @@ -116,6 +128,9 @@ feature -- Operation local st: SQLITE_QUERY_STATEMENT do + debug ("roc_storage") + print ("> sql_query (" +a_sql_statement + ").%N") + end last_sqlite_result_cursor := Void create st.make (a_sql_statement, sqlite) last_statement := st @@ -129,16 +144,31 @@ feature -- Operation else error_handler.add_custom_error (1, "invalid query", "query compilation failed!") end + debug ("roc_storage") + print ("< sql_query (" +a_sql_statement + ").%N") + end end sql_finalize -- Finalize sql query (i.e destroy previous query statement. do - if attached last_statement as st then - st.dispose + debug ("roc_storage") + print ("> sql_finalize.%N") + end + if attached last_statement as st then + st.cleanup + end + if attached last_sqlite_result_cursor as cur then + if cur.statement /= last_statement then + check should_not_occurs: False end + cur.statement.cleanup + end + last_sqlite_result_cursor := Void end - last_sqlite_result_cursor := Void last_statement := Void + debug ("roc_storage") + print ("< sql_finalize.%N") + end end sql_insert (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) @@ -146,6 +176,9 @@ feature -- Operation local st: SQLITE_INSERT_STATEMENT do + debug ("roc_storage") + print ("> sql_insert (" +a_sql_statement + ").%N") + end last_sqlite_result_cursor := Void create st.make (a_sql_statement, sqlite) last_statement := st @@ -159,6 +192,9 @@ feature -- Operation else error_handler.add_custom_error (1, "invalid query", "query compilation failed!") end + debug ("roc_storage") + print ("< sql_insert (" +a_sql_statement + ").%N") + end end sql_modify (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) @@ -166,6 +202,9 @@ feature -- Operation local st: SQLITE_MODIFY_STATEMENT do + debug ("roc_storage") + print ("> sql_modify (" +a_sql_statement + ").%N") + end last_sqlite_result_cursor := Void create st.make (a_sql_statement, sqlite) last_statement := st @@ -179,6 +218,9 @@ feature -- Operation else error_handler.add_custom_error (1, "invalid query", "query compilation failed!") end + debug ("roc_storage") + print ("< sql_modify (" +a_sql_statement + ").%N") + end end sqlite_arguments (a_params: STRING_TABLE [detachable ANY]): ARRAYED_LIST [SQLITE_BIND_ARG [ANY]] @@ -279,32 +321,14 @@ feature -- Operation feature -- Access --- sql_rows_count: INTEGER --- -- Number of rows for last sql execution. --- do --- if attached last_sqlite_result_cursor as l_cursor then --- -- FIXME: find better solution! --- from --- Result := 1 --- until --- not l_cursor.after --- loop --- Result := Result + 1 --- end --- end --- end - sql_start - -- Set the cursor on first element. + -- . do - -- Already at first position if any ? - if attached last_sqlite_result_cursor as l_cursor then --- l_cursor.start - end + -- sqlite cursor `last_sqlite_result_cursor', already at first position if any. end sql_after: BOOLEAN - -- Are there no more items to iterate over? + -- . do if attached last_sqlite_result_cursor as l_cursor then Result := l_cursor.after @@ -312,7 +336,7 @@ feature -- Access end sql_forth - -- Fetch next row from last sql execution, if any. + -- . do if attached last_sqlite_result_cursor as l_cursor then l_cursor.forth