Skip to content

Commit 5d5edda

Browse files
authored
Merge pull request #258 from kyuengmanKim/refactor/project-structure
Refactor/project structure
2 parents 041f79a + e11a40c commit 5d5edda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1335
-1200
lines changed

python/insight/app/api/anomaly/anomaly.py

Lines changed: 82 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,75 @@
1+
import logging
2+
13
from fastapi import APIRouter, Depends
24
from sqlalchemy.orm import Session
3-
from app.api.anomaly.description.description import (get_options_description, get_settings_description,
4-
post_settings_description, put_settings_description,
5-
delete_settings_description, get_specific_settings_mci_description, get_specific_settings_vm_description,
6-
get_history_mci_description, get_history_vm_description, post_anomaly_detection_description,
7-
get_anomaly_detection_measurements_description,
8-
get_specific_measurement_description)
9-
from app.api.anomaly.response.res import (ResBodyAnomalyDetectionOptions, AnomalyDetectionOptions,
10-
ResBodyAnomalyDetectionSettings)
11-
from app.api.anomaly.utils.utils import AnomalyService
5+
6+
from app.api.anomaly.description.description import (
7+
delete_settings_description,
8+
get_anomaly_detection_measurements_description,
9+
get_history_mci_description,
10+
get_history_vm_description,
11+
get_options_description,
12+
get_settings_description,
13+
get_specific_measurement_description,
14+
get_specific_settings_mci_description,
15+
get_specific_settings_vm_description,
16+
post_anomaly_detection_description,
17+
post_settings_description,
18+
put_settings_description,
19+
)
20+
from app.api.anomaly.request.req import (
21+
AnomalyDetectionTargetRegistration,
22+
AnomalyDetectionTargetUpdate,
23+
GetAnomalyHistoryFilter,
24+
GetHistoryMCIPath,
25+
GetHistoryVMPath,
26+
GetMeasurementPath,
27+
)
28+
from app.api.anomaly.response.res import (
29+
AnomalyDetectionOptions,
30+
ResBodyAnomalyDetectionHistoryResponse,
31+
ResBodyAnomalyDetectionMeasurement,
32+
ResBodyAnomalyDetectionOptions,
33+
ResBodyAnomalyDetectionSettings,
34+
ResBodyAnomalyDetectionSpecificMeasurement,
35+
ResBodyVoid,
36+
)
1237
from app.api.anomaly.utils.history import AnomalyHistoryService
1338
from app.api.anomaly.utils.setting import AnomalySettingsService
14-
from app.api.anomaly.response.res import (ResBodyAnomalyDetectionMeasurement, ResBodyAnomalyDetectionSpecificMeasurement,
15-
ResBodyVoid, ResBodyAnomalyDetectionHistoryResponse)
16-
from app.api.anomaly.request.req import (GetMeasurementPath, AnomalyDetectionTargetRegistration, AnomalyDetectionTargetUpdate,
17-
GetHistoryMCIPath, GetHistoryVMPath, GetAnomalyHistoryFilter)
18-
from config.ConfigManager import ConfigManager
39+
from app.api.anomaly.utils.utils import AnomalyService
1940
from app.core.dependencies.db import get_db
20-
from fastapi.responses import JSONResponse
41+
from config.ConfigManager import ConfigManager
2142

43+
logger = logging.getLogger(__name__)
2244
router = APIRouter()
2345

2446

2547
@router.get(
26-
path='/anomaly-detection/measurement',
27-
description=get_anomaly_detection_measurements_description['api_description'],
28-
responses=get_anomaly_detection_measurements_description['response'],
48+
path="/anomaly-detection/measurement",
49+
description=get_anomaly_detection_measurements_description["api_description"],
50+
responses=get_anomaly_detection_measurements_description["response"],
2951
response_model=ResBodyAnomalyDetectionMeasurement,
30-
operation_id="GetAnomalyMeasurementList"
52+
operation_id="GetAnomalyMeasurementList",
3153
)
32-
async def get_anomaly_detection_measurements(
33-
db: Session = Depends(get_db)
34-
):
54+
async def get_anomaly_detection_measurements(db: Session = Depends(get_db)):
3555
config = ConfigManager()
36-
measurement_field_config = config.get_anomaly_config()['measurement_fields']
56+
measurement_field_config = config.get_anomaly_config()["measurement_fields"]
3757
anomaly_setting_service = AnomalySettingsService(db=db)
3858
result_dict = anomaly_setting_service.map_plugin_info(measurement_field_config)
3959

4060
return ResBodyAnomalyDetectionMeasurement(data=result_dict)
4161

4262

4363
@router.get(
44-
path='/anomaly-detection/measurement/{measurement}',
45-
description=get_specific_measurement_description['api_description'],
46-
responses=get_specific_measurement_description['response'],
64+
path="/anomaly-detection/measurement/{measurement}",
65+
description=get_specific_measurement_description["api_description"],
66+
responses=get_specific_measurement_description["response"],
4767
response_model=ResBodyAnomalyDetectionSpecificMeasurement,
48-
operation_id="GetAnomalyFieldListByMeasurement"
68+
operation_id="GetAnomalyFieldListByMeasurement",
4969
)
50-
async def get_specific_measurement(
51-
path_params: GetMeasurementPath = Depends(),
52-
db: Session = Depends(get_db)
53-
):
70+
async def get_specific_measurement(path_params: GetMeasurementPath = Depends(), db: Session = Depends(get_db)):
5471
config = ConfigManager()
55-
measurement_field_config = config.get_anomaly_config()['measurement_fields']
72+
measurement_field_config = config.get_anomaly_config()["measurement_fields"]
5673
anomaly_setting_service = AnomalySettingsService(db=db)
5774
result_dict = anomaly_setting_service.map_plugin_info(measurement_field_config, target_measurement=path_params)
5875

@@ -61,8 +78,8 @@ async def get_specific_measurement(
6178

6279
@router.get(
6380
path="/anomaly-detection/options",
64-
description=get_options_description['api_description'],
65-
responses=get_options_description['response'],
81+
description=get_options_description["api_description"],
82+
responses=get_options_description["response"],
6683
response_model=ResBodyAnomalyDetectionOptions,
6784
operation_id="GetAnomalyDetectionOptions",
6885
)
@@ -77,99 +94,82 @@ async def get_available_options_for_anomaly_detection():
7794

7895
@router.get(
7996
path="/anomaly-detection/settings",
80-
description=get_settings_description['api_description'],
97+
description=get_settings_description["api_description"],
8198
response_model=ResBodyAnomalyDetectionSettings,
82-
operation_id="GetAllAnomalyDetectionSettings"
99+
operation_id="GetAllAnomalyDetectionSettings",
83100
)
84-
async def get_all_anomaly_detection_settings(
85-
db: Session = Depends(get_db)
86-
):
101+
async def get_all_anomaly_detection_settings(db: Session = Depends(get_db)):
87102
anomaly_setting_service = AnomalySettingsService(db=db)
88103
response = anomaly_setting_service.get_all_settings()
89104
return response
90105

91106

92107
@router.post(
93108
path="/anomaly-detection/settings",
94-
description=post_settings_description['api_description'],
109+
description=post_settings_description["api_description"],
95110
response_model=ResBodyVoid,
96-
operation_id="PostAnomalyDetectionSettings"
111+
operation_id="PostAnomalyDetectionSettings",
97112
)
98-
async def register_anomaly_detection_target(
99-
body: AnomalyDetectionTargetRegistration,
100-
db: Session = Depends(get_db)
101-
):
113+
async def register_anomaly_detection_target(body: AnomalyDetectionTargetRegistration, db: Session = Depends(get_db)):
102114
service = AnomalySettingsService(db=db)
103115
return service.create_setting(setting_data=body.dict())
104116

105117

106118
@router.put(
107119
path="/anomaly-detection/settings/{settingSeq}",
108-
description=put_settings_description['api_description'],
120+
description=put_settings_description["api_description"],
109121
response_model=ResBodyVoid,
110-
operation_id="PutAnomalyDetectionSettings"
122+
operation_id="PutAnomalyDetectionSettings",
111123
)
112124
async def update_anomaly_detection_target(
113-
settingSeq: int,
114-
body: AnomalyDetectionTargetUpdate,
115-
db: Session = Depends(get_db)
125+
settingSeq: int, body: AnomalyDetectionTargetUpdate, db: Session = Depends(get_db)
116126
):
117127
service = AnomalySettingsService(db=db)
118128
return service.update_setting(setting_seq=settingSeq, update_data=body.dict())
119129

120130

121131
@router.delete(
122132
path="/anomaly-detection/settings/{settingSeq}",
123-
description=delete_settings_description['api_description'],
133+
description=delete_settings_description["api_description"],
124134
response_model=ResBodyVoid,
125-
operation_id="DeleteAnomalyDetectionSettings"
135+
operation_id="DeleteAnomalyDetectionSettings",
126136
)
127-
async def delete_anomaly_detection_target(
128-
settingSeq: int,
129-
db: Session = Depends(get_db)
130-
):
137+
async def delete_anomaly_detection_target(settingSeq: int, db: Session = Depends(get_db)):
131138
service = AnomalySettingsService(db=db)
132139
return service.delete_setting(setting_seq=settingSeq)
133140

134141

135142
@router.get(
136143
path="/anomaly-detection/settings/ns/{nsId}/mci/{mciId}",
137-
description=get_specific_settings_mci_description['api_description'],
144+
description=get_specific_settings_mci_description["api_description"],
138145
response_model=ResBodyAnomalyDetectionSettings,
139-
operation_id="GetMCIAnomalyDetectionSettings"
146+
operation_id="GetMCIAnomalyDetectionSettings",
140147
)
141-
async def get_specific_anomaly_detection_mci(
142-
nsId: str,
143-
mciId: str,
144-
db: Session = Depends(get_db)
145-
):
148+
async def get_specific_anomaly_detection_mci(nsId: str, mciId: str, db: Session = Depends(get_db)):
146149
service = AnomalySettingsService(db=db)
147150
return service.get_setting(ns_id=nsId, mci_id=mciId)
148151

152+
149153
@router.get(
150154
path="/anomaly-detection/settings/ns/{nsId}/mci/{mciId}/vm/{vmId}",
151-
description=get_specific_settings_vm_description['api_description'],
155+
description=get_specific_settings_vm_description["api_description"],
152156
response_model=ResBodyAnomalyDetectionSettings,
153-
operation_id="GetVMAnomalyDetectionSettings"
157+
operation_id="GetVMAnomalyDetectionSettings",
154158
)
155-
async def get_specific_anomaly_detection_vm(
156-
nsId: str,
157-
mciId: str,
158-
vmId: str,
159-
db: Session = Depends(get_db)
160-
):
159+
async def get_specific_anomaly_detection_vm(nsId: str, mciId: str, vmId: str, db: Session = Depends(get_db)):
161160
service = AnomalySettingsService(db=db)
162161
return service.get_setting(ns_id=nsId, mci_id=mciId, vm_id=vmId)
163162

163+
164164
@router.get(
165165
path="/anomaly-detection/ns/{nsId}/mci/{mciId}/history",
166-
description=get_history_mci_description['api_description'],
166+
description=get_history_mci_description["api_description"],
167167
response_model=ResBodyAnomalyDetectionHistoryResponse,
168-
operation_id="GetAnomalyDetectionMCIHistory"
168+
operation_id="GetAnomalyDetectionMCIHistory",
169169
)
170170
async def get_anomaly_detection_mci_history(
171-
path_params: GetHistoryMCIPath = Depends(),
172-
query_params: GetAnomalyHistoryFilter = Depends(),
171+
path_params: GetHistoryMCIPath = Depends(),
172+
query_params: GetAnomalyHistoryFilter = Depends(),
173173
):
174174
service = AnomalyHistoryService(path_params=path_params, query_params=query_params)
175175
data = service.get_anomaly_detection_results()
@@ -178,13 +178,13 @@ async def get_anomaly_detection_mci_history(
178178

179179
@router.get(
180180
path="/anomaly-detection/ns/{nsId}/mci/{mciId}/vm/{vmId}/history",
181-
description=get_history_vm_description['api_description'],
181+
description=get_history_vm_description["api_description"],
182182
response_model=ResBodyAnomalyDetectionHistoryResponse,
183-
operation_id="GetAnomalyDetectionVMHistory"
183+
operation_id="GetAnomalyDetectionVMHistory",
184184
)
185185
async def get_anomaly_detection_vm_history(
186-
path_params: GetHistoryVMPath = Depends(),
187-
query_params: GetAnomalyHistoryFilter = Depends(),
186+
path_params: GetHistoryVMPath = Depends(),
187+
query_params: GetAnomalyHistoryFilter = Depends(),
188188
):
189189
service = AnomalyHistoryService(path_params=path_params, query_params=query_params)
190190
data = service.get_anomaly_detection_results()
@@ -193,14 +193,11 @@ async def get_anomaly_detection_vm_history(
193193

194194
@router.post(
195195
path="/anomaly-detection/{settingSeq}",
196-
description=post_anomaly_detection_description['api_description'],
196+
description=post_anomaly_detection_description["api_description"],
197197
response_model=ResBodyVoid,
198-
operation_id="PostAnomalyDetection"
198+
operation_id="PostAnomalyDetection",
199199
)
200-
async def post_anomaly_detection(
201-
settingSeq: int,
202-
db: Session = Depends(get_db)
203-
):
200+
async def post_anomaly_detection(settingSeq: int, db: Session = Depends(get_db)):
204201
service = AnomalyService(db=db, seq=settingSeq)
205202
service.anomaly_detection()
206203

0 commit comments

Comments
 (0)