@@ -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