From 07cfd44193f6ebd552d13325858e8b5b5c131bfb Mon Sep 17 00:00:00 2001 From: Aashish Sharma Date: Mon, 25 Jul 2022 13:48:39 +0530 Subject: [PATCH] mgr/dashboard: Show error on creating service with duplicate service id Fixes: https://tracker.ceph.com/issues/56689 Signed-off-by: Aashish Sharma --- .../mgr/dashboard/controllers/service.py | 27 ++++++++---- .../service-form/service-form.component.html | 6 ++- .../service-form/service-form.component.ts | 30 ++++++++++--- .../app/shared/api/ceph-service.service.ts | 14 ++++++ src/pybind/mgr/dashboard/openapi.yaml | 44 +++++++++++++++++++ .../mgr/dashboard/services/exception.py | 8 ++++ .../mgr/dashboard/services/orchestrator.py | 6 ++- 7 files changed, 117 insertions(+), 18 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/service.py b/src/pybind/mgr/dashboard/controllers/service.py index d3ba882a1d926..afe684302b160 100644 --- a/src/pybind/mgr/dashboard/controllers/service.py +++ b/src/pybind/mgr/dashboard/controllers/service.py @@ -3,12 +3,11 @@ from typing import Dict, List, Optional import cherrypy from ceph.deployment.service_spec import ServiceSpec -from ..exceptions import DashboardException from ..security import Scope -from ..services.exception import handle_orchestrator_error +from ..services.exception import handle_custom_error, handle_orchestrator_error from ..services.orchestrator import OrchClient, OrchFeature from . import APIDoc, APIRouter, CreatePermission, DeletePermission, Endpoint, \ - ReadPermission, RESTController, Task + ReadPermission, RESTController, Task, UpdatePermission from .orchestrator import raise_if_no_orchestrator @@ -50,6 +49,7 @@ class Service(RESTController): return [d.to_dict() for d in daemons] @CreatePermission + @handle_custom_error('service', exceptions=(ValueError, TypeError)) @raise_if_no_orchestrator([OrchFeature.SERVICE_CREATE]) @handle_orchestrator_error('service') @service_task('create', {'service_name': '{service_name}'}) @@ -59,11 +59,22 @@ class Service(RESTController): :param service_name: The service name, e.g. 'alertmanager'. :return: None """ - try: - orch = OrchClient.instance() - orch.services.apply(service_spec) - except (ValueError, TypeError) as e: - raise DashboardException(e, component='service') + + OrchClient.instance().services.apply(service_spec, no_overwrite=True) + + @UpdatePermission + @handle_custom_error('service', exceptions=(ValueError, TypeError)) + @raise_if_no_orchestrator([OrchFeature.SERVICE_CREATE]) + @handle_orchestrator_error('service') + @service_task('edit', {'service_name': '{service_name}'}) + def set(self, service_spec: Dict, service_name: str): # pylint: disable=W0613 + """ + :param service_spec: The service specification as JSON. + :param service_name: The service name, e.g. 'alertmanager'. + :return: None + """ + + OrchClient.instance().services.apply(service_spec, no_overwrite=False) @DeletePermission @raise_if_no_orchestrator([OrchFeature.SERVICE_DELETE]) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html index 35f61965710e4..c9cdc70b0ccec 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html @@ -17,7 +17,8 @@