Skip to content

Commit ce747b7

Browse files
committed
Merge branch 'feature/api/delete_agent' into develop
2 parents 07596ff + 26e847a commit ce747b7

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

platform-api/src/main/java/com/flow/platform/api/controller/AgentController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public List<AgentWithFlow> index() {
8686
* }
8787
*/
8888
@PostMapping(path = "/create")
89-
public Agent create(@RequestBody AgentPath agentPath) {
89+
public AgentWithFlow create(@RequestBody AgentPath agentPath) {
9090
if (agentPath.isEmpty()) {
9191
throw new IllegalParameterException("Zone and agent name are required");
9292
}

platform-api/src/main/java/com/flow/platform/api/service/AgentService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface AgentService {
4242
/**
4343
* Create agent and return token from cc
4444
*/
45-
Agent create(AgentPath agentPath);
45+
AgentWithFlow create(AgentPath agentPath);
4646

4747
/**
4848
* Get agent setting by token from cc

platform-api/src/main/java/com/flow/platform/api/service/AgentServiceImpl.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public Boolean shutdown(String zone, String name, String password) {
135135
}
136136

137137
@Override
138-
public Agent create(AgentPath agentPath) {
138+
public AgentWithFlow create(AgentPath agentPath) {
139139
try {
140140
AgentPathWithWebhook pathWithWebhook = new AgentPathWithWebhook(agentPath, buildAgentWebhook());
141141

@@ -149,7 +149,10 @@ public Agent create(AgentPath agentPath) {
149149
throw new HttpException("Unable to create agent via control center");
150150
}
151151

152-
return Agent.parse(response.getBody(), Agent.class);
152+
Agent agent = Agent.parse(response.getBody(), Agent.class);
153+
154+
AgentWithFlow agentWithFlow = new AgentWithFlow(agent, null);
155+
return agentWithFlow;
153156

154157
} catch (UnsupportedEncodingException | JsonSyntaxException e) {
155158
throw new IllegalStatusException("Unable to create agent", e);
@@ -172,14 +175,15 @@ public AgentSettings settings(String token) {
172175
}
173176

174177
@Override
175-
public void delete(AgentPath agentPath){
178+
public void delete(AgentPath agentPath) {
176179
Agent agent = findAgent(agentPath);
177180

178181
try {
179182
HttpClient.build(platformURL.getAgentDeleteUrl())
180183
.post(agent.toJson())
181184
.withContentType(ContentType.APPLICATION_JSON)
182-
.retry(httpRetryTimes);
185+
.retry(httpRetryTimes)
186+
.bodyAsString();
183187

184188
} catch (UnsupportedEncodingException e) {
185189
throw new IllegalStatusException(e.getMessage());
@@ -199,8 +203,9 @@ private String buildAgentWebhook() {
199203
/**
200204
* find agent
201205
*/
202-
private Agent findAgent(AgentPath agentPath){
203-
String url = platformURL.getAgentFindUrl() + "?" + "zone=" + agentPath.getZone() + "&" + "name=" + agentPath.getName();
206+
private Agent findAgent(AgentPath agentPath) {
207+
String url =
208+
platformURL.getAgentFindUrl() + "?" + "zone=" + agentPath.getZone() + "&" + "name=" + agentPath.getName();
204209
HttpResponse<String> response = HttpClient.build(url)
205210
.get()
206211
.retry(httpRetryTimes)
@@ -212,7 +217,11 @@ private Agent findAgent(AgentPath agentPath){
212217

213218
Agent agent = Agent.parse(response.getBody(), Agent.class);
214219

215-
if (agent.getStatus() == AgentStatus.BUSY){
220+
if (agent == null){
221+
throw new IllegalStatusException("agent is not exist");
222+
}
223+
224+
if (agent.getStatus() == AgentStatus.BUSY) {
216225
throw new IllegalStatusException("agent is busy, please wait");
217226
}
218227

0 commit comments

Comments
 (0)