Skip to content

Commit 8b4cf15

Browse files
Merge pull request #9 from paulparkinson/main
prep statement in propsetup, python debug stmt removed, etc
2 parents 2e9e383 + b5adc5f commit 8b4cf15

File tree

4 files changed

+99
-58
lines changed

4 files changed

+99
-58
lines changed

grabdish/addAndSourcePropertiesInBashrc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
# we put a placeholder msdataworkshopjaegeraddress.txt as we wont have the Jaeger LB address until later/setJaegerAddress.sh step
66
touch workingdir/msdataworkshopjaegeraddress.txt
77
echo "export MSDATAWORKSHOP_LOCATION=~/microservices-datadriven/grabdish/" >> ~/.bashrc
8-
echo "source ~/msdataworkshop-master/msdataworkshop.properties" >> ~/.bashrc
8+
echo "source $MSDATAWORKSHOP_LOCATION/msdataworkshop.properties" >> ~/.bashrc
99
source ~/.bashrc
1010

grabdish/atpaqadmin/src/main/java/oracle/db/microservices/PropagationSetup.java

Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
2+
33
**
44
** Copyright (c) 2021 Oracle and/or its affiliates.
55
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
@@ -20,64 +20,39 @@
2020
class PropagationSetup {
2121
String GET_OBJECT_CWALLETSSO_DATA_PUMP_DIR = "BEGIN " +
2222
"DBMS_CLOUD.GET_OBJECT(" +
23-
"object_uri => '" + cwalletobjecturi + "', " +
23+
"object_uri => ?, " +
2424
"directory_name => 'DATA_PUMP_DIR'); " +
2525
"END;";
2626

27-
String DROP_CREDENTIAL_INVENTORYPDB_CRED_SQL = "BEGIN " +
27+
String DROP_CREDENTIAL_SQL = "BEGIN " +
2828
"DBMS_CLOUD.DROP_CREDENTIAL(" +
29-
"credential_name => 'INVENTORYPDB_CRED'" +
29+
"credential_name => ?" +
3030
");" +
3131
"END;";
3232

33-
String CREATE_CREDENTIAL_INVENTORYPDB_CRED_SQL = " BEGIN" +
33+
String CREATE_CREDENTIAL_SQL = " BEGIN" +
3434
" DBMS_CLOUD.CREATE_CREDENTIAL(" +
3535
" credential_name => 'INVENTORYPDB_CRED'," +
36-
" username => '" + inventoryuser + "'," +
37-
" password => '" + inventorypw.trim() + "'" +
36+
" username => ?," +
37+
" password => ?" +
3838
" );" +
3939
" END;";
4040

41-
String CREATE_DBLINK_ORDERTOINVENTORY_SQL = "BEGIN " +
41+
String CREATE_DBLINK_SQL = "BEGIN " +
4242
"DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK(" +
43-
"db_link_name => '" + orderToInventoryLinkName + "'," +
44-
"hostname => '" + inventoryhostname + "'," +
45-
"port => '" + inventoryport + "'," +
46-
"service_name => '" + inventoryservice_name + "'," +
47-
"ssl_server_cert_dn => '" + inventoryssl_server_cert_dn + "'," +
48-
"credential_name => 'INVENTORYPDB_CRED'," +
49-
"directory_name => 'DATA_PUMP_DIR');" +
50-
"END;";
51-
52-
String DROP_CREDENTIAL_ORDERPDB_CRED_SQL = "BEGIN " +
53-
"DBMS_CLOUD.DROP_CREDENTIAL(" +
54-
"credential_name => 'ORDERPDB_CRED'" +
55-
");" +
56-
"END;";
57-
58-
String CREATE_CREDENTIAL_ORDERPDB_CRED_SQL = " BEGIN" +
59-
" DBMS_CLOUD.CREATE_CREDENTIAL(" +
60-
" credential_name => 'ORDERPDB_CRED'," +
61-
" username => '" + orderuser + "'," +
62-
" password => '" + orderpw.trim() + "'" +
63-
" );" +
64-
" END;";
65-
66-
String CREATE_DBLINK_INVENTORYTOORDER_SQL = "BEGIN " +
67-
"DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK(" +
68-
"db_link_name => '" + inventoryToOrderLinkName + "'," +
69-
"hostname => '" + orderhostname + "'," +
70-
"port => '" + orderport + "'," +
71-
"service_name => '" + orderservice_name + "'," +
72-
"ssl_server_cert_dn => '" + orderssl_server_cert_dn + "'," +
73-
"credential_name => 'ORDERPDB_CRED'," +
74-
"directory_name => 'DATA_PUMP_DIR');" +
43+
"db_link_name => ?," +
44+
"hostname => ?," +
45+
"port => ?," +
46+
"service_name => ?," +
47+
"ssl_server_cert_dn => ?," +
48+
"credential_name => ?," +
49+
"directory_name => ?);" +
7550
"END;";
7651

7752
String createInventoryTable(DataSource inventorypdbDataSource) throws SQLException {
7853
System.out.println("createInventoryTable and add items");
7954
String returnValue = "createInventoryTable and add items... ";
80-
try (Connection connection = inventorypdbDataSource.getConnection(inventoryuser, inventorypw)){
55+
try (Connection connection = inventorypdbDataSource.getConnection(inventoryuser, inventorypw)) {
8156
connection.createStatement().execute("drop table inventory");
8257
returnValue += " inventory table dropped, about to create inventory table...";
8358
connection.createStatement().execute(
@@ -94,7 +69,7 @@ String createInventoryTable(DataSource inventorypdbDataSource) throws SQLExcepti
9469
return returnValue;
9570
}
9671

97-
String createUsers(DataSource orderpdbDataSource, DataSource inventorypdbDataSource) throws SQLException {
72+
String createUsers(DataSource orderpdbDataSource, DataSource inventorypdbDataSource) {
9873
String returnValue = "";
9974
try {
10075
returnValue += createAQUser(orderpdbDataSource, orderuser, orderpw);
@@ -114,7 +89,7 @@ String createUsers(DataSource orderpdbDataSource, DataSource inventorypdbDataSou
11489
Object createAQUser(DataSource ds, String queueOwner, String queueOwnerPW) throws SQLException {
11590
String outputString = "createAQUser queueOwner = [" + queueOwner + "]";
11691
System.out.println(outputString + "queueOwnerPW = [" + queueOwnerPW + "]");
117-
try (Connection connection = ds.getConnection()){
92+
try (Connection connection = ds.getConnection()) {
11893
PreparedStatement pstmt = connection.prepareStatement("grant pdb_dba to ? identified by ?");
11994
pstmt.setString(1, queueOwner);
12095
pstmt.setString(2, queueOwnerPW);
@@ -134,43 +109,55 @@ Object createAQUser(DataSource ds, String queueOwner, String queueOwnerPW) throw
134109

135110
String createDBLinks(DataSource orderpdbDataSource, DataSource inventorypdbDataSource) throws SQLException {
136111
System.out.println("createDBLinks...");
137-
try (Connection connection = orderpdbDataSource.getConnection(orderuser, orderpw)){
112+
try (Connection connection = orderpdbDataSource.getConnection(orderuser, orderpw)) {
138113
// create link from order to inventory...
139114
createDBLink(connection,
140-
GET_OBJECT_CWALLETSSO_DATA_PUMP_DIR, DROP_CREDENTIAL_INVENTORYPDB_CRED_SQL,
141-
CREATE_CREDENTIAL_INVENTORYPDB_CRED_SQL, CREATE_DBLINK_ORDERTOINVENTORY_SQL, orderToInventoryLinkName);
115+
GET_OBJECT_CWALLETSSO_DATA_PUMP_DIR, "INVENTORYPDB_CRED", "ordertoinventory", orderToInventoryLinkName);
142116
}
143117
try (Connection connection = inventorypdbDataSource.getConnection(inventoryuser, inventorypw)) {
144118
createDBLink(connection,
145-
GET_OBJECT_CWALLETSSO_DATA_PUMP_DIR, DROP_CREDENTIAL_ORDERPDB_CRED_SQL,
146-
CREATE_CREDENTIAL_ORDERPDB_CRED_SQL, CREATE_DBLINK_INVENTORYTOORDER_SQL, inventoryToOrderLinkName);
119+
GET_OBJECT_CWALLETSSO_DATA_PUMP_DIR, "ORDERPDB_CRED", "inventorytoorder", inventoryToOrderLinkName);
147120
}
148121
verifyDBLinks(orderpdbDataSource, inventorypdbDataSource);
149122
return "DBLinks created and verified successfully";
150123
}
151124

152-
private void createDBLink(Connection connection, String getobject, String dropcred,
153-
String createcred, String createlink, String linkname) throws SQLException {
125+
private void createDBLink(Connection connection, String getobject, String dropcred, String createlink, String linkname) throws SQLException {
126+
boolean isOrderToInventory = createlink.equals("ordertoinventory"); // if it's not OrderToInventory it's InventoryToOrder
154127
System.out.println(" creating link:" + linkname);
155128
System.out.println("\n about to " + getobject);
156-
connection.createStatement().execute(getobject);
129+
PreparedStatement preparedStatement2 = connection.prepareStatement(GET_OBJECT_CWALLETSSO_DATA_PUMP_DIR);
130+
preparedStatement2.setString(1, cwalletobjecturi);
131+
preparedStatement2.execute();
157132
try {
158133
System.out.println("\n GET_OBJECT cwalletobjecturi successful, about to (if exists_" + dropcred);
159-
connection.createStatement().execute(dropcred);
134+
PreparedStatement preparedStatement = connection.prepareStatement(DROP_CREDENTIAL_SQL);
135+
preparedStatement.setString(1, dropcred);
136+
preparedStatement.execute();
160137
} catch (SQLException ex) {
161138
System.out.println("SQLException from DROP_CREDENTIAL_INVENTORYPDB_CRED_SQL (likely expected) :" + ex);
162139
}
163-
System.out.println("\n GET_OBJECT cwalletobjecturi successful, about to " + createcred);
164-
connection.createStatement().execute(createcred);
140+
System.out.println("\n GET_OBJECT cwalletobjecturi successful, about to create credential");
141+
PreparedStatement preparedStatement1 = connection.prepareStatement(CREATE_CREDENTIAL_SQL);
142+
preparedStatement1.setString(1, isOrderToInventory?inventoryuser:orderuser);
143+
preparedStatement1.setString(1, isOrderToInventory?inventorypw.trim():orderpw.trim());
144+
preparedStatement1.execute();
165145
System.out.println("\n CREATE_CREDENTIAL INVENTORYPDB_CRED successful, about to " + createlink);
166146
connection.createStatement().execute(createlink);
147+
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_DBLINK_SQL);
148+
preparedStatement.setString(1, isOrderToInventory ? orderToInventoryLinkName : inventoryToOrderLinkName);
149+
preparedStatement.setString(2, isOrderToInventory ? inventoryhostname : orderhostname);
150+
preparedStatement.setInt(3, Integer.valueOf(isOrderToInventory ? inventoryport : orderport));
151+
preparedStatement.setString(4, isOrderToInventory ? inventoryservice_name : orderservice_name);
152+
preparedStatement.setString(5, isOrderToInventory ? inventoryssl_server_cert_dn : orderssl_server_cert_dn);
153+
preparedStatement.execute();
167154
System.out.println("\n CREATE_DATABASE_LINK " + linkname + " successful,");
168155
}
169156

170157
String verifyDBLinks(DataSource orderpdbDataSource, DataSource inventorypdbDataSource) throws SQLException {
171158
String returnString = "";
172159
returnString += "orderuser select on inventorypdb using link...";
173-
try (Connection orderconnection = orderpdbDataSource.getConnection(orderuser, orderpw)){
160+
try (Connection orderconnection = orderpdbDataSource.getConnection(orderuser, orderpw)) {
174161
System.out.println("verifyDBLinks orderconnection:" + orderconnection);
175162
orderconnection.createStatement().execute("create table templinktest (id varchar(32))");
176163
System.out.println("verifyDBLinks temp table created on order");
@@ -183,7 +170,7 @@ String verifyDBLinks(DataSource orderpdbDataSource, DataSource inventorypdbDataS
183170
returnString += ex;
184171
}
185172
returnString += "inventoryuser select on orderpdb using link...";
186-
try (Connection inventoryconnection = inventorypdbDataSource.getConnection(inventoryuser, inventorypw)){
173+
try (Connection inventoryconnection = inventorypdbDataSource.getConnection(inventoryuser, inventorypw)) {
187174
System.out.println("verifyDBLinks inventoryconnection:" + inventoryconnection);
188175
inventoryconnection.createStatement().execute("create table templinktest (id varchar(32))");
189176
System.out.println("verifyDBLinks temp table created on inventory");

grabdish/inventory-python/common/dbmgr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
kms_vault_client_composite = oci.key_management.KmsVaultClientCompositeOperations(
2929
kms_vault_client)
3030
db_password = get_secret(vaults_management_client_composite, region_id, vault_secret_ocid).data
31-
print("Secret ID is {}.".format(db_password))
3231

3332
readyfile = ""
3433
logger = None
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: supplier-helidon-se
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: supplier
10+
template:
11+
metadata:
12+
labels:
13+
app: supplier
14+
version: helidon-se
15+
spec:
16+
initContainers:
17+
- name: decode-creds
18+
command:
19+
- bash
20+
- -c
21+
- "for i in `ls -1 /tmp/creds | grep -v user_name`; do cat /tmp/creds/$i | base64 --decode > /creds/$i; done; ls -l /creds/*;"
22+
image: oraclelinux:7.5
23+
volumeMounts:
24+
- name: creds-raw
25+
mountPath: /tmp/creds
26+
readOnly: false
27+
- name: creds
28+
mountPath: /creds
29+
containers:
30+
- name: supplier
31+
image: %DOCKER_REGISTRY%/supplier-helidon-se:0.1
32+
imagePullPolicy: Always
33+
env:
34+
- name: database.user
35+
value: "INVENTORYUSER"
36+
- name: database.url
37+
value: "jdbc:oracle:thin:@%INVENTORY_PDB_NAME%_tp?TNS_ADMIN=/msdataworkshop/creds"
38+
- name: inventoryqueuename
39+
value: "inventoryqueue"
40+
- name: OCI_REGION
41+
value: "%OCI_REGION%"
42+
- name: VAULT_SECRET_OCID
43+
value: "%VAULT_SECRET_OCID%"
44+
volumeMounts:
45+
- name: creds
46+
mountPath: /msdataworkshop/creds
47+
ports:
48+
- containerPort: 8080
49+
restartPolicy: Always
50+
volumes:
51+
- name: creds-raw
52+
secret:
53+
secretName: atp-demo-binding-inventory
54+
- name: creds
55+
emptyDir: {}

0 commit comments

Comments
 (0)