1515import com .sap .ai .sdk .core .model .AiDeploymentDeletionResponse ;
1616import com .sap .ai .sdk .core .model .AiDeploymentList ;
1717import com .sap .ai .sdk .core .model .AiDeploymentModificationRequest ;
18- import com .sap .ai .sdk .core .model .AiDeploymentModificationResponse ;
1918import com .sap .ai .sdk .core .model .AiDeploymentTargetStatus ;
2019import com .sap .ai .sdk .core .model .AiParameterArgumentBinding ;
2120import com .sap .ai .sdk .foundationmodels .openai .OpenAiModel ;
@@ -41,7 +40,8 @@ class DeploymentController {
4140 private static final DeploymentApi CLIENT = new DeploymentApi ();
4241 private static final String RESOURCE_GROUP = "default" ;
4342 private final ObjectMapper mapper =
44- new ObjectMapper ().setVisibility (PropertyAccessor .FIELD , JsonAutoDetect .Visibility .ANY )
43+ new ObjectMapper ()
44+ .setVisibility (PropertyAccessor .FIELD , JsonAutoDetect .Visibility .ANY )
4545 .registerModule (new JavaTimeModule ());
4646
4747 /**
@@ -61,6 +61,13 @@ AiDeploymentDeletionResponse createAndDeleteDeploymentByConfigId(final String co
6161 return CLIENT .delete (RESOURCE_GROUP , deployment .getId ());
6262 }
6363
64+ /**
65+ * Create and delete a deployment with the Java specific configuration ID
66+ *
67+ * @param configId The configuration id.
68+ * @param accept The accept header.
69+ * @return a response entity with a string representation of the deployment creation response
70+ */
6471 @ GetMapping ("/by-config/{id}/createDelete" )
6572 ResponseEntity <String > createAndDeleteDeploymentByConfigId (
6673 @ Nonnull @ PathVariable ("id" ) final String configId ,
@@ -72,7 +79,8 @@ ResponseEntity<String> createAndDeleteDeploymentByConfigId(
7279 .contentType (MediaType .APPLICATION_JSON )
7380 .body (mapper .writeValueAsString (response ));
7481 }
75- return ResponseEntity .ok ("Deployment under config with id " + configId + " created and deleted." );
82+ return ResponseEntity .ok (
83+ "Deployment under config with id " + configId + " created and deleted." );
7684 }
7785
7886 /**
@@ -81,26 +89,29 @@ ResponseEntity<String> createAndDeleteDeploymentByConfigId(
8189 * <p>Only RUNNING deployments can be STOPPED
8290 *
8391 * @param configId The configuration id.
84- * @return the deployment modification response
92+ * @param accept The accept header.
93+ * @return a response entity with a string representation of the deployment modification response
8594 */
8695 @ GetMapping ("/by-config/{id}/stop" )
8796 @ Nonnull
8897 ResponseEntity <String > stopByConfigId (
8998 @ Nonnull @ PathVariable ("id" ) final String configId ,
90- @ RequestHeader (value = "accept" , required = false ) final String accept ) throws JsonProcessingException {
99+ @ RequestHeader (value = "accept" , required = false ) final String accept )
100+ throws JsonProcessingException {
91101 final List <AiDeployment > myDeployments = getAllByConfigId (configId );
92102 log .info ("Found {} deployments to STOP" , myDeployments .size ());
93103
94104 // STOP my deployments
95- var stoppedDeployments = myDeployments .stream ()
96- .map (
97- deployment ->
98- CLIENT .modify (
99- RESOURCE_GROUP ,
100- deployment .getId (),
101- AiDeploymentModificationRequest .create ()
102- .targetStatus (AiDeploymentTargetStatus .STOPPED )))
103- .toList ();
105+ final var stoppedDeployments =
106+ myDeployments .stream ()
107+ .map (
108+ deployment ->
109+ CLIENT .modify (
110+ RESOURCE_GROUP ,
111+ deployment .getId (),
112+ AiDeploymentModificationRequest .create ()
113+ .targetStatus (AiDeploymentTargetStatus .STOPPED )))
114+ .toList ();
104115
105116 if ("application/json" .equals (accept )) {
106117 return ResponseEntity .ok ()
@@ -116,19 +127,23 @@ ResponseEntity<String> stopByConfigId(
116127 * <p>Only UNKNOWN and STOPPED deployments can be DELETED
117128 *
118129 * @param configId The configuration id.
119- * @return the deployment deletion response
130+ * @param accept The accept header.
131+ * @return a response entity with a string representation of the deployment deletion response
120132 */
121133 @ GetMapping ("/by-config/{id}/delete" )
122134 @ Nonnull
123135 ResponseEntity <String > deleteByConfigId (
124- @ Nonnull @ PathVariable ("id" ) final String configId , @ RequestHeader (value = "accept" , required = false ) final String accept ) throws JsonProcessingException {
136+ @ Nonnull @ PathVariable ("id" ) final String configId ,
137+ @ RequestHeader (value = "accept" , required = false ) final String accept )
138+ throws JsonProcessingException {
125139 final List <AiDeployment > myDeployments = getAllByConfigId (configId );
126140 log .info ("Found {} deployments to DELETE" , myDeployments .size ());
127141
128142 // DELETE my deployments
129- var responseList = myDeployments .stream ()
130- .map (deployment -> CLIENT .delete (RESOURCE_GROUP , deployment .getId ()))
131- .toList ();
143+ final var responseList =
144+ myDeployments .stream ()
145+ .map (deployment -> CLIENT .delete (RESOURCE_GROUP , deployment .getId ()))
146+ .toList ();
132147 if ("application/json" .equals (accept )) {
133148 return ResponseEntity .ok ()
134149 .contentType (MediaType .APPLICATION_JSON )
@@ -141,7 +156,8 @@ ResponseEntity<String> deleteByConfigId(
141156 * Get all deployments with the Java specific configuration ID
142157 *
143158 * @param configId The configuration id.
144- * @return the Java specific deployments
159+ * @param accept The accept header.
160+ * @return a response entity with a string representation of the Java specific deployments
145161 */
146162 @ GetMapping ("/by-config/{id}/getAll" )
147163 ResponseEntity <String > getAllByConfigId (
@@ -157,16 +173,27 @@ ResponseEntity<String> getAllByConfigId(
157173 return ResponseEntity .ok (buildMessage (deployments ));
158174 }
159175
160- private String buildMessage (List <AiDeployment > deployments ) {
161- var message = new StringBuilder ("The following deployments are available: " );
162- for (var deployment : deployments ) {
176+ /**
177+ * Build a message from the deployment list.
178+ *
179+ * @param deployments The deployment list.
180+ * @return the message
181+ */
182+ private String buildMessage (final List <AiDeployment > deployments ) {
183+ final var message = new StringBuilder ("The following deployments are available: " );
184+ for (final var deployment : deployments ) {
163185 message .append (deployment .getId ()).append (", " );
164186 }
165187 message .setCharAt (message .length () - 2 , '.' );
166188 return message .toString ();
167189 }
168190
169-
191+ /**
192+ * Get all deployments with the Java specific configuration ID
193+ *
194+ * @param configId The configuration id.
195+ * @return the Java specific deployments
196+ */
170197 @ Nonnull
171198 List <AiDeployment > getAllByConfigId (@ Nonnull @ PathVariable ("id" ) final String configId ) {
172199 final AiDeploymentList deploymentList = CLIENT .query (RESOURCE_GROUP );
@@ -179,7 +206,8 @@ List<AiDeployment> getAllByConfigId(@Nonnull @PathVariable("id") final String co
179206 /**
180207 * Get all deployments, including non-Java specific deployments
181208 *
182- * @return the Java specific deployments
209+ * @param accept The accept header.
210+ * @return a response entity with a string representation of the Java specific deployments
183211 */
184212 @ GetMapping ("/getAll" )
185213 @ Nonnull
@@ -195,6 +223,11 @@ ResponseEntity<String> getAll(
195223 return ResponseEntity .ok (buildMessage (deployments .getResources ().stream ().toList ()));
196224 }
197225
226+ /**
227+ * Get all deployments
228+ *
229+ * @return all deployments
230+ */
198231 @ Nullable
199232 AiDeploymentList getAll () {
200233 return CLIENT .query (RESOURCE_GROUP );
0 commit comments