WIP: Improve --function-alias support

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 91cb149ea3
7 changed files with 153 additions and 3 deletions

View File

@ -68,6 +68,23 @@ class ExecutionsController(rest.RestController):
LOG.info("Creating %s. [params=%s]", self.type, params)
version = params.get('function_version', 0)
function_alias = params.get('function_alias')
if function_alias:
# Check if the alias exists.
alias_db = db_api.get_function_alias(function_alias)
function_id = alias_db.function_id
version = alias_db.function_version
params.update({'function_id': function_id,
'function_version': version})
else:
# Check the function(version) exists.
db_api.get_function(params['function_id'])
if version > 0:
# Check if the version exists.
db_api.get_function_version(params['function_id'], version)
db_model = executions.create_execution(self.engine_client, params)
return resources.Execution.from_db_obj(db_model)

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))