Skip to content

Commit

Permalink
add oracle cdc
Browse files Browse the repository at this point in the history
agregamos cdc de oracle
  • Loading branch information
jr-marquez committed Feb 22, 2021
1 parent c71291c commit 0075e93
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ Icon
Network Trash Folder
Temporary Items
.apdisk
terraform/aws/.terraform/plugins/darwin_amd64/terraform-provider-aws_v3.28.0_x5
terraform/aws/.terraform/plugins/darwin_amd64/terraform-provider-template_v2.2.0_x4
terraform/aws/terraform.tfstate
terraform/aws/terraform.tfstate.backup
11 changes: 9 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ services:


# Other systems

mysql:
# *-----------------------------*
# To connect to the DB:
Expand Down Expand Up @@ -258,8 +259,6 @@ services:
CONTROL_CENTER_REST_LISTENERS: "http://0.0.0.0:9021"
PORT: 9021

# CONTROL_CENTER_STREAMS_CONSUMER_REQUEST_TIMEOUT_MS: "960032"

mongo:
image: mongo:4.2.5
hostname: mongo
Expand Down Expand Up @@ -295,3 +294,11 @@ services:
- "9300:9300"
environment:
discovery.type: single-node
oracle:
image: store/oracle/database-enterprise:12.2.0.1
hostname: oracle
volumes:
- ./scripts:/scripts
container_name: oracle
ports:
- 1521:1521
16 changes: 16 additions & 0 deletions docker/scripts/go_sqlplus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

export ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1
export ORACLE_SID=ORCLCDB
export PATH=${PATH}:${ORACLE_HOME}/bin
export TNS_ADMIN=${ORACLE_HOME}/admin/ORCLCDB

SQL_FILE=${1}

if [ -z "$SQL_FILE" ]; then
sqlplus '/ as sysdba'
else
sqlplus '/ as sysdba' @${SQL_FILE}
fi


37 changes: 37 additions & 0 deletions docker/scripts/oracle_setup_aws_rds.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Amazon RDS
CREATE USER myuser IDENTIFIED BY PASSWORD DEFAULT TABLESPACE USERS;
GRANT CREATE SESSION, SELECT ANY TRANSACTION, SELECT ANY DICTIONARY TO myuser;
GRANT SELECT ON SYSTEM.LOGMNR_COL$ TO myuser;
GRANT SELECT ON SYSTEM.LOGMNR_OBJ$ TO myuser;
GRANT SELECT ON SYSTEM.LOGMNR_USER$ TO myuser;
GRANT SELECT ON SYSTEM.LOGMNR_UID$ TO myuser;
ALTER USER myuser QUOTA UNLIMITED ON USERS;

GRANT CREATE SESSION TO myuser;
GRANT CREATE TABLE TO myuser;
GRANT CREATE SEQUENCE TO myuser;
GRANT CREATE TRIGGER TO myuser;
GRANT LOGMINING TO myuser;

--/
begin
rdsadmin.rdsadmin_util.grant_sys_object('DBMS_LOGMNR', 'MYUSER', 'EXECUTE');
end;
/


--/
begin
rdsadmin.rdsadmin_util.alter_supplemental_logging('ADD');
rdsadmin.rdsadmin_util.alter_supplemental_logging('ADD','ALL');
end;
/




--ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;

GRANT FLASHBACK ANY TABLE TO myuser;


69 changes: 69 additions & 0 deletions docker/scripts/oracle_setup_docker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
prompt Starting Setup

prompt Check if the ORACLE database is in archive log mode
select log_mode from v$database;

prompt Turn on ARCHIVELOG mode
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;

prompt Check if the ORACLE database is in archive log mode
select log_mode from v$database;

prompt Enable supplemental logging for all columns
ALTER SESSION SET CONTAINER=cdb$root;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;

-- to be run in the CDB
-- credit : https://docs.confluent.io/kafka-connect-oracle-cdc/current
CREATE ROLE C##CDC_PRIVS;
GRANT CREATE SESSION,
EXECUTE_CATALOG_ROLE,
SELECT ANY TRANSACTION,
SELECT ANY DICTIONARY TO C##CDC_PRIVS;
GRANT SELECT ON SYSTEM.LOGMNR_COL$ TO C##CDC_PRIVS;
GRANT SELECT ON SYSTEM.LOGMNR_OBJ$ TO C##CDC_PRIVS;
GRANT SELECT ON SYSTEM.LOGMNR_USER$ TO C##CDC_PRIVS;
GRANT SELECT ON SYSTEM.LOGMNR_UID$ TO C##CDC_PRIVS;

CREATE USER C##myuser IDENTIFIED BY password CONTAINER=ALL;
GRANT C##CDC_PRIVS TO C##myuser CONTAINER=ALL;
ALTER USER C##myuser QUOTA UNLIMITED ON sysaux;
ALTER USER C##myuser SET CONTAINER_DATA = (CDB$ROOT, ORCLPDB1) CONTAINER=CURRENT;

ALTER SESSION SET CONTAINER=CDB$ROOT;
GRANT CREATE SESSION, ALTER SESSION, SET CONTAINER, LOGMINING, EXECUTE_CATALOG_ROLE TO C##myuser CONTAINER=ALL;
GRANT SELECT ON GV_$DATABASE TO C##myuser CONTAINER=ALL;
GRANT SELECT ON V_$LOGMNR_CONTENTS TO C##myuser CONTAINER=ALL;
GRANT SELECT ON GV_$ARCHIVED_LOG TO C##myuser CONTAINER=ALL;
GRANT CONNECT TO C##myuser CONTAINER=ALL;
GRANT CREATE TABLE TO C##myuser CONTAINER=ALL;
GRANT CREATE SEQUENCE TO C##myuser CONTAINER=ALL;
GRANT CREATE TRIGGER TO C##myuser CONTAINER=ALL;

ALTER SESSION SET CONTAINER=cdb$root;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;

GRANT FLASHBACK ANY TABLE TO C##myuser;
GRANT FLASHBACK ANY TABLE TO C##myuser container=all;


prompt Create some objects
CREATE TABLE C##MYUSER.emp
(
i INTEGER GENERATED BY DEFAULT AS IDENTITY,
name VARCHAR2(100),
PRIMARY KEY (i)
) tablespace sysaux;

insert into C##MYUSER.emp (name) values ('Bob');
insert into C##MYUSER.emp (name) values ('Jane');
insert into C##MYUSER.emp (name) values ('Mary');
insert into C##MYUSER.emp (name) values ('Alice');

prompt All Done

exit;

2 changes: 2 additions & 0 deletions terraform/aws/env-vars.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export TF_VAR_aws_secret_key=<ENTER YOUR aws secret>
export TF_VAR_aws_region=<ENTER YOUR region>
export TF_VAR_ssh_key_name=<Enter your sh key name>
export TF_VAR_instance_count=<Enter your count of instances you want to create>
export TF_VAR_docker_login=<Enter your docker login -- for the oracle download, please follow with before: https://stackoverflow.com/questions/47887403/pull-access-denied-for-container-registry-oracle-com-database-enterprise>
export TF_VAR_docker_password=<Enter docker password>
15 changes: 12 additions & 3 deletions terraform/aws/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
###########################################

output "PublicIPs" {
value = tonumber(var.instance_count) >= 1 ? " Public IP Adresses are ${join(",",formatlist("%s", aws_instance.ksqldb-demo.*.public_ip),)} " : "Confluent Cloud Platform on AWS is disabled"
value ="${formatlist(
"Public IP = %s",
aws_instance.ksqldb-demo.*.public_ip
)}"
}

output "SSH" {
value = tonumber(var.instance_count) >= 1 ? " SSH Access: ssh -i ~/keys/jrMarquez_terraform.pem ec2-user@${join(",",formatlist("%s", aws_instance.ksqldb-demo.*.public_ip),)} " : "Confluent Cloud Platform on AWS is disabled"
value = "${formatlist(
"SSH Access: ssh -i ~/keys/jrMarquez_terraform.pem ec2-user@%s",
aws_instance.ksqldb-demo.*.public_ip
)}"
}
output "C3" {
value = tonumber(var.instance_count) >= 1 ? " Control Center: http://${join(",",formatlist("%s", aws_instance.ksqldb-demo.*.public_ip),)}:9021" : "Confluent Cloud Platform on AWS is disabled"
value = "${formatlist(
"Control Center: http://%s:9021",
aws_instance.ksqldb-demo.*.public_ip
)}"
}
4 changes: 3 additions & 1 deletion terraform/aws/userdata.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ data "template_file" "confluent_instance" {
template = file("../utils/instance.sh")

vars = {
confluent_ksqldb_demo = var.confluentksqldbdemo
confluent_ksqldb_demo = var.confluentksqldbdemo,
docker_login=var.docker_login,
docker_password=var.docker_password
}
}
7 changes: 5 additions & 2 deletions terraform/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ variable "instance_type_resource" {
variable "confluentksqldbdemo" {
default = "https://github.com/jr-marquez/ksqldbWorkshop/archive/main.zip"
}

variable "docker_login" {
}
variable "docker_password" {
}
variable "instance_count" {
default = "1"
default = "2"
}
6 changes: 5 additions & 1 deletion terraform/utils/instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ SCRIPT2="sed -i 's/CONTROL_CENTER_KSQL_WORKSHOP_ADVERTISED_URL: http:\/\/localho
bash -c "$SCRIPT1"
bash -c "$SCRIPT2"
#bash -c "$SCRIPT4"

chmod 666 /var/run/docker.sock
docker login -u ${docker_login} -p ${docker_password}
docker-compose up -d
sleep 120
docker-compose exec oracle /scripts/go_sqlplus.sh /scripts/oracle_setup_docker

0 comments on commit 0075e93

Please sign in to comment.