Skip to content

Commit

Permalink
[WebConsoleV2]hot fix namespace when submit job, and set config field…
Browse files Browse the repository at this point in the history
… longer (#697)

* fix db length and namespace

* fix pylint

* fix migration

* fix test

* rename migration file

* resize

* fix

Co-authored-by: xiangyuxuan.prs <[email protected]>
  • Loading branch information
Ssskrilex and xiangyuxuan.prs authored Mar 19, 2021
1 parent 4c902f0 commit 633f6b6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion web_console_v2/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ delete migrations folder first
```
FLASK_APP=command:app flask db init
FLASK_APP=command:app flask flask db migrate -m "Initial migration."
FLASK_APP=command:app flask db migrate -m "Initial migration."
```

## References
Expand Down
2 changes: 1 addition & 1 deletion web_console_v2/api/fedlearner_webconsole/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ def get_namespace(self):
if config is not None:
variables = self.get_config().variables
for variable in variables:
if variable.name == 'NAMESPACE':
if variable.name == 'namespace':
return variable.value
return 'default'
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ def _schedule_job(self, job_id):

k8s_client = get_client()
yaml = generate_job_run_yaml(job)

try:
k8s_client.create_or_replace_custom_object(CrdKind.FLAPP, yaml)
k8s_client.create_or_replace_custom_object(CrdKind.FLAPP, yaml,
job.project.
get_namespace())
except RuntimeError as e:
logging.error('Start job %d has Runtime error msg: %s'
, job_id, e.args)
Expand Down
6 changes: 4 additions & 2 deletions web_console_v2/api/fedlearner_webconsole/workflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class Workflow(db.Model):
uuid = db.Column(db.String(64), comment='uuid')
name = db.Column(db.String(255), comment='name')
project_id = db.Column(db.Integer, comment='project_id')
config = db.Column(db.LargeBinary(), comment='config')
# max store 16777215 bytes (16 MB)
config = db.Column(db.LargeBinary(16777215), comment='config')
comment = db.Column('cmt',
db.String(255),
key='comment',
Expand All @@ -156,7 +157,8 @@ class Workflow(db.Model):
# index in config.job_defs instead of job's id
peer_create_job_flags = db.Column(db.TEXT(),
comment='peer_create_job_flags')
fork_proposal_config = db.Column(db.LargeBinary(),
# max store 16777215 bytes (16 MB)
fork_proposal_config = db.Column(db.LargeBinary(16777215),
comment='fork_proposal_config')

recur_type = db.Column(db.Enum(RecurType, native_enum=False),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class WorkflowTemplate(db.Model):
group_alias = db.Column(db.String(255),
nullable=False,
comment='group_alias')
config = db.Column(db.LargeBinary(), nullable=False, comment='config')
# max store 16777215 bytes (16 MB)
config = db.Column(db.LargeBinary(16777215), nullable=False,
comment='config')
is_left = db.Column(db.Boolean, comment='is_left')

def set_config(self, proto):
Expand Down
6 changes: 4 additions & 2 deletions web_console_v2/api/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
url=url, target_metadata=target_metadata, literal_binds=True,
compare_type=True
)

with context.begin_transaction():
Expand Down Expand Up @@ -77,7 +78,8 @@ def process_revision_directives(context, revision, directives):
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
**current_app.extensions['migrate'].configure_args,
compare_type=True
)

with context.begin_transaction():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""empty message
Revision ID: 80b0a98ce379
Revises: b3512a6ce912
Create Date: 2021-03-18 21:11:17.902485
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '80b0a98ce379'
down_revision = 'b3512a6ce912'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('workflow_v2', 'config', existing_type=sa.LargeBinary(), type_=sa.LargeBinary(16777215))
op.alter_column('template_v2', 'config', existing_type=sa.LargeBinary(), type_=sa.LargeBinary(16777215))
op.alter_column('workflow_v2', 'fork_proposal_config', existing_type=sa.LargeBinary(), type_=sa.LargeBinary(16777215))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('workflow_v2', 'config', existing_type=sa.LargeBinary(16777215), type_=mysql.BLOB)
op.alter_column('template_v2', 'config', existing_type=sa.LargeBinary(16777215), type_=mysql.BLOB)
op.alter_column('workflow_v2', 'fork_proposal_config', existing_type=sa.LargeBinary(16777215), type_=mysql.BLOB)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_get_namespace_from_variables(self):
project.set_config(project_pb2.Project(
variables=[
common_pb2.Variable(
name='NAMESPACE',
name='namespace',
value='haha'
)
]
Expand Down

0 comments on commit 633f6b6

Please sign in to comment.