2424import lombok .extern .log4j .Log4j2 ;
2525import org .openapitools .jackson .nullable .JsonNullableModule ;
2626import org .testng .Assert ;
27-
28-
2927import java .io .File ;
3028import java .io .IOException ;
3129import java .nio .file .Path ;
3634import java .util .Locale ;
3735import java .util .concurrent .ExecutionException ;
3836import java .util .stream .Collectors ;
39-
4037import static java .time .Duration .ofMinutes ;
4138import static lombok .Lombok .sneakyThrow ;
4239
@@ -134,7 +131,8 @@ public String help() {
134131
135132 public KafkaRequest createKafka (String name ) throws CliGenericException {
136133 return retryKafkaCreation (() -> exec ("kafka" , "create" , "--bypass-checks" , "--name" , name , "--provider" , Environment .CLOUD_PROVIDER , "--region" , Environment .DEFAULT_KAFKA_REGION ))
137- .asJson (KafkaRequest .class );
134+ .parseNodeFromProcessOutput ()
135+ .getObjectValue (KafkaRequest ::createFromDiscriminatorValue );
138136 }
139137
140138 public void deleteKafka (String id ) throws CliGenericException {
@@ -143,12 +141,14 @@ public void deleteKafka(String id) throws CliGenericException {
143141
144142 public KafkaRequest describeKafkaById (String id ) throws CliGenericException {
145143 return retry (() -> exec ("kafka" , "describe" , "--id" , id ))
146- .asJson (KafkaRequest .class );
144+ .parseNodeFromProcessOutput ()
145+ .getObjectValue (KafkaRequest ::createFromDiscriminatorValue );
147146 }
148147
149148 public KafkaRequest describeKafkaByName (String name ) throws CliGenericException {
150149 return retry (() -> exec ("kafka" , "describe" , "--name" , name ))
151- .asJson (KafkaRequest .class );
150+ .parseNodeFromProcessOutput ()
151+ .getObjectValue (KafkaRequest ::createFromDiscriminatorValue );
152152 }
153153
154154 public void useKafka (String id ) throws CliGenericException {
@@ -157,25 +157,26 @@ public void useKafka(String id) throws CliGenericException {
157157
158158 public KafkaRequestList listKafka () throws CliGenericException {
159159 return retry (() -> exec ("kafka" , "list" , "-o" , "json" ))
160- .asJson (KafkaRequestList .class );
160+ .parseNodeFromProcessOutput ()
161+ .getObjectValue (KafkaRequestList ::createFromDiscriminatorValue );
161162 }
162163
163164 public KafkaRequestList searchKafkaByName (String name ) throws CliGenericException {
164- var p = retry (() -> exec ("kafka" , "list" , "--search" , name , "-o" , "json" ));
165- if (p .stderrAsString ().contains ("No Kafka instances were found" )) {
166- return new KafkaRequestList ();
167- }
168- return p .asJson (KafkaRequestList .class );
165+ return retry (() -> exec ("kafka" , "list" , "--search" , name , "-o" , "json" ))
166+ .parseNodeFromProcessOutput ()
167+ .getObjectValue (KafkaRequestList ::createFromDiscriminatorValue );
169168 }
170169
171170 public ServiceAccountData describeServiceAccount (String id ) throws CliGenericException {
172171 return retry (() -> exec ("service-account" , "describe" , "--id" , id ))
173- .asJson (ServiceAccountData .class );
172+ .parseNodeFromProcessOutput ()
173+ .getObjectValue (ServiceAccountData ::createFromDiscriminatorValue );
174174 }
175175
176- public ServiceAccountData [] listServiceAccount () throws CliGenericException {
176+ public List < ServiceAccountData > listServiceAccount () throws CliGenericException {
177177 return retry (() -> exec ("service-account" , "list" , "-o" , "json" ))
178- .asJson (ServiceAccountData [].class );
178+ .parseNodeFromProcessOutput ()
179+ .getCollectionOfObjectValues (ServiceAccountData ::createFromDiscriminatorValue );
179180 }
180181
181182 public void deleteServiceAccount (String id ) throws CliGenericException {
@@ -188,12 +189,14 @@ public void createServiceAccount(String name, Path path) throws CliGenericExcept
188189
189190 public Topic createTopic (String topicName ) throws CliGenericException {
190191 return retry (() -> exec ("kafka" , "topic" , "create" , "--name" , topicName , "-o" , "json" ))
191- .asJson (Topic .class );
192+ .parseNodeFromProcessOutput ()
193+ .getObjectValue (Topic ::createFromDiscriminatorValue );
192194 }
193195
194196 public Topic createTopic (String topicName , int partitions ) throws CliGenericException {
195197 return retry (() -> exec ("kafka" , "topic" , "create" , "--name" , topicName , "--partitions" , String .valueOf (partitions ), "-o" , "json" ))
196- .asJson (Topic .class );
198+ .parseNodeFromProcessOutput ()
199+ .getObjectValue (Topic ::createFromDiscriminatorValue );
197200 }
198201
199202 public void deleteTopic (String topicName ) throws CliGenericException {
@@ -202,12 +205,14 @@ public void deleteTopic(String topicName) throws CliGenericException {
202205
203206 public TopicsList listTopics () throws CliGenericException {
204207 return retry (() -> exec ("kafka" , "topic" , "list" , "-o" , "json" ))
205- .asJson (TopicsList .class );
208+ .parseNodeFromProcessOutput ()
209+ .getObjectValue (TopicsList ::createFromDiscriminatorValue );
206210 }
207211
208212 public Topic describeTopic (String topicName ) throws CliGenericException {
209213 return retry (() -> exec ("kafka" , "topic" , "describe" , "--name" , topicName , "-o" , "json" ))
210- .asJson (Topic .class );
214+ .parseNodeFromProcessOutput ()
215+ .getObjectValue (Topic ::createFromDiscriminatorValue );
211216 }
212217
213218 public void updateTopic (String topicName , String retentionTime ) throws CliGenericException {
@@ -216,7 +221,8 @@ public void updateTopic(String topicName, String retentionTime) throws CliGeneri
216221
217222 public ConsumerGroupList listConsumerGroups () throws CliGenericException {
218223 return retry (() -> exec ("kafka" , "consumer-group" , "list" , "-o" , "json" ))
219- .asJson (ConsumerGroupList .class );
224+ .parseNodeFromProcessOutput ()
225+ .getObjectValue (ConsumerGroupList ::createFromDiscriminatorValue );
220226 }
221227
222228 public void deleteConsumerGroup (String id ) throws CliGenericException {
@@ -225,7 +231,8 @@ public void deleteConsumerGroup(String id) throws CliGenericException {
225231
226232 public ConsumerGroup describeConsumerGroup (String name ) throws CliGenericException {
227233 return retry (() -> exec ("kafka" , "consumer-group" , "describe" , "--id" , name , "-o" , "json" ))
228- .asJson (ConsumerGroup .class );
234+ .parseNodeFromProcessOutput ()
235+ .getObjectValue (ConsumerGroup ::createFromDiscriminatorValue );
229236 }
230237
231238 public void connectCluster (String token , String kubeconfig , String serviceType ) throws CliGenericException {
@@ -253,12 +260,14 @@ public void createAcl(ACLEntityType aclEntityType, String entityIdentificator, A
253260 //// kafka acl list
254261 public AclBindingListPage listACLs () throws CliGenericException {
255262 return retry (() -> exec ("kafka" , "acl" , "list" , "-o" , "json" ))
256- .asJson (AclBindingListPage .class );
263+ .parseNodeFromProcessOutput ()
264+ .getObjectValue (AclBindingListPage ::createFromDiscriminatorValue );
257265 }
258266
259267 public AclBindingListPage listACLs (ACLEntityType aclEntityType , String entityIdentificator ) throws CliGenericException {
260268 return retry (() -> exec ("kafka" , "acl" , "list" , aclEntityType .flag , entityIdentificator , "-o" , "json" ))
261- .asJson (AclBindingListPage .class );
269+ .parseNodeFromProcessOutput ()
270+ .getObjectValue (AclBindingListPage ::createFromDiscriminatorValue );
262271 }
263272
264273 //// kafka acl delete
@@ -285,22 +294,26 @@ public void grantAdminAcl(ACLEntityType aclEntityType, String entityIdentificato
285294 */
286295 public Registry createServiceRegistry (String name ) throws CliGenericException {
287296 return retry (() -> exec ("service-registry" , "create" , "--name" , name ))
288- .asJson (Registry .class );
297+ .parseNodeFromProcessOutput ()
298+ .getObjectValue (Registry ::createFromDiscriminatorValue );
289299 }
290300
291301 public Registry describeServiceRegistry (String id ) throws CliGenericException {
292302 return retry (() -> exec ("service-registry" , "describe" , "--id" , id ))
293- .asJson (Registry .class );
303+ .parseNodeFromProcessOutput ()
304+ .getObjectValue (Registry ::createFromDiscriminatorValue );
294305 }
295306
296307 public Registry describeServiceRegistry () throws CliGenericException {
297308 return retry (() -> exec ("service-registry" , "describe" ))
298- .asJson (Registry .class );
309+ .parseNodeFromProcessOutput ()
310+ .getObjectValue (Registry ::createFromDiscriminatorValue );
299311 }
300312
301313 public RegistryList listServiceRegistry () throws CliGenericException {
302314 return retry (() -> exec ("service-registry" , "list" , "-o" , "json" ))
303- .asJson (RegistryList .class );
315+ .parseNodeFromProcessOutput ()
316+ .getObjectValue (RegistryList ::createFromDiscriminatorValue );
304317 }
305318
306319 public void useServiceRegistry (String id ) throws CliGenericException {
0 commit comments