Skip to content

Commit

Permalink
Merge pull request #10498 from paulozulato/master
Browse files Browse the repository at this point in the history
feat(oracle): Oracle Database integration
  • Loading branch information
paulozulato committed Apr 27, 2023
2 parents 2bb4078 + 43bb6f0 commit 5f83562
Show file tree
Hide file tree
Showing 31 changed files with 1,494 additions and 13 deletions.
11 changes: 11 additions & 0 deletions .ci/docker-compose-file/docker-compose-oracle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.9'

services:
oracle_server:
container_name: oracle
image: oracleinanutshell/oracle-xe-11g:1.0.0
restart: always
environment:
ORACLE_DISABLE_ASYNCH_IO: true
networks:
- emqx_bridge
6 changes: 6 additions & 0 deletions .ci/docker-compose-file/toxiproxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,11 @@
"listen": "0.0.0.0:6653",
"upstream": "pulsar:6653",
"enabled": true
},
{
"name": "oracle",
"listen": "0.0.0.0:1521",
"upstream": "oracle:1521",
"enabled": true
}
]
2 changes: 1 addition & 1 deletion apps/emqx_bridge/src/emqx_bridge.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_bridge, [
{description, "EMQX bridges"},
{vsn, "0.1.17"},
{vsn, "0.1.18"},
{registered, [emqx_bridge_sup]},
{mod, {emqx_bridge_app, []}},
{applications, [
Expand Down
3 changes: 2 additions & 1 deletion apps/emqx_bridge/src/emqx_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
T == rocketmq;
T == cassandra;
T == sqlserver;
T == pulsar_producer
T == pulsar_producer;
T == oracle
).

load() ->
Expand Down
94 changes: 94 additions & 0 deletions apps/emqx_bridge_oracle/BSL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Business Source License 1.1

Licensor: Hangzhou EMQ Technologies Co., Ltd.
Licensed Work: EMQX Enterprise Edition
The Licensed Work is (c) 2023
Hangzhou EMQ Technologies Co., Ltd.
Additional Use Grant: Students and educators are granted right to copy,
modify, and create derivative work for research
or education.
Change Date: 2027-02-01
Change License: Apache License, Version 2.0

For information about alternative licensing arrangements for the Software,
please contact Licensor: https://www.emqx.com/en/contact

Notice

The Business Source License (this document, or the “License”) is not an Open
Source license. However, the Licensed Work will eventually be made available
under an Open Source License, as stated in this License.

License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
“Business Source License” is a trademark of MariaDB Corporation Ab.

-----------------------------------------------------------------------------

Business Source License 1.1

Terms

The Licensor hereby grants you the right to copy, modify, create derivative
works, redistribute, and make non-production use of the Licensed Work. The
Licensor may make an Additional Use Grant, above, permitting limited
production use.

Effective on the Change Date, or the fourth anniversary of the first publicly
available distribution of a specific version of the Licensed Work under this
License, whichever comes first, the Licensor hereby grants you rights under
the terms of the Change License, and the rights granted in the paragraph
above terminate.

If your use of the Licensed Work does not comply with the requirements
currently in effect as described in this License, you must purchase a
commercial license from the Licensor, its affiliated entities, or authorized
resellers, or you must refrain from using the Licensed Work.

All copies of the original and modified Licensed Work, and derivative works
of the Licensed Work, are subject to this License. This License applies
separately for each version of the Licensed Work and the Change Date may vary
for each version of the Licensed Work released by Licensor.

You must conspicuously display this License on each original or modified copy
of the Licensed Work. If you receive the Licensed Work in original or
modified form from a third party, the terms and conditions set forth in this
License apply to your use of that work.

Any use of the Licensed Work in violation of this License will automatically
terminate your rights under this License for the current and all other
versions of the Licensed Work.

This License does not grant you any right in any trademark or logo of
Licensor or its affiliates (provided that you may use a trademark or logo of
Licensor as expressly required by this License).

TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
TITLE.

MariaDB hereby grants you permission to use this License’s text to license
your works, and to refer to it using the trademark “Business Source License”,
as long as you comply with the Covenants of Licensor below.

Covenants of Licensor

In consideration of the right to use this License’s text and the “Business
Source License” name and trademark, Licensor covenants to MariaDB, and to all
other recipients of the licensed work to be provided by Licensor:

1. To specify as the Change License the GPL Version 2.0 or any later version,
or a license that is compatible with GPL Version 2.0 or a later version,
where “compatible” means that software provided under the Change License can
be included in a program with software provided under GPL Version 2.0 or a
later version. Licensor may specify additional Change Licenses without
limitation.

2. To either: (a) specify an additional grant of rights to use that does not
impose any additional restriction on the right granted in this License, as
the Additional Use Grant; or (b) insert the text “None”.

3. To specify a Change Date.

4. Not to modify this License in any other way.
28 changes: 28 additions & 0 deletions apps/emqx_bridge_oracle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# EMQX Oracle Database Bridge

This application houses the Oracle Database bridge for EMQX Enterprise Edition.
It implements the data bridge APIs for interacting with an Oracle Database Bridge.


# Documentation

- Refer to [EMQX Rules](https://docs.emqx.com/en/enterprise/v5.0/data-integration/rules.html)
for the EMQX rules engine introduction.


# HTTP APIs

- Several APIs are provided for bridge management, which includes create bridge,
update bridge, get bridge, stop or restart bridge and list bridges etc.

Refer to [API Docs - Bridges](https://docs.emqx.com/en/enterprise/v5.0/admin/api-docs.html#tag/Bridges) for more detailed information.


## Contributing

Please see our [contributing.md](../../CONTRIBUTING.md).


## License

See [BSL](./BSL.txt).
2 changes: 2 additions & 0 deletions apps/emqx_bridge_oracle/docker-ct
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
toxiproxy
oracle
Empty file.
13 changes: 13 additions & 0 deletions apps/emqx_bridge_oracle/rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%% -*- mode: erlang; -*-

{erl_opts, [debug_info]}.
{deps, [ {emqx_oracle, {path, "../../apps/emqx_oracle"}}
, {emqx_connector, {path, "../../apps/emqx_connector"}}
, {emqx_resource, {path, "../../apps/emqx_resource"}}
, {emqx_bridge, {path, "../../apps/emqx_bridge"}}
]}.

{shell, [
% {config, "config/sys.config"},
{apps, [emqx_bridge_oracle]}
]}.
14 changes: 14 additions & 0 deletions apps/emqx_bridge_oracle/src/emqx_bridge_oracle.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{application, emqx_bridge_oracle, [
{description, "EMQX Enterprise Oracle Database Bridge"},
{vsn, "0.1.0"},
{registered, []},
{applications, [
kernel,
stdlib,
emqx_oracle
]},
{env, []},
{modules, []},

{links, []}
]}.
109 changes: 109 additions & 0 deletions apps/emqx_bridge_oracle/src/emqx_bridge_oracle.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_bridge_oracle).

-include_lib("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-include_lib("emqx_bridge/include/emqx_bridge.hrl").
-include_lib("emqx_resource/include/emqx_resource.hrl").

-export([
conn_bridge_examples/1
]).

-export([
namespace/0,
roots/0,
fields/1,
desc/1
]).

-define(DEFAULT_SQL, <<
"insert into t_mqtt_msg(msgid, topic, qos, payload)"
"values (${id}, ${topic}, ${qos}, ${payload})"
>>).

conn_bridge_examples(Method) ->
[
#{
<<"oracle">> => #{
summary => <<"Oracle Database Bridge">>,
value => values(Method)
}
}
].

values(_Method) ->
#{
enable => true,
type => oracle,
name => <<"foo">>,
server => <<"127.0.0.1:1521">>,
pool_size => 8,
database => <<"ORCL">>,
sid => <<"ORCL">>,
username => <<"root">>,
password => <<"******">>,
sql => ?DEFAULT_SQL,
local_topic => <<"local/topic/#">>,
resource_opts => #{
worker_pool_size => 8,
health_check_interval => ?HEALTHCHECK_INTERVAL_RAW,
auto_restart_interval => ?AUTO_RESTART_INTERVAL_RAW,
batch_size => ?DEFAULT_BATCH_SIZE,
batch_time => ?DEFAULT_BATCH_TIME,
query_mode => async,
max_buffer_bytes => ?DEFAULT_BUFFER_BYTES
}
}.

%% -------------------------------------------------------------------------------------------------
%% Hocon Schema Definitions

namespace() -> "bridge_oracle".

roots() -> [].

fields("config") ->
[
{enable,
hoconsc:mk(
boolean(),
#{desc => ?DESC("config_enable"), default => true}
)},
{sql,
hoconsc:mk(
binary(),
#{desc => ?DESC("sql_template"), default => ?DEFAULT_SQL, format => <<"sql">>}
)},
{local_topic,
hoconsc:mk(
binary(),
#{desc => ?DESC("local_topic"), default => undefined}
)}
] ++ emqx_resource_schema:fields("resource_opts") ++
(emqx_oracle_schema:fields(config) --
emqx_connector_schema_lib:prepare_statement_fields());
fields("post") ->
fields("post", oracle);
fields("put") ->
fields("config");
fields("get") ->
emqx_bridge_schema:status_fields() ++ fields("post").

fields("post", Type) ->
[type_field(Type), name_field() | fields("config")].

desc("config") ->
?DESC("desc_config");
desc(_) ->
undefined.

%% -------------------------------------------------------------------------------------------------

type_field(Type) ->
{type, hoconsc:mk(hoconsc:enum([Type]), #{required => true, desc => ?DESC("desc_type")})}.

name_field() ->
{name, hoconsc:mk(binary(), #{required => true, desc => ?DESC("desc_name")})}.

0 comments on commit 5f83562

Please sign in to comment.