Skip to content

Commit e0d9a8e

Browse files
author
Jongmin Kim
authored
Merge pull request #22 from whdalsrnt/master
fix: fix missing domain_id issue
2 parents 84a9d82 + 5bc7cce commit e0d9a8e

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/spaceone/statistics/manager/identity_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def __init__(self, *args, **kwargs):
1616
def list_domains(self, query: dict) -> dict:
1717
system_token = config.get_global("TOKEN")
1818
return self.identity_conn.dispatch(
19-
"Domain.list", {"query": query}, token=system_token
19+
"Domain.list", {"query": query, "state": "ENABLED"}, token=system_token
2020
)

src/spaceone/statistics/manager/resource_manager.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pandas as pd
33
import numpy as np
44

5+
from spaceone.core.auth.jwt.jwt_util import JWTUtil
56
from spaceone.core.manager import BaseManager
67
from spaceone.core.connector.space_connector import SpaceConnector
78
from spaceone.statistics.error import *
@@ -20,25 +21,25 @@
2021

2122

2223
class ResourceManager(BaseManager):
23-
def stat(self, aggregate: list, page: dict) -> dict:
24-
results = self._execute_aggregate_operations(aggregate)
24+
def stat(self, aggregate: list, page: dict, domain_id: str = None) -> dict:
25+
results = self._execute_aggregate_operations(aggregate, domain_id)
2526
return self._page(page, results)
2627

27-
def _execute_aggregate_operations(self, aggregate):
28+
def _execute_aggregate_operations(self, aggregate: list, domain_id: str = None):
2829
df = None
2930

3031
if "query" not in aggregate[0]:
3132
raise ERROR_REQUIRED_QUERY_OPERATION()
3233

3334
for stage in aggregate:
3435
if "query" in stage:
35-
df = self._query(stage["query"])
36+
df = self._query(stage["query"], domain_id=domain_id)
3637

3738
elif "join" in stage:
38-
df = self._join(stage["join"], df)
39+
df = self._join(stage["join"], df, domain_id)
3940

4041
elif "concat" in stage:
41-
df = self._concat(stage["concat"], df)
42+
df = self._concat(stage["concat"], df, domain_id)
4243

4344
elif "sort" in stage:
4445
df = self._sort(stage["sort"], df)
@@ -122,8 +123,8 @@ def _sort(options, base_df):
122123

123124
return base_df
124125

125-
def _concat(self, options, base_df):
126-
concat_df = self._query(options, operator="join")
126+
def _concat(self, options, base_df, domain_id):
127+
concat_df = self._query(options, operator="join", domain_id=domain_id)
127128

128129
try:
129130
base_df = pd.concat([base_df, concat_df], ignore_index=True)
@@ -152,15 +153,15 @@ def _generate_empty_data(query):
152153

153154
return pd.DataFrame(empty_data)
154155

155-
def _join(self, options, base_df):
156+
def _join(self, options, base_df, domain_id):
156157
if "type" in options and options["type"] not in _JOIN_TYPE_MAP:
157158
raise ERROR_INVALID_PARAMETER_TYPE(
158159
key="aggregate.join.type", type=list(_JOIN_TYPE_MAP.keys())
159160
)
160161

161162
join_keys = options.get("keys")
162163
join_type = options.get("type", "LEFT")
163-
join_df = self._query(options, operator="join")
164+
join_df = self._query(options, operator="join", domain_id=domain_id)
164165

165166
try:
166167
if join_keys:
@@ -185,7 +186,7 @@ def _join(self, options, base_df):
185186

186187
return base_df
187188

188-
def _query(self, options, operator="query"):
189+
def _query(self, options, operator="query", domain_id=None):
189190
resource_type = options.get("resource_type")
190191
query = options.get("query")
191192
extend_data = options.get("extend_data", {})
@@ -199,12 +200,21 @@ def _query(self, options, operator="query"):
199200
service, resource = self._parse_resource_type(resource_type)
200201

201202
try:
203+
token = self.transaction.get_meta("token")
204+
token_type = JWTUtil.get_value_from_token(token, "typ")
205+
202206
connector: SpaceConnector = self.locator.get_connector(
203207
"SpaceConnector", service=service
204208
)
205209

206210
_LOGGER.debug(f"[_query] stat resource: {resource_type}.stat")
207-
response = connector.dispatch(f"{resource}.stat", {"query": query})
211+
if token_type == "SYSTEM_TOKEN":
212+
response = connector.dispatch(
213+
f"{resource}.stat", {"query": query}, x_domain_id=domain_id
214+
)
215+
else:
216+
response = connector.dispatch(f"{resource}.stat", {"query": query})
217+
208218
results = response.get("results", [])
209219

210220
if len(results) > 0 and not isinstance(results[0], dict):

src/spaceone/statistics/service/history_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def create(self, params: dict) -> None:
4646
aggregate = options.get("aggregate", [])
4747
page = params.get("page", {})
4848

49-
response = self.resource_mgr.stat(aggregate, page)
49+
response = self.resource_mgr.stat(aggregate, page, domain_id)
5050

5151
results = response.get("results", [])
5252
self.history_mgr.create_history(schedule_vo, topic, results, domain_id)

0 commit comments

Comments
 (0)