diff --git a/play-with-sld/kubernetes/k8s/sld-api-backend.yml b/play-with-sld/kubernetes/k8s/sld-api-backend.yml index 6f9b7ff3..72d194b5 100644 --- a/play-with-sld/kubernetes/k8s/sld-api-backend.yml +++ b/play-with-sld/kubernetes/k8s/sld-api-backend.yml @@ -17,7 +17,7 @@ spec: subdomain: primary containers: - name: api-backend - image: d10s0vsky/sld-api:v3.6.1 + image: d10s0vsky/sld-api:v3.6.2 imagePullPolicy: Always command: ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"] ports: diff --git a/play-with-sld/kubernetes/k8s/sld-dashboard.yml b/play-with-sld/kubernetes/k8s/sld-dashboard.yml index f2ae4706..8a6fa4f3 100644 --- a/play-with-sld/kubernetes/k8s/sld-dashboard.yml +++ b/play-with-sld/kubernetes/k8s/sld-dashboard.yml @@ -17,7 +17,7 @@ spec: subdomain: primary containers: - name: sld-dashboard - image: d10s0vsky/sld-dashboard:v3.6.1 + image: d10s0vsky/sld-dashboard:v3.6.2 env: - name: PATH value: "/home/sld/.asdf/shims:/home/sld/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" diff --git a/play-with-sld/kubernetes/k8s/sld-worker-default.yml b/play-with-sld/kubernetes/k8s/sld-worker-default.yml index 15538e50..e0c0411f 100644 --- a/play-with-sld/kubernetes/k8s/sld-worker-default.yml +++ b/play-with-sld/kubernetes/k8s/sld-worker-default.yml @@ -17,7 +17,7 @@ spec: subdomain: primary containers: - name: stack-deploy-worker-default - image: d10s0vsky/sld-api:v3.6.1 + image: d10s0vsky/sld-api:v3.6.2 imagePullPolicy: Always env: - name: TF_WARN_OUTPUT_ERRORS diff --git a/play-with-sld/kubernetes/k8s/sld-worker-squad1.yml b/play-with-sld/kubernetes/k8s/sld-worker-squad1.yml index de26ce42..8aa3a4ee 100644 --- a/play-with-sld/kubernetes/k8s/sld-worker-squad1.yml +++ b/play-with-sld/kubernetes/k8s/sld-worker-squad1.yml @@ -17,7 +17,7 @@ spec: subdomain: primary containers: - name: stack-deploy-worker-squad1 - image: d10s0vsky/sld-api:v3.6.1 + image: d10s0vsky/sld-api:v3.6.2 imagePullPolicy: Always env: - name: TF_WARN_OUTPUT_ERRORS diff --git a/play-with-sld/kubernetes/k8s/sld-worker-squad2.yml b/play-with-sld/kubernetes/k8s/sld-worker-squad2.yml index 1e06ddac..72953591 100644 --- a/play-with-sld/kubernetes/k8s/sld-worker-squad2.yml +++ b/play-with-sld/kubernetes/k8s/sld-worker-squad2.yml @@ -17,7 +17,7 @@ spec: subdomain: primary containers: - name: stack-deploy-worker-squad2 - image: d10s0vsky/sld-api:v3.6.1 + image: d10s0vsky/sld-api:v3.6.2 imagePullPolicy: Always env: - name: TF_WARN_OUTPUT_ERRORS diff --git a/sld-api-backend/src/deploy/api/container/deploy/delete.py b/sld-api-backend/src/deploy/api/container/deploy/delete.py index eb3811da..3c15377a 100644 --- a/sld-api-backend/src/deploy/api/container/deploy/delete.py +++ b/sld-api-backend/src/deploy/api/container/deploy/delete.py @@ -53,7 +53,7 @@ async def delete_infra_by_id( try: # Check deploy state if not check_deploy_state(deploy_data.task_id): - raise ValueError("Deploy state running, cannot upgrade") + raise ValueError("The deployment task is locked and cannot be upgraded. If you wish to proceed with the change, you can force the deletion of the task.") # Delete deploy db by id crud_deploys.delete_deploy_by_id(db=db, deploy_id=deploy_id, squad=squad) # push task destroy to queue and return task_id diff --git a/sld-api-backend/src/deploy/api/container/deploy/destroy.py b/sld-api-backend/src/deploy/api/container/deploy/destroy.py index fec8a8dc..1cf6b698 100644 --- a/sld-api-backend/src/deploy/api/container/deploy/destroy.py +++ b/sld-api-backend/src/deploy/api/container/deploy/destroy.py @@ -60,7 +60,7 @@ async def destroy_infra( try: # Check deploy state if not check_deploy_state(deploy_data.task_id): - raise ValueError("Deploy state running, cannot upgrade") + raise ValueError("The deployment task is locked and cannot be upgraded. If you wish to proceed with the change, you can force the deletion of the task.") # push task destroy to queue and return task_id pipeline_destroy = async_destroy(DeployParams( git_repo=git_repo, diff --git a/sld-api-backend/src/deploy/api/container/deploy/update.py b/sld-api-backend/src/deploy/api/container/deploy/update.py index ca07bf89..12866cfe 100644 --- a/sld-api-backend/src/deploy/api/container/deploy/update.py +++ b/sld-api-backend/src/deploy/api/container/deploy/update.py @@ -66,7 +66,7 @@ async def deploy_by_id( check_cron_schedule(deploy_update.destroy_time) # Check deploy state if not check_deploy_state(deploy_data.task_id): - raise ValueError("Deploy state running, cannot upgrade") + raise ValueError("The deployment task is locked and cannot be upgraded. If you wish to proceed with the change, you can force the deletion of the task.") # push task Deploy Update to queue and return task_id pipeline_deploy = async_deploy(DeployParams( git_repo=git_repo, diff --git a/sld-api-backend/src/deploy/api/container/plan/get.py b/sld-api-backend/src/deploy/api/container/plan/get.py index ce9ac6d7..2b5ad68b 100644 --- a/sld-api-backend/src/deploy/api/container/plan/get.py +++ b/sld-api-backend/src/deploy/api/container/plan/get.py @@ -43,7 +43,7 @@ async def get_plan_by_id_deploy( try: # Check deploy state if not check_deploy_state(deploy_data.task_id): - raise ValueError("Deploy state running, cannot upgrade") + raise ValueError("The deployment task is locked and cannot be upgraded. If you wish to proceed with the change, you can force the deletion of the task.") # push task Deploy to queue and return task_id pipeline_plan = async_plan( git_repo, diff --git a/sld-api-backend/src/deploy/api/container/plan/update.py b/sld-api-backend/src/deploy/api/container/plan/update.py index cd72f1a2..5e73d2ee 100644 --- a/sld-api-backend/src/deploy/api/container/plan/update.py +++ b/sld-api-backend/src/deploy/api/container/plan/update.py @@ -58,7 +58,7 @@ async def update_plan_by_id( check_cron_schedule(deploy_update.destroy_time) # Check deploy state if not check_deploy_state(deploy_data.task_id): - raise ValueError("Deploy state running, cannot upgrade") + raise ValueError("The deployment task is locked and cannot be upgraded. If you wish to proceed with the change, you can force the deletion of the task.") # push task Deploy to queue and return task_id pipeline_plan = async_plan(DeployParams( git_repo=git_repo, diff --git a/sld-api-backend/src/tasks/api/container/delete.py b/sld-api-backend/src/tasks/api/container/delete.py index ff34c6fb..75de6c2b 100644 --- a/sld-api-backend/src/tasks/api/container/delete.py +++ b/sld-api-backend/src/tasks/api/container/delete.py @@ -1,13 +1,18 @@ -from config.celery_config import celery_app -from fastapi import Depends +from sqlalchemy.orm import Session +from fastapi import Depends, HTTPException from src.shared.security import deps from src.users.domain.entities import users as schemas_users +from src.tasks.infrastructure.repositories import delete_celery_task_meta_by_task_id async def get_task_by_id( task_id: str, + db: Session = Depends(deps.get_db), current_user: schemas_users.User = Depends(deps.get_current_active_user), ): - result = celery_app.control.revoke(task_id, terminate=True) - return {"result": f"REVOKE {task_id}"} + try: + delete_celery_task_meta_by_task_id(db=db, task_id=task_id) + return {"result": f"REVOKE {task_id}"} + except Exception as err: + raise HTTPException(status_code=500, detail=str(err)) diff --git a/sld-api-backend/src/tasks/infrastructure/models.py b/sld-api-backend/src/tasks/infrastructure/models.py index ad01455a..01ca2d5f 100644 --- a/sld-api-backend/src/tasks/infrastructure/models.py +++ b/sld-api-backend/src/tasks/infrastructure/models.py @@ -1,7 +1,7 @@ import datetime from config.database import Base -from sqlalchemy import Column, DateTime, Integer, String +from sqlalchemy import Column, DateTime, Integer, String, Text, LargeBinary class Tasks(Base): @@ -14,3 +14,19 @@ class Tasks(Base): squad = Column(String(50), nullable=False) action = Column(String(50), nullable=False) created_at = Column(DateTime, default=datetime.datetime.now()) + + +class CeleryTaskMeta(Base): + __tablename__ = "celery_taskmeta" + id = Column(Integer, primary_key=True, autoincrement=True) + task_id = Column(String(155), unique=True) + status = Column(String(50)) + result = Column(LargeBinary) + date_done = Column(DateTime) + traceback = Column(Text) + name = Column(String(155)) + args = Column(LargeBinary) + kwargs = Column(LargeBinary) + worker = Column(String(155)) + retries = Column(Integer) + queue = Column(String(155)) \ No newline at end of file diff --git a/sld-api-backend/src/tasks/infrastructure/repositories.py b/sld-api-backend/src/tasks/infrastructure/repositories.py index 46be1c72..f5486584 100644 --- a/sld-api-backend/src/tasks/infrastructure/repositories.py +++ b/sld-api-backend/src/tasks/infrastructure/repositories.py @@ -70,3 +70,17 @@ def get_tasks_by_deploy_id(db: Session, deploy_id: int): return db.query(models.Tasks).filter(models.Tasks.deploy_id == deploy_id).all() except Exception as err: raise err + + +def delete_celery_task_meta_by_task_id(db: Session, task_id: str): + try: + db_task_meta = db.query(models.CeleryTaskMeta).filter(models.CeleryTaskMeta.task_id == task_id).first() + if db_task_meta is not None: + db.delete(db_task_meta) + db.commit() + return True + else: + return False + except Exception as err: + raise err + diff --git a/sld-dashboard/app/home/routes.py b/sld-dashboard/app/home/routes.py index 5465d75a..b26975cf 100644 --- a/sld-dashboard/app/home/routes.py +++ b/sld-dashboard/app/home/routes.py @@ -270,7 +270,29 @@ def destroy_deploy_console(deploy_id): except Exception: return render_template("page-500.html"), 500 - +@blueprint.route("/task/") +@login_required +def unlock_task(task_id): + try: + token = decrypt(r.get(current_user.id)) + # Check if token no expired + check_unauthorized_token(token) + endpoint = f"tasks/id/{task_id}" + response = request_url( + verb="DELETE", uri=f"{endpoint}", headers={"Authorization": f"Bearer {token}"} + ) + if response.get("status_code") == 200: + flash("Delete task id locked") + else: + flash(response["json"]["detail"], "error") + return redirect( + url_for("home_blueprint.route_template", template="deploys-list") + ) + except TemplateNotFound: + return render_template("page-404.html"), 404 + except TypeError: + return redirect(url_for("base_blueprint.logout")) + @blueprint.route("/deploys/unlock/") @login_required def unlock_deploy(deploy_id): diff --git a/sld-dashboard/app/home/templates/deploys-list.html b/sld-dashboard/app/home/templates/deploys-list.html index 2c4c14c9..5273249a 100644 --- a/sld-dashboard/app/home/templates/deploys-list.html +++ b/sld-dashboard/app/home/templates/deploys-list.html @@ -262,6 +262,16 @@

All Deploys

Delete + + + + Task + {% else %} @@ -321,6 +341,7 @@

All Deploys

> + @@ -365,6 +386,45 @@