Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat.] FunctionGraph Test Events #512

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions doc/source/sdk/guides/function_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ It is the minimum unit that can run independently.
A function can be triggered by triggers and automatically schedule
required resources and environments to achieve expected results.

Function Lifecycle
------------------

Create Function
^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -106,6 +108,9 @@ This API is used to update the maximum number of instances of a function.
.. literalinclude:: ../examples/function_graph/update_function_metadata.py
:lines: 16-23

Function Invocation
-------------------

Function Execution Synchronously
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -122,6 +127,9 @@ This API is used to execute a function synchronously.
.. literalinclude:: ../examples/function_graph/async_function_invocation.py
:lines: 16-27

Function Quotas
---------------

Querying Tenant Quotas
^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -130,6 +138,9 @@ This API is used to query tenant quotas.
.. literalinclude:: ../examples/function_graph/list_quotas.py
:lines: 16-24

Dependencies
------------

Querying Dependencies
^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -169,3 +180,46 @@ This API is used to delete a dependency version.

.. literalinclude:: ../examples/function_graph/delete_dependency_version.py
:lines: 16-31

Test Events
-----------

Querying Test Events of a Function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to query the test events of a function.

.. literalinclude:: ../examples/function_graph/list_events.py
:lines: 16-24

Creating a Test Event
^^^^^^^^^^^^^^^^^^^^^

This API is used to query the test events of a function.

.. literalinclude:: ../examples/function_graph/create_event.py
:lines: 16-39

Deleting a Test Event
^^^^^^^^^^^^^^^^^^^^^

This API is used to delete a test event.

.. literalinclude:: ../examples/function_graph/delete_event.py
:lines: 16-40

Obtaining the Details of a Test Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This API is used to query the details of a test event.

.. literalinclude:: ../examples/function_graph/get_event.py
:lines: 16-42

Updating a Test Event
^^^^^^^^^^^^^^^^^^^^^

This API is used to update a test event.

.. literalinclude:: ../examples/function_graph/update_event.py
:lines: 16-45
8 changes: 8 additions & 0 deletions doc/source/sdk/proxies/function_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ Dependencies
:noindex:
:members: dependencies, create_dependency_version, delete_dependency_version,
dependency_versions, get_dependency_version

Events
^^^^^^

.. autoclass:: otcextensions.sdk.function_graph.v2._proxy.Proxy
:noindex:
:members: create_event, delete_event, events,
get_event, update_event
1 change: 1 addition & 0 deletions doc/source/sdk/resources/function_graph/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ FunctionGraph Resources
v2/function_invocation
v2/quota
v2/dependency
v2/event
13 changes: 13 additions & 0 deletions doc/source/sdk/resources/function_graph/v2/event.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.function_graph.v2.event
=========================================

.. automodule:: otcextensions.sdk.function_graph.v2.event

The Event Class
---------------

The ``Event`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.function_graph.v2.event.Event
:members:
39 changes: 39 additions & 0 deletions examples/function_graph/create_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Create new event
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

event_attrs = {
'name': 'event-xx',
'content': 'eyJrIjoidiJ9'
}
func_attrs = {
'func_name': 'test-function',
'package': 'default',
'runtime': 'Python3.9',
'handler': 'index.handler',
'timeout': 30,
'memory_size': 128,
'code_type': 'inline',
}
fg = conn.functiongraph.create_function(**func_attrs)
ev = conn.functiongraph.create_event(
fg, **event_attrs
)
40 changes: 40 additions & 0 deletions examples/function_graph/delete_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Delete event
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

event_attrs = {
'name': 'event-xx',
'content': 'eyJrIjoidiJ9'
}
func_attrs = {
'func_name': 'test-function',
'package': 'default',
'runtime': 'Python3.9',
'handler': 'index.handler',
'timeout': 30,
'memory_size': 128,
'code_type': 'inline',
}
fg = conn.functiongraph.create_function(**func_attrs)
ev = conn.functiongraph.create_event(
fg, **event_attrs
)
conn.functiongraph.delete_event(fg, ev)
42 changes: 42 additions & 0 deletions examples/function_graph/get_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Get event
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

event_attrs = {
'name': 'event-xx',
'content': 'eyJrIjoidiJ9'
}
func_attrs = {
'func_name': 'test-function',
'package': 'default',
'runtime': 'Python3.9',
'handler': 'index.handler',
'timeout': 30,
'memory_size': 128,
'code_type': 'inline',
}
fg = conn.functiongraph.create_function(**func_attrs)
ev = conn.functiongraph.create_event(
fg, **event_attrs
)
e = conn.functiongraph.get_event(
fg, ev)
print(e)
24 changes: 24 additions & 0 deletions examples/function_graph/list_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Get all functions
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

for fg in conn.functiongraph.events(func_urn='urn'):
print(fg)
45 changes: 45 additions & 0 deletions examples/function_graph/update_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Update event
"""
import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)

event_attrs = {
'name': 'event-xx',
'content': 'eyJrIjoidiJ9'
}
func_attrs = {
'func_name': 'test-function',
'package': 'default',
'runtime': 'Python3.9',
'handler': 'index.handler',
'timeout': 30,
'memory_size': 128,
'code_type': 'inline',
}
fg = conn.functiongraph.create_function(**func_attrs)
ev = conn.functiongraph.create_event(
fg, **event_attrs
)
event_attrs = {
'content': 'ewogICAgImJvZHkiOiAiIiwKICAgICJy'
}
updated = conn.functiongraph.update_event(
fg, ev, **event_attrs)
print(updated)
Loading