Improve function_alias integration

When creating webhook using function_alias, the function id
and function version should be updated dynamically. For example,
a function alias A1 is created for function_1 and version 1,
a job is created using A1.

When the user updates A1 with function 1 and version 2, the webhook
should pick up the new version automatically.

For function execution, the execution has to make sure if an alias
is provided then the function id and the function version should be
the same as the one from the alias.

Change-Id: I17320a2a4f55cda8884de928c69ceba366c37f2e
Story: 2006337
Task: 36085
This commit is contained in:
Gaëtan Trellu 2019-08-05 18:49:01 -04:00
parent 32a68d1bfc
commit e28e5a1666
8 changed files with 143 additions and 4 deletions

View File

@ -235,7 +235,7 @@ class Execution(Resource):
id = types.uuid
function_id = wsme.wsattr(types.uuid)
function_version = wsme.wsattr(int, default=0)
function_alias = wtypes.text
function_alias = wsme.wsattr(wtypes.text)
description = wtypes.text
status = wsme.wsattr(wtypes.text, readonly=True)
sync = bool

View File

@ -0,0 +1,31 @@
# Copyright 2019 - Ormuco Inc.
#
# 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.
"""add function_alias field for executions table
Revision ID: 008
Revises: 007
"""
revision = '008'
down_revision = '007'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column(
'executions',
sa.Column('function_alias', sa.String(length=255), nullable=True)
)

View File

@ -0,0 +1,31 @@
# Copyright 2019 - Ormuco Inc.
#
# 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.
"""add function_alias field for webhooks table
Revision ID: 009
Revises: 008
"""
revision = '009'
down_revision = '008'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column(
'webhooks',
sa.Column('function_alias', sa.String(length=255), nullable=True)
)

View File

@ -0,0 +1,34 @@
# Copyright 2019 - Ormuco Inc.
#
# 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.
"""Make function id nullable for executions table
Revision ID: 010
Revises: 009
"""
revision = '010'
down_revision = '009'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column(
'executions',
'function_id',
existing_type=sa.String(length=36),
nullable=True
)

View File

@ -0,0 +1,34 @@
# Copyright 2019 - Ormuco Inc.
#
# 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.
"""Make function id nullable for webhooks table
Revision ID: 011
Revises: 010
"""
revision = '011'
down_revision = '010'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column(
'webhooks',
'function_id',
existing_type=sa.String(length=36),
nullable=True
)

View File

@ -52,7 +52,8 @@ class Function(model_base.QinlingSecureModelBase):
class Execution(model_base.QinlingSecureModelBase):
__tablename__ = 'executions'
function_id = sa.Column(sa.String(36), nullable=False)
function_alias = sa.Column(sa.String(255), nullable=True)
function_id = sa.Column(sa.String(36), nullable=True)
function_version = sa.Column(sa.Integer, default=0)
status = sa.Column(sa.String(32), nullable=False)
sync = sa.Column(sa.BOOLEAN, default=True)
@ -91,9 +92,11 @@ class Job(model_base.QinlingSecureModelBase):
class Webhook(model_base.QinlingSecureModelBase):
__tablename__ = 'webhooks'
function_alias = sa.Column(sa.String(255), nullable=True)
function_id = sa.Column(
sa.String(36),
sa.ForeignKey(Function.id)
sa.ForeignKey(Function.id),
nullable=True
)
function_version = sa.Column(sa.Integer, default=0)
description = sa.Column(sa.String(255))

View File

@ -80,7 +80,7 @@ def create_execution(engine_client, params):
function_id = alias_db.function_id
version = alias_db.function_version
params.update({'function_id': function_id,
'version': version})
'function_version': version})
func_db = db_api.get_function(function_id)
runtime_id = func_db.runtime_id

View File

@ -0,0 +1,6 @@
---
features:
- Support ``--function-alias`` for creating function execution and webhook,
change the positional argument of function to optional ``--function``,
so that the end user can either specify a function alias or a function
identifier to create function execution or webhook.