Skip to content

Commit f672701

Browse files
authored
Merge branch 'main' into jbrasero3110
2 parents 678039c + a2d3176 commit f672701

File tree

15 files changed

+392
-3
lines changed

15 files changed

+392
-3
lines changed

app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ This example is based on the <a href="../java-helloworld-with-local-dev-and-oci-
5555

5656
To do the OCI SDK authentication and authorization to use the GenAI services the function uses two options:
5757
<ul>
58-
<li>IAM regular <b>user auth</b> for the local dev and test on mac</li>
59-
<li><b>InstancePrincipal</b> auth for the OCI Function by passing config key <code>AUTH_INSTANCE_PRINCIPAL</code> with any value (then not being null)</li>
58+
<li><b>IAM regular user</b> for the local dev and test on mac</li>
59+
<li><b>InstancePrincipal</b> for the OCI Function by passing config key <code>AUTH_INSTANCE_PRINCIPAL</code> with any value (then not being null)</li>
6060
</ul>
6161

6262
<p>
6363
IAM user option will work on both cases above, as local and as OCI Function.
6464

65+
## Build and test
66+
67+
During following the steps of the <a href="../java-helloworld-with-local-dev-and-oci-functions">Hello function example </a> adjust the <a href="https://github.com/oracle-devrel/technology-engineering/blob/main/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java#L93">line 93</a> to match your <code>GenAI service OCID</code>.
68+
6569
<p>
6670

6771
Testing with curl (or copy-pasting the API Gateway deployment url to a browser):

data-platform/open-source-data-platforms/oci-streaming/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Reviewed: 04.06.2024
1111

1212
# Team Publications
1313

14-
- [Revival of the Magical Suitcase](https://medium.com/@devpiotrekk/revival-of-the-magical-suitcase-73093af23f29)
1514
- [LiveLabs: Deploying OCI Streaming Service](https://apexapps.oracle.com/pls/apex/f?p=133:180:107188281482541::::wid:664)
1615
- [LiveLabs: How do I ingest messages into OCI streaming in real-time with Oracle GoldenGate for Big Data?](https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/run-workshop?p210_wid=3572&session=107188281482541)
1716

@@ -20,6 +19,13 @@ Reviewed: 04.06.2024
2019
- [OCI Streaming Documentation](https://docs.oracle.com/en-us/iaas/Content/Streaming/Concepts/streamingoverview.htm)
2120
- [Overview of OCI Streaming - YouTube](https://www.youtube.com/watch?v=G8-E_j-uVak)
2221

22+
# Reusable Assets
23+
24+
- [Revival of the Magical Suitcase](https://medium.com/@devpiotrekk/revival-of-the-magical-suitcase-73093af23f29)
25+
26+
- [Fake Producer and Consumer for OCI Streaming](https://github.com/oracle-devrel/technology-engineering/tree/main/data-platform/open-source-data-platforms/oci-streaming/code-examples/fake-producer-consumer)
27+
28+
- [Create and run Mosquitto & Node-RED, connecting to OCI Streaming](https://github.com/oracle-devrel/technology-engineering/tree/main/data-platform/open-source-data-platforms/oci-streaming/code-examples/mosquitto_node-red)
2329

2430
# License
2531

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2024 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Example of Producing and Consuming for OCI Streaming
2+
3+
Reviewed: 22.10.2024
4+
5+
1. Create compute instance. Oracle Linux 7.
6+
2. Run the below to install Git, clone the repo, and install several packages
7+
```
8+
sudo dnf install git-all -y
9+
git clone https://github.com/bobpeulen/apache_kafka.git
10+
sudo pip3 install kafka-python3 pandas numpy datetime
11+
```
12+
13+
3. Run the producer.
14+
15+
```
16+
python apache_kafka/oci_streaming/producer.py \
17+
-tenancy_name 'oraemeadatamgmt' \
18+
-region 'eu-frankfurt-1' \
19+
-user_name 'OracleIdentityCloudService/[email protected]' \
20+
-stream_name 'OpenSourceData_stream_1' \
21+
-stream_pool_ocid 'ocid1.streampool.oc1.eu-frankfurt-1.amaaaaaaeicj2tiacazj6xzvn7rkfdyci6w2io634erapt7ctpxtqxauvocmea' \
22+
-auth_token 'ADD YOUR TOKEN HERE'
23+
```
24+
25+
4. Run the consumer.
26+
```
27+
python apache_kafka/oci_streaming/consumer.py \
28+
-tenancy_name 'oraemeadatamgmt' \
29+
-region 'eu-frankfurt-1' \
30+
-user_name 'OracleIdentityCloudService/[email protected]' \
31+
-stream_name 'OpenSourceData_stream_1' \
32+
-stream_pool_ocid 'ocid1.streampool.oc1.eu-frankfurt-1.amaaaaaaeicj2tiacazj6xzvn7rkfdyci6w2io634erapt7ctpxtqxauvocmea' \
33+
-auth_token 'ADD YOUR TOKEN HERE'
34+
```
35+
36+
# License
37+
38+
Copyright (c) 2024 Oracle and/or its affiliates.
39+
40+
Licensed under the Universal Permissive License (UPL), Version 1.0.
41+
42+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from kafka3 import KafkaConsumer, KafkaProducer
2+
import pandas as pd
3+
from time import sleep
4+
import datetime
5+
import numpy as np
6+
from datetime import datetime, timedelta
7+
import random
8+
import argparse
9+
import uuid
10+
11+
#get arguments
12+
parser = argparse.ArgumentParser()
13+
14+
parser.add_argument("-tenancy_name", "--tenancy_name", help="tenancy_name", required=True)
15+
parser.add_argument("-region", "--region", help="region",required=True)
16+
parser.add_argument("-user_name", "--user_name", help="user_name including OracleIdentityCloudService", required=True)
17+
parser.add_argument("-stream_name", "--stream_name", help="stream_name / topic", required=True)
18+
parser.add_argument("-stream_pool_ocid", "--stream_pool_ocid", help="stream_pool_ocid", required=True)
19+
parser.add_argument("-auth_token", "--auth_token", help="auth_token", required=True)
20+
21+
22+
args = parser.parse_args()
23+
tenancy_name = args.tenancy_name
24+
region = args.region
25+
user_name = args.user_name
26+
stream_name = args.stream_name
27+
stream_pool_ocid = args.stream_pool_ocid
28+
auth_token = args.auth_token
29+
30+
31+
def main():
32+
consumer = KafkaConsumer(stream_name, bootstrap_servers = f'cell-1.streaming.{region}.oci.oraclecloud.com:9092',
33+
security_protocol = 'SASL_SSL', sasl_mechanism = 'PLAIN',
34+
sasl_plain_username = f'{tenancy_name}/{user_name}/{stream_pool_ocid}',
35+
sasl_plain_password = auth_token)
36+
37+
for message in consumer:
38+
print(f"{message.key}: {message.value}")
39+
40+
41+
if __name__ == '__main__':
42+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from kafka3 import KafkaConsumer, KafkaProducer
2+
import pandas as pd
3+
from time import sleep
4+
import datetime
5+
import numpy as np
6+
from datetime import datetime, timedelta
7+
import random
8+
import argparse
9+
import uuid
10+
11+
#get arguments
12+
parser = argparse.ArgumentParser()
13+
14+
parser.add_argument("-tenancy_name", "--tenancy_name", help="tenancy_name", required=True)
15+
parser.add_argument("-region", "--region", help="region",required=True)
16+
parser.add_argument("-user_name", "--user_name", help="user_name including OracleIdentityCloudService", required=True)
17+
parser.add_argument("-stream_name", "--stream_name", help="stream_name / topic", required=True)
18+
parser.add_argument("-stream_pool_ocid", "--stream_pool_ocid", help="stream_pool_ocid", required=True)
19+
parser.add_argument("-auth_token", "--auth_token", help="auth_token", required=True)
20+
21+
22+
args = parser.parse_args()
23+
tenancy_name = args.tenancy_name
24+
region = args.region
25+
user_name = args.user_name
26+
stream_name = args.stream_name
27+
stream_pool_ocid = args.stream_pool_ocid
28+
auth_token = args.auth_token
29+
30+
31+
def main():
32+
## create connection
33+
producer = KafkaProducer(bootstrap_servers = f'cell-1.streaming.{region}.oci.oraclecloud.com:9092', linger_ms = 50, batch_size = 2,
34+
security_protocol = 'SASL_SSL', sasl_mechanism = 'PLAIN',
35+
value_serializer = lambda v: v.encode('utf-8'),
36+
sasl_plain_username = f'{tenancy_name}/{user_name}/{stream_pool_ocid}',
37+
sasl_plain_password = auth_token)
38+
#create random data
39+
pd_list = []
40+
41+
for i in range(500):
42+
43+
#set randomness, so each goes up and down together
44+
randomness_sun_price = random.uniform(0.95, 1.015)
45+
randomness_wspd = random.uniform(0.90, 0.95)
46+
cust_id = str(uuid.uuid4())
47+
kwh_producing = round(random.uniform(0.11, 5.55), 2)
48+
kwh_consuming = round(random.uniform(3.55, 19.55), 2)
49+
50+
##weather info
51+
temp = randomness_sun_price
52+
wspd = randomness_wspd
53+
tsun = randomness_sun_price *1.22
54+
energy_price = randomness_sun_price *0.89
55+
56+
pd_list.append([cust_id, kwh_producing, kwh_consuming, temp, wspd, tsun, energy_price])
57+
58+
df_out = pd.DataFrame(pd_list, columns = ["cust_id", "kwh_producing", "kwh_consuming", "temp", "windspeed","sun_light", "energy_price"])
59+
60+
#push random data to stream
61+
for index, row in df_out.iterrows():
62+
row_json = row.to_json(orient='records', lines=True)
63+
producer.send(stream_name, value=row_json)
64+
producer.flush()
65+
print(f"Producing to stream: {row_json}")
66+
sleep(5)
67+
68+
69+
if __name__ == '__main__':
70+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from kafka3 import KafkaConsumer, KafkaProducer
2+
import pandas as pd
3+
from time import sleep
4+
import datetime
5+
import numpy as np
6+
from datetime import datetime, timedelta
7+
import random
8+
import argparse
9+
import uuid
10+
11+
#get arguments
12+
parser = argparse.ArgumentParser()
13+
14+
parser.add_argument("-tenancy_name", "--tenancy_name", help="tenancy_name", required=True)
15+
parser.add_argument("-region", "--region", help="region",required=True)
16+
parser.add_argument("-user_name", "--user_name", help="user_name including OracleIdentityCloudService", required=True)
17+
parser.add_argument("-stream_name", "--stream_name", help="stream_name / topic", required=True)
18+
parser.add_argument("-stream_pool_ocid", "--stream_pool_ocid", help="stream_pool_ocid", required=True)
19+
parser.add_argument("-auth_token", "--auth_token", help="auth_token", required=True)
20+
21+
22+
args = parser.parse_args()
23+
tenancy_name = args.tenancy_name
24+
region = args.region
25+
user_name = args.user_name
26+
stream_name = args.stream_name
27+
stream_pool_ocid = args.stream_pool_ocid
28+
auth_token = args.auth_token
29+
30+
31+
def main():
32+
## create connection
33+
producer = KafkaProducer(bootstrap_servers = f'cell-1.streaming.{region}.oci.oraclecloud.com:9092', linger_ms = 50, batch_size = 2,
34+
security_protocol = 'SASL_SSL', sasl_mechanism = 'PLAIN',
35+
value_serializer = lambda v: v.encode('utf-8'),
36+
sasl_plain_username = f'{tenancy_name}/{user_name}/{stream_pool_ocid}',
37+
sasl_plain_password = auth_token)
38+
39+
40+
df_out = pd.read_csv("./NAME_OF_CSV.csv")
41+
42+
#push random data to stream
43+
for index, row in df_out.iterrows():
44+
row_json = row.to_json(orient='records', lines=True)
45+
producer.send(stream_name, value=row_json)
46+
producer.flush()
47+
print(f"Producing to stream: {row_json}")
48+
sleep(5)
49+
50+
51+
if __name__ == '__main__':
52+
main()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2024 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.

0 commit comments

Comments
 (0)