Skip to content

Commit

Permalink
refactor: change all apis for SpaceONE 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stat-kwon committed Dec 18, 2023
1 parent 7d1a891 commit dccc06c
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 245 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cloudforet/python-core:1.12
FROM cloudforet/python-core:2.0
ARG PACKAGE_VERSION
ENV PYTHONUNBUFFERED 1
ENV SPACEONE_PORT 50051
Expand All @@ -9,7 +9,8 @@ ENV PACKAGE_VERSION=$PACKAGE_VERSION

COPY pkg/pip_requirements.txt pip_requirements.txt

RUN pip install --upgrade -r pip_requirements.txt
RUN pip install --upgrade pip && \
pip install --upgrade -r pip_requirements.txt

COPY src ${SRC_DIR}
WORKDIR ${SRC_DIR}
Expand All @@ -21,4 +22,4 @@ RUN pip install --upgrade spaceone-api
EXPOSE ${SPACEONE_PORT}

ENTRYPOINT ["spaceone"]
CMD ["grpc", "spaceone.dashboard", "-m", "/opt"]
CMD ["run", "grpc-server", "spaceone.dashboard", "-m", "/opt"]
2 changes: 1 addition & 1 deletion deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.3.10
version: 1.3.11

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
13 changes: 1 addition & 12 deletions deploy/helm/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ GLOBAL:
backend: spaceone.core.cache.redis_cache.RedisCache
host: redis
port: 6379
db: 1
encoding: utf-8
socket_timeout: 10
socket_connect_timeout: 10
Expand All @@ -30,14 +29,4 @@ GLOBAL:
handlers:
file:
type: file
filename: /var/log/spaceone/dashboard.log

HANDLERS:
authentication:
- backend: spaceone.core.handler.authentication_handler.AuthenticationGRPCHandler
uri: grpc+ssl://identity.dev.spaceone.dev:443/v1/Domain/get_public_key
authorization:
- backend: spaceone.core.handler.authorization_handler.AuthorizationGRPCHandler
uri: grpc+ssl://identity.dev.spaceone.dev:443/v1/Authorization/verify
mutation:
- backend: spaceone.core.handler.mutation_handler.SpaceONEMutationHandler
filename: /var/log/spaceone/dashboard.log
2 changes: 1 addition & 1 deletion deploy/helm/templates/deployment-rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
resources:
{{- toYaml .Values.resources.rest | nindent 12 }}
{{- end }}
command: ['spaceone', 'rest', 'spaceone.{{ regexReplaceAll "-" .Values.name "_" }}', '-p', '8000']
command: ['spaceone', 'run', 'rest-server', 'spaceone.{{ regexReplaceAll "-" .Values.name "_" }}', '-p', '8000']
ports:
- containerPort: 8000
volumeMounts:
Expand Down
4 changes: 2 additions & 2 deletions deploy/helm/templates/deployment-scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
resources:
{{- toYaml .Values.resources.scheduler | nindent 12 }}
{{- end }}
command: ['spaceone', 'scheduler', 'spaceone.{{ regexReplaceAll "-" .Values.name "_" }}']
command: ['spaceone', 'run', 'scheduler', 'spaceone.{{ regexReplaceAll "-" .Values.name "_" }}']
volumeMounts:
- name: default-conf
mountPath: /opt/spaceone/{{ .Values.name }}/config/config.yaml
Expand Down Expand Up @@ -85,7 +85,7 @@ spec:
{{- end }}

volumes:
- name: default-conf
- name: default-conf
configMap:
name: {{ .Values.name }}-conf
- name: database-conf
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/templates/deployment-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
resources:
{{- toYaml .Values.resources.worker | nindent 12 }}
{{- end }}
command: ['spaceone', 'scheduler', 'spaceone.{{ regexReplaceAll "-" .Values.name "_" }}', '-m', '/opt']
command: ['spaceone', 'run', 'scheduler', 'spaceone.{{ regexReplaceAll "-" .Values.name "_" }}', '-m', '/opt']
volumeMounts:
- name: default-conf
mountPath: /opt/spaceone/{{ .Values.name }}/config/config.yaml
Expand Down
2 changes: 1 addition & 1 deletion src/spaceone/dashboard/conf/global_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# Connector Settings
CONNECTORS = {
"SpaceConnector": {
"backend": "spaceone.core.connector.space_connector.SpaceConnector",
"backend": "spaceone.core.connector.space_connector:SpaceConnector",
"endpoints": {
"identity": "grpc://identity:50051",
},
Expand Down
5 changes: 3 additions & 2 deletions src/spaceone/dashboard/info/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from spaceone.dashboard.info.domain_dashboard_info import *
from spaceone.dashboard.info.domain_dashboard_version_info import *
from spaceone.dashboard.info.dashboard_info import *
from spaceone.dashboard.info.dashboard_version_info import *
from spaceone.dashboard.info.common_info import *
12 changes: 12 additions & 0 deletions src/spaceone/dashboard/info/common_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from google.protobuf.empty_pb2 import Empty
from spaceone.core.pygrpc.message_type import *

__all__ = ["EmptyInfo", "StatisticsInfo"]


def EmptyInfo():
return Empty()


def StatisticsInfo(result):
return change_struct_type(result)
51 changes: 25 additions & 26 deletions src/spaceone/dashboard/info/dashboard_info.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
import functools
from spaceone.api.dashboard.v1 import domain_dashboard_pb2
from spaceone.api.dashboard.v1 import dashboard_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.dashboard.model.dashboard_model import Dashboard

__all__ = ["DomainDashboardInfo", "DomainDashboardsInfo"]
__all__ = ["DashboardInfo", "DashboardsInfo"]


def DomainDashboardInfo(domain_dashboard_vo: Dashboard, minimal=False):
def DashboardInfo(dashboard_vo: Dashboard, minimal=False):
info = {
"domain_dashboard_id": domain_dashboard_vo.domain_dashboard_id,
"name": domain_dashboard_vo.name,
"viewers": domain_dashboard_vo.viewers,
"version": domain_dashboard_vo.version,
"labels": change_list_value_type(domain_dashboard_vo.labels),
"user_id": domain_dashboard_vo.user_id,
"domain_id": domain_dashboard_vo.domain_id,
"dashboard_id": dashboard_vo.dashboard_id,
"name": dashboard_vo.name,
"dashboard_type": dashboard_vo.dashboard_type,
"version": dashboard_vo.version,
"labels": change_list_value_type(dashboard_vo.labels),
"resource_group": dashboard_vo.resource_group,
"user_id": dashboard_vo.user_id,
"project_id": dashboard_vo.project_id,
"workspace_id": dashboard_vo.workspace_id,
"domain_id": dashboard_vo.domain_id,
}

if not minimal:
info.update(
{
"layouts": change_list_value_type(domain_dashboard_vo.layouts)
if domain_dashboard_vo.layouts
"layouts": change_list_value_type(dashboard_vo.layouts)
if dashboard_vo.layouts
else None,
"variables": change_struct_type(domain_dashboard_vo.variables),
"settings": change_struct_type(domain_dashboard_vo.settings),
"variables_schema": change_struct_type(
domain_dashboard_vo.variables_schema
),
"tags": change_struct_type(domain_dashboard_vo.tags),
"created_at": utils.datetime_to_iso8601(domain_dashboard_vo.created_at),
"updated_at": utils.datetime_to_iso8601(domain_dashboard_vo.updated_at),
"variables": change_struct_type(dashboard_vo.variables),
"settings": change_struct_type(dashboard_vo.settings),
"variables_schema": change_struct_type(dashboard_vo.variables_schema),
"tags": change_struct_type(dashboard_vo.tags),
"created_at": utils.datetime_to_iso8601(dashboard_vo.created_at),
"updated_at": utils.datetime_to_iso8601(dashboard_vo.updated_at),
}
)

return domain_dashboard_pb2.DomainDashboardInfo(**info)
return dashboard_pb2.DashboardInfo(**info)


def DomainDashboardsInfo(domain_dashboard_vos, total_count, **kwargs):
return domain_dashboard_pb2.DomainDashboardsInfo(
results=list(
map(functools.partial(DomainDashboardInfo, **kwargs), domain_dashboard_vos)
),
def DashboardsInfo(dashboard_vos, total_count, **kwargs):
return dashboard_pb2.DashboardsInfo(
results=list(map(functools.partial(DashboardInfo, **kwargs), dashboard_vos)),
total_count=total_count,
)
38 changes: 19 additions & 19 deletions src/spaceone/dashboard/info/dashboard_version_info.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import functools
from spaceone.api.dashboard.v1 import domain_dashboard_pb2
from spaceone.api.dashboard.v1 import dashboard_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.dashboard.model import DashboardVersion

__all__ = ["DomainDashboardVersionInfo", "DomainDashboardVersionsInfo"]
__all__ = ["DashboardVersionInfo", "DashboardVersionsInfo"]


def DomainDashboardVersionInfo(
domain_dashboard_version_vo: DashboardVersion, minimal=False, latest_version=None
def DashboardVersionInfo(
dashboard_version_vo: DashboardVersion, minimal=False, latest_version=None
):
info = {
"domain_dashboard_id": domain_dashboard_version_vo.domain_dashboard_id,
"version": domain_dashboard_version_vo.version,
"created_at": utils.datetime_to_iso8601(domain_dashboard_version_vo.created_at),
"domain_id": domain_dashboard_version_vo.domain_id,
"dashboard_id": dashboard_version_vo.dashboard_id,
"version": dashboard_version_vo.version,
"created_at": utils.datetime_to_iso8601(dashboard_version_vo.created_at),
"domain_id": dashboard_version_vo.domain_id,
}

if latest_version:
if latest_version == domain_dashboard_version_vo.version:
if latest_version == dashboard_version_vo.version:
info.update({"latest": True})
else:
info.update({"latest": False})

if not minimal:
info.update(
{
"layouts": change_list_value_type(domain_dashboard_version_vo.layouts)
if domain_dashboard_version_vo.layouts
"layouts": change_list_value_type(dashboard_version_vo.layouts)
if dashboard_version_vo.layouts
else None,
"variables": change_struct_type(domain_dashboard_version_vo.variables),
"settings": change_struct_type(domain_dashboard_version_vo.settings),
"variables": change_struct_type(dashboard_version_vo.variables),
"settings": change_struct_type(dashboard_version_vo.settings),
"variables_schema": change_struct_type(
domain_dashboard_version_vo.variables_schema
dashboard_version_vo.variables_schema
),
}
)

return domain_dashboard_pb2.DomainDashboardVersionInfo(**info)
return dashboard_pb2.DashboardVersionInfo(**info)


def DomainDashboardVersionsInfo(domain_dashboard_version_vos, total_count, **kwargs):
return domain_dashboard_pb2.DomainDashboardVersionsInfo(
def DashboardVersionsInfo(dashboard_version_vos, total_count, **kwargs):
return dashboard_pb2.DashboardVersionsInfo(
results=list(
map(
functools.partial(DomainDashboardVersionInfo, **kwargs),
domain_dashboard_version_vos,
functools.partial(DashboardVersionInfo, **kwargs),
dashboard_version_vos,
)
),
total_count=total_count,
Expand Down
1 change: 1 addition & 0 deletions src/spaceone/dashboard/manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from spaceone.dashboard.manager.dashboard_manager import DashboardManager
from spaceone.dashboard.manager.dashboard_version_manager import DashboardVersionManager
from spaceone.dashboard.manager.identity_manager import IdentityManager
93 changes: 52 additions & 41 deletions src/spaceone/dashboard/manager/dashboard_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,80 @@
class DashboardManager(BaseManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.domain_dashboard_model: Dashboard = self.locator.get_model("Dashboard")
self.dashboard_model: Dashboard = self.locator.get_model("Dashboard")

def create_domain_dashboard(self, params):
def _rollback(domain_dashboard_vo):
def create_dashboard(self, params: dict) -> Dashboard:
def _rollback(vo: Dashboard) -> None:
_LOGGER.info(
f"[create_domain_dashboard._rollback] "
f"Delete domain_dashboard_vo : {domain_dashboard_vo.name} "
f"({domain_dashboard_vo.domain_dashboard_id})"
f"[create_dashboard._rollback] "
f"Delete vo : {vo.name} "
f"({vo.dashboard_id})"
)
domain_dashboard_vo.delete()
vo.delete()

domain_dashboard_vo: Dashboard = self.domain_dashboard_model.create(params)
self.transaction.add_rollback(_rollback, domain_dashboard_vo)
dashboard_vo: Dashboard = self.dashboard_model.create(params)
self.transaction.add_rollback(_rollback, dashboard_vo)

return domain_dashboard_vo
return dashboard_vo

def update_domain_dashboard(self, params):
domain_dashboard_vo: Dashboard = self.get_domain_dashboard(
params["domain_dashboard_id"], params["domain_id"]
def update_dashboard(self, params: dict) -> Dashboard:
dashboard_vo: Dashboard = self.get_dashboard(
params["dashboard_id"], params["domain_id"]
)
return self.update_domain_dashboard_by_vo(params, domain_dashboard_vo)
return self.update_dashboard_by_vo(params, dashboard_vo)

def update_domain_dashboard_by_vo(self, params, domain_dashboard_vo):
def _rollback(old_data):
def update_dashboard_by_vo(
self, params: dict, dashboard_vo: Dashboard
) -> Dashboard:
def _rollback(old_data: dict) -> None:
_LOGGER.info(
f"[update_domain_dashboard_by_vo._rollback] Revert Data : "
f'{old_data["domain_dashboard_id"]}'
f"[update_dashboard_by_vo._rollback] Revert Data : "
f'{old_data["dashboard_id"]}'
)
domain_dashboard_vo.update(old_data)
dashboard_vo.update(old_data)

self.transaction.add_rollback(_rollback, domain_dashboard_vo.to_dict())
return domain_dashboard_vo.update(params)
self.transaction.add_rollback(_rollback, dashboard_vo.to_dict())
return dashboard_vo.update(params)

def delete_domain_dashboard(self, domain_dashboard_id, domain_id):
domain_dashboard_vo: Dashboard = self.get_domain_dashboard(
domain_dashboard_id, domain_id
)
domain_dashboard_vo.delete()
def delete_dashboard(self, dashboard_id: str, domain_id: str) -> None:
dashboard_vo: Dashboard = self.get_dashboard(dashboard_id, domain_id)
dashboard_vo.delete()

def get_domain_dashboard(self, domain_dashboard_id, domain_id, only=None):
return self.domain_dashboard_model.get(
domain_dashboard_id=domain_dashboard_id, domain_id=domain_id, only=only
)
def get_dashboard(
self,
dashboard_id: str,
domain_id: str,
workspace_id: str = None,
user_projects=None,
) -> Dashboard:
conditions = {"dashboard_id": dashboard_id, "domain_id": domain_id}

if workspace_id:
conditions["workspace_id"] = workspace_id

if user_projects:
conditions["project_id"] = user_projects

return self.dashboard_model.get(**conditions)

def list_domain_dashboards(self, query=None):
def list_dashboards(self, query=None):
if query is None:
query = {}
return self.domain_dashboard_model.query(**query)
return self.dashboard_model.query(**query)

def stat_domain_dashboards(self, query):
return self.domain_dashboard_model.stat(**query)
def stat_dashboards(self, query: dict) -> dict:
return self.dashboard_model.stat(**query)

def increase_version(self, domain_dashboard_vo):
def increase_version(self, dashboard_vo: Dashboard) -> None:
def _rollback(vo: Dashboard):
_LOGGER.info(
f"[increase_version._rollback] Decrease Version : "
f"{vo.domain_dashboard_id}"
f"[increase_version._rollback] Decrease Version : " f"{vo.dashboard_id}"
)
vo.decrement("version")

domain_dashboard_vo.increment("version")
self.transaction.add_rollback(_rollback, domain_dashboard_vo)
dashboard_vo.increment("version")
self.transaction.add_rollback(_rollback, dashboard_vo)

@staticmethod
def delete_by_domain_dashboard_vo(domain_dashboard_vo):
domain_dashboard_vo.delete()
def delete_by_dashboard_vo(dashboard_vo: Dashboard) -> None:
dashboard_vo.delete()
Loading

0 comments on commit dccc06c

Please sign in to comment.