-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfigurationController.java
More file actions
196 lines (167 loc) · 7.51 KB
/
Copy pathConfigurationController.java
File metadata and controls
196 lines (167 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.dbaagent.controller;
import com.dbaagent.model.ConfigurationRecommendation;
import com.dbaagent.service.DatabaseConfigurationService;
import com.dbaagent.service.security.AccessControlService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* REST controller for database configuration tuning endpoints
*/
@RestController
@RequestMapping("/configuration")
@RequiredArgsConstructor
@Slf4j
@CrossOrigin(origins = "http://localhost:3000")
public class ConfigurationController {
private final DatabaseConfigurationService configurationService;
private final AccessControlService accessControlService;
/**
* Analyze database configuration and generate tuning recommendations
*/
@PostMapping("/analyze/{connectionId}")
public ResponseEntity<AnalyzeResponse> analyzeConfiguration(@PathVariable String connectionId) {
log.info("Analyzing configuration for connection: {}", connectionId);
accessControlService.assertCanManageConnectionContent(connectionId);
try {
List<ConfigurationRecommendation> recommendations = configurationService.analyzeConfiguration(connectionId);
AnalyzeResponse response = new AnalyzeResponse();
response.setSuccess(true);
response.setMessage("Generated " + recommendations.size() + " configuration recommendations");
response.setCount(recommendations.size());
response.setRecommendations(recommendations);
return ResponseEntity.ok(response);
} catch (org.springframework.web.server.ResponseStatusException e) {
throw e;
} catch (Exception e) {
log.error("Error analyzing configuration: {}", e.getMessage(), e);
AnalyzeResponse response = new AnalyzeResponse();
response.setSuccess(false);
response.setMessage("Error analyzing configuration: " + e.getMessage());
response.setCount(0);
return ResponseEntity.internalServerError().body(response);
}
}
/**
* Get all recommendations for a connection (latest analysis)
*/
@GetMapping("/{connectionId}")
public ResponseEntity<List<ConfigurationRecommendation>> getRecommendations(@PathVariable String connectionId) {
log.info("Fetching configuration recommendations for connection: {}", connectionId);
accessControlService.assertCanReadConnectionContent(connectionId);
List<ConfigurationRecommendation> recommendations = configurationService.getRecommendations(connectionId);
return ResponseEntity.ok(recommendations);
}
/**
* Get pending recommendations for a connection
*/
@GetMapping("/pending/{connectionId}")
public ResponseEntity<List<ConfigurationRecommendation>> getPendingRecommendations(@PathVariable String connectionId) {
log.info("Fetching pending configuration recommendations for connection: {}", connectionId);
accessControlService.assertCanReadConnectionContent(connectionId);
List<ConfigurationRecommendation> recommendations = configurationService.getPendingRecommendations(connectionId);
return ResponseEntity.ok(recommendations);
}
/**
* Mark recommendation as applied
*/
@PutMapping("/{id}/apply")
public ResponseEntity<ConfigurationRecommendation> markAsApplied(@PathVariable String id) {
log.info("Marking configuration recommendation as applied: {}", id);
try {
ConfigurationRecommendation existing = configurationService.requireById(id);
accessControlService.assertCanManageConnectionContent(existing.getConnectionId());
ConfigurationRecommendation recommendation = configurationService.markAsApplied(id);
return ResponseEntity.ok(recommendation);
} catch (IllegalArgumentException e) {
log.error("Recommendation not found: {}", id);
return ResponseEntity.notFound().build();
} catch (org.springframework.web.server.ResponseStatusException e) {
throw e;
} catch (Exception e) {
log.error("Error marking recommendation as applied: {}", e.getMessage(), e);
return ResponseEntity.internalServerError().build();
}
}
/**
* Dismiss recommendation
*/
@PutMapping("/{id}/dismiss")
public ResponseEntity<ConfigurationRecommendation> dismissRecommendation(@PathVariable String id) {
log.info("Dismissing configuration recommendation: {}", id);
try {
ConfigurationRecommendation existing = configurationService.requireById(id);
accessControlService.assertCanManageConnectionContent(existing.getConnectionId());
ConfigurationRecommendation recommendation = configurationService.dismissRecommendation(id);
return ResponseEntity.ok(recommendation);
} catch (IllegalArgumentException e) {
log.error("Recommendation not found: {}", id);
return ResponseEntity.notFound().build();
} catch (org.springframework.web.server.ResponseStatusException e) {
throw e;
} catch (Exception e) {
log.error("Error dismissing recommendation: {}", e.getMessage(), e);
return ResponseEntity.internalServerError().build();
}
}
/**
* Delete recommendation
*/
@DeleteMapping("/{id}")
public ResponseEntity<Map<String, String>> deleteRecommendation(@PathVariable String id) {
log.info("Deleting configuration recommendation: {}", id);
try {
ConfigurationRecommendation existing = configurationService.requireById(id);
accessControlService.assertCanManageConnectionContent(existing.getConnectionId());
configurationService.deleteRecommendation(id);
return ResponseEntity.ok(Map.of(
"success", "true",
"message", "Recommendation deleted successfully"
));
} catch (IllegalArgumentException e) {
return ResponseEntity.notFound().build();
} catch (org.springframework.web.server.ResponseStatusException e) {
throw e;
} catch (Exception e) {
log.error("Error deleting recommendation: {}", e.getMessage(), e);
return ResponseEntity.internalServerError().body(Map.of(
"success", "false",
"message", "Error deleting recommendation: " + e.getMessage()
));
}
}
// DTOs
public static class AnalyzeResponse {
private boolean success;
private String message;
private int count;
private List<ConfigurationRecommendation> recommendations;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public List<ConfigurationRecommendation> getRecommendations() {
return recommendations;
}
public void setRecommendations(List<ConfigurationRecommendation> recommendations) {
this.recommendations = recommendations;
}
}
}