forked from release-engineering/kojiji
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKojiClient.java
More file actions
1924 lines (1637 loc) · 76.7 KB
/
Copy pathKojiClient.java
File metadata and controls
1924 lines (1637 loc) · 76.7 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.redhat.red.build.koji;
import com.redhat.red.build.koji.config.KojiConfig;
import com.redhat.red.build.koji.kerberos.KrbAuthenticator;
import com.redhat.red.build.koji.model.ImportFile;
import com.redhat.red.build.koji.model.KojiImportResult;
import com.redhat.red.build.koji.model.generated.Model_Registry;
import com.redhat.red.build.koji.model.json.KojiImport;
import com.redhat.red.build.koji.model.json.util.KojiObjectMapper;
import com.redhat.red.build.koji.model.xmlrpc.*;
import com.redhat.red.build.koji.model.xmlrpc.messages.*;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.commonjava.atlas.maven.ident.ref.ProjectRef;
import org.commonjava.atlas.maven.ident.ref.ProjectVersionRef;
import org.commonjava.rwx.api.RWXMapper;
import org.commonjava.rwx.core.Registry;
import org.commonjava.rwx.error.XmlRpcException;
import com.redhat.red.build.koji.http.RequestModifier;
import com.redhat.red.build.koji.http.UrlBuildResult;
import com.redhat.red.build.koji.http.UrlBuilder;
import com.redhat.red.build.koji.http.httpclient4.HC4SyncObjectClient;
import org.commonjava.util.jhttpc.HttpFactory;
import org.commonjava.util.jhttpc.JHttpCException;
import org.commonjava.util.jhttpc.auth.PasswordManager;
import org.commonjava.util.jhttpc.util.UrlUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.security.auth.DestroyFailedException;
import static com.redhat.red.build.koji.KojiClientUtils.buildMultiCallRequest;
import static com.redhat.red.build.koji.KojiClientUtils.parseMultiCallResponse;
import static com.redhat.red.build.koji.model.util.KojiFormats.toKojiName;
import static com.redhat.red.build.koji.model.xmlrpc.KojiBuildTypeInfo.addBuildTypeInfo;
import static com.redhat.red.build.koji.model.xmlrpc.KojiXmlRpcConstants.*;
import static com.redhat.red.build.koji.model.xmlrpc.messages.Constants.GET_BUILD;
import static com.redhat.red.build.koji.model.xmlrpc.messages.MultiCallRequest.getBuilder;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.apache.http.client.utils.HttpClientUtils.closeQuietly;
/**
* Created by jdcasey on 12/3/15.
*/
public class KojiClient
implements Closeable
{
static Logger logger = LoggerFactory.getLogger( KojiClient.class );
private HC4SyncObjectClient xmlrpcClient;
private HttpFactory httpFactory;
private ExecutorService executorService;
private KojiObjectMapper objectMapper;
private KojiConfig config;
public KojiConfig getConfig()
{
return config;
}
private AtomicInteger callCount = new AtomicInteger( 0 );
private static final RequestModifier STANDARD_REQUEST_MODIFIER = ( request ) -> {
request.setHeader( ACCEPT_ENCODING_HEADER, IDENTITY_ENCODING_VALUE );
logger.debug( "\n\n\n\nTarget URI: {}\n\n\n\n", request.getURI() );
};
private static final UrlBuilder NO_OP_URL_BUILDER = ( url ) -> new UrlBuildResult( url );
private UrlBuilder sessionUrlBuilder( KojiSessionInfo session )
{
return sessionUrlBuilder( session, null );
}
private UrlBuilder sessionUrlBuilder( KojiSessionInfo session, Supplier<Map<String, Object>> paramEditor )
{
return ( url ) -> {
if ( session == null )
{
return new UrlBuildResult( url );
}
Map<String, String> params = new HashMap<>();
params.put( SESSION_ID_PARAM, Integer.toString( session.getSessionId() ) );
params.put( SESSION_KEY_PARAM, session.getSessionKey() );
params.put( CALL_NUMBER_PARAM, Integer.toString( callCount.getAndIncrement() ) );
if ( paramEditor != null )
{
Map<String, Object> extraParams = paramEditor.get();
if ( extraParams != null )
{
MalformedURLException error = (MalformedURLException) extraParams.get( EMBEDDED_ERROR_PARAM );
if ( error != null )
{
return new UrlBuildResult( error );
}
else
{
extraParams.forEach( ( key, value ) -> {
params.put( key, String.valueOf( value ) );
} );
}
}
}
String result = UrlUtils.buildUrl( url, params );
logger.debug( "\n\n\n\nBuild URL: {}\n\n\n\n", result );
return new UrlBuildResult( result );
};
}
public KojiClient( KojiConfig config, PasswordManager passwordManager, ExecutorService executorService )
throws KojiClientException
{
this.config = config;
this.httpFactory = new HttpFactory( passwordManager );
this.executorService = executorService;
setup();
}
@Override
public synchronized void close()
{
if ( xmlrpcClient != null )
{
xmlrpcClient.close();
xmlrpcClient = null;
}
}
static
{
Registry.setInstance( new Model_Registry() ); // Register RWX Parser/Renderers
}
public void setup()
throws KojiClientException
{
objectMapper = new KojiObjectMapper();
logger.debug( "SETUP: Starting KojiClient for: {}", config.getKojiURL() );
try
{
xmlrpcClient = new HC4SyncObjectClient( httpFactory, config.getKojiSiteConfig() );
}
catch ( IOException e )
{
xmlrpcClient.close();
xmlrpcClient = null;
throw new KojiClientException( "Cannot construct koji HTTP site-config: " + e.getMessage(), e );
}
try
{
ApiVersionResponse response =
xmlrpcClient.call( new ApiVersionRequest(), ApiVersionResponse.class, NO_OP_URL_BUILDER,
STANDARD_REQUEST_MODIFIER );
if ( 1 != response.getApiVersion() )
{
logger.error( "Cannot connect to koji at: {}. API Version reported is '{}' but this client only supports version 1.", config.getKojiURL(), response.getApiVersion() );
xmlrpcClient.close();
xmlrpcClient = null;
}
}
catch ( XmlRpcException e )
{
logger.error( "Cannot retrieve koji API version from: {}. (Reason: {})", config.getKojiURL(), e.getMessage(), e );
xmlrpcClient.close();
xmlrpcClient = null;
}
}
public int getApiVersion()
throws KojiClientException
{
checkConnection();
try
{
ApiVersionResponse response =
xmlrpcClient.call( new ApiVersionRequest(), ApiVersionResponse.class, NO_OP_URL_BUILDER,
STANDARD_REQUEST_MODIFIER );
return response == null ? -1 : response.getApiVersion();
}
catch ( XmlRpcException e )
{
throw new KojiClientException( "Cannot retrieve koji API version from: {}. (Reason: {})", e,
config.getKojiURL(), e.getMessage() );
}
}
public KojiSessionInfo krbLogin()
throws KojiClientException
{
checkConnection();
try
{
KrbAuthenticator krbAuthenticator = new KrbAuthenticator( config );
String encodedApReq = krbAuthenticator.prepareRequest();
KrbLoginResponse loginResponse =
xmlrpcClient.call( new KrbLoginRequest( encodedApReq ), KrbLoginResponse.class, NO_OP_URL_BUILDER, STANDARD_REQUEST_MODIFIER );
if ( loginResponse == null )
{
throw new KojiClientException( "Failed to get loginResponse" );
}
KojiSessionInfo session = krbAuthenticator.handleResponse( loginResponse );
setLoggedInUser( session );
return session;
}
catch ( XmlRpcException e )
{
throw new KojiClientException( "Failed to login: %s", e, e.getMessage() );
}
}
public KojiSessionInfo login()
throws KojiClientException
{
checkConnection();
if ( config.getKrbService() != null )
{
return krbLogin();
}
try
{
UrlBuilder urlBuilder = ( url ) -> new UrlBuildResult( UrlUtils.buildUrl( url, SSL_LOGIN_PATH ) );
RequestModifier requestModifier =
( request ) -> request.setHeader( ACCEPT_ENCODING_HEADER, IDENTITY_ENCODING_VALUE );
LoginResponse loginResponse =
xmlrpcClient.call( new LoginRequest(), LoginResponse.class, urlBuilder, requestModifier );
if ( loginResponse == null )
{
throw new KojiClientException( "Failed to get loginResponse" );
}
KojiSessionInfo session = loginResponse.getSessionInfo();
setLoggedInUser( session );
return session;
}
catch ( XmlRpcException e )
{
throw new KojiClientException( "Failed to login: %s", e, e.getMessage() );
}
}
public <T> T withKojiSession( KojiCustomCommand<T> command )
throws KojiClientException
{
KojiSessionInfo session = null;
T result = null;
try
{
session = login();
result = command.execute( session );
}
catch ( Exception e )
{
if ( logger.isDebugEnabled() )
{
logger.error( "Koji withSession lambda failed", e );
}
if ( e instanceof KojiClientException )
{
throw e;
}
else
{
throw new KojiClientException( "Koji withSession lambda command failed: %s", e, e.getMessage() );
}
}
finally
{
logout( session );
}
return result;
}
private interface KojiInternalCommand<T>
{
T execute()
throws KojiClientException, XmlRpcException;
}
private <T> T doXmlRpcAndThrow( KojiInternalCommand<T> cmd, String message, Object... params )
throws KojiClientException
{
checkConnection();
try
{
return cmd.execute();
}
catch ( XmlRpcException e )
{
throw new KojiClientException( "%s. Reason: %s", e, String.format( message, params ), e.getMessage() );
}
}
@SuppressWarnings( "unused" )
private <T> T doXmlRpcAndWarn( KojiInternalCommand<T> cmd, String message, Object... params )
{
try
{
checkConnection();
return cmd.execute();
}
catch ( XmlRpcException | KojiClientException e )
{
String formatted = String.format( "%s. Reason: %s", String.format( message, params ), e.getMessage() );
if ( logger.isDebugEnabled() )
{
logger.warn( formatted, e );
}
else
{
logger.warn( formatted );
}
}
return null;
}
public KojiUserInfo getLoggedInUserInfo( String username )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
UserResponse response =
xmlrpcClient.call( new UserRequest( username ), UserResponse.class, NO_OP_URL_BUILDER,
STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getUserInfo();
}, "Failed to retrieve current user info." );
}
public KojiUserInfo getLoggedInUserInfo( KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
UserResponse response =
xmlrpcClient.call( new LoggedInUserRequest(), UserResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getUserInfo();
}, "Failed to retrieve current user info." );
}
public void logout( KojiSessionInfo session )
{
if ( session == null )
{
return;
}
if ( xmlrpcClient != null )
{
try
{
StatusResponse response =
xmlrpcClient.call( new LogoutRequest(), StatusResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
if ( isNotEmpty( response.getError() ) )
{
logger.error( "Failed to logout from Koji: {}", response.getError() );
}
}
catch ( XmlRpcException e )
{
logger.error( "Failed to logout: {}", e.getMessage(), e );
}
}
try
{
session.destroy();
}
catch ( DestroyFailedException e )
{
logger.error( "Failed to destroy session: {}", e.getMessage(), e );
}
}
private void checkConnection()
throws KojiClientException
{
if ( xmlrpcClient == null )
{
throw new KojiClientException( "Connection to koji at %s is closed. Perhaps it failed to initialize?",
config.getKojiURL() );
}
}
public List<KojiPermission> getAllPermissions( KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
AllPermissionsResponse response =
xmlrpcClient.call( new AllPermissionsRequest(), AllPermissionsResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getPermissions();
}, "Failed to retrieve listing of koji permissions." );
}
public boolean hasPermission( String permission, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
ConfirmationResponse response =
xmlrpcClient.call( new CheckPermissionRequest( permission ), ConfirmationResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response == null ? false : response.isSuccess();
}, "Failed to check whether logged-in user has permission: %s", permission );
}
public Integer createTag( CreateTagRequest request, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
IdResponse response = xmlrpcClient.call( request, IdResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getId();
}, "Failed to create tag: %s", request );
}
public KojiTagInfo getTag( int tagId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
TagResponse response =
xmlrpcClient.call( new TagRequest( tagId ), TagResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getTagInfo();
}, "Failed to retrieve tag: %s", tagId );
}
public KojiTagInfo getTag( String tagName, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
TagResponse response =
xmlrpcClient.call( new TagRequest( tagName ), TagResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getTagInfo();
}, "Failed to retrieve tag: %s", tagName );
}
public Integer getTagId( String tagName, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
IdResponse response =
xmlrpcClient.call( new GetTagIdRequest( tagName ), IdResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getId();
}, "Failed to retrieve tag: %s", tagName );
}
public Integer getPackageId( String packageName, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
IdResponse response = xmlrpcClient.call( new GetPackageIdRequest( packageName ), IdResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getId();
}, "Failed to retrieve package: %s", packageName );
}
public Map<String, KojiArchiveType> getArchiveTypeMap( KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( ()->{
GetArchiveTypesResponse response =
xmlrpcClient.call( new GetArchiveTypesRequest(), GetArchiveTypesResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
if ( response == null )
{
return Collections.emptyMap();
}
Map<String, KojiArchiveType> types = new HashMap<>();
response.getArchiveTypes()
.forEach( ( at ) -> at.getExtensions().forEach( ( ext ) -> types.put( ext, at ) ) );
return types;
}, "Failed to retrieve list of acceptable archive types" );
}
public KojiArchiveType getArchiveType( GetArchiveTypeRequest request, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
GetArchiveTypeResponse response =
xmlrpcClient.call( request, GetArchiveTypeResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getArchiveType();
}, "Failed to retrieve archive type for request: %s", request );
}
public KojiImportResult importBuild( KojiImport importInfo, Iterable<Supplier<ImportFile>> importedFileSuppliers,
KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
try
{
String dirname = generateUploadDirname( session, importInfo );
Map<String, KojijiErrorInfo> uploadErrors =
uploadForImport( null, importedFileSuppliers, dirname, session );
if ( !uploadErrors.isEmpty() )
{
return new KojiImportResult( importInfo ).withUploadErrors( uploadErrors );
}
GetBuildResponse response =
xmlrpcClient.call( new CGInlinedImportRequest( importInfo, dirname ), GetBuildResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return new KojiImportResult( importInfo ).withBuildInfo( response.getBuildInfo() );
}
catch ( RuntimeException e )
{
logger.error( "FAIL: {}", e.getMessage(), e );
throw e;
}
}, "Failed to execute content-generator import" );
}
public <T extends KojiQuery> List<Integer> queryCountOnly( String method, List<T> queries, KojiSessionInfo session )
throws KojiClientException
{
Registry registry = Registry.getInstance();
List<Object> args = new ArrayList<>();
for ( T query : queries )
{
if ( query.getQueryOpts() != null )
{
query.getQueryOpts().setCountOnly( true );
}
else
{
query.setQueryOpts( new KojiQueryOpts().withCountOnly( true ) );
}
args.add( registry.renderTo( query ) );
}
MultiCallRequest.Builder builder = getBuilder();
args.forEach( arg -> builder.addCallObj( method, arg ) );
MultiCallResponse multiCallResponse = multiCall( builder.build(), session );
List<KojiMultiCallValueObj> multiCallValueObjs = multiCallResponse.getValueObjs();
List<Integer> ret = new ArrayList<>( multiCallValueObjs.size() );
multiCallValueObjs.forEach( v -> {
Object data = v.getData();
if ( data instanceof Integer )
{
ret.add( (Integer) data );
}
else
{
logger.debug( "Data object is not of type Integer, type: {}, data: {}", data.getClass(), data );
ret.add( null ); // indicate an error
}
} );
return ret;
}
public List<KojiBuildType> listBuildTypes( KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( ()->{
ListBuildTypesResponse response =
xmlrpcClient.call( new ListBuildTypesRequest(), ListBuildTypesResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiBuildType> types = response.getBuildTypes();
return types == null ? Collections.emptyList() : types;
}, "Failed to retrieve list of available build types" );
}
public List<KojiBuildType> listBuildTypes( KojiBuildTypeQuery query, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( ()->{
ListBuildTypesResponse response =
xmlrpcClient.call( new ListBuildTypesRequest( query ), ListBuildTypesResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiBuildType> types = response.getBuildTypes();
return types == null ? Collections.emptyList() : types;
}, "Failed to retrieve list of available build types for build type query: %s", query );
}
public int getBuildTypeCount( KojiBuildTypeQuery query, KojiSessionInfo session )
throws KojiClientException
{
if ( query.getQueryOpts() != null )
{
query.getQueryOpts().setCountOnly( true );
}
else
{
query.setQueryOpts( new KojiQueryOpts().withCountOnly( true ) );
}
return doXmlRpcAndThrow( ()->{
KojiQueryCountOnlyResponse response =
xmlrpcClient.call( new ListBuildTypesRequest( query ), KojiQueryCountOnlyResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response.getCount();
}, "Failed to retrieve count for query: %s", query );
}
public List<KojiBuildInfo> listBuilds( KojiBuildQuery query, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
BuildListResponse response =
xmlrpcClient.call( new ListBuildsRequest( query ),
BuildListResponse.class, sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiBuildInfo> builds = response.getBuilds();
return builds == null ? Collections.emptyList() : builds;
}, "Failed to retrieve list of builds for build query: %s", query );
}
public int getBuildCount( KojiBuildQuery query, KojiSessionInfo session )
throws KojiClientException
{
if ( query.getQueryOpts() != null )
{
query.getQueryOpts().setCountOnly( true );
}
else
{
query.setQueryOpts( new KojiQueryOpts().withCountOnly( true ) );
}
return doXmlRpcAndThrow( ()->{
KojiQueryCountOnlyResponse response =
xmlrpcClient.call( new ListBuildsRequest( query ), KojiQueryCountOnlyResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response.getCount();
}, "Failed to retrieve count for query: %s", query );
}
public List<KojiTagInfo> listAllTags( KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
ListTagsResponse response =
xmlrpcClient.call( new ListTagsRequest(), ListTagsResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiTagInfo> tags = response.getTags();
return tags == null ? Collections.emptyList() : tags;
}, "Failed to retrieve list of all tags" );
}
public int getTagCount( KojiTagQuery query, KojiSessionInfo session )
throws KojiClientException
{
if ( query.getQueryOpts() != null )
{
query.getQueryOpts().setCountOnly( true );
}
else
{
query.setQueryOpts( new KojiQueryOpts().withCountOnly( true ) );
}
return doXmlRpcAndThrow( ()->{
KojiQueryCountOnlyResponse response =
xmlrpcClient.call( new ListTagsRequest( query ), KojiQueryCountOnlyResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response.getCount();
}, "Failed to retrieve count for query: %s", query );
}
public List<KojiTagInfo> listTags( KojiBuildInfo buildInfo, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
ListTagsResponse response =
xmlrpcClient.call( new ListTagsRequest( new KojiTagQuery( buildInfo ) ), ListTagsResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiTagInfo> tags = response.getTags();
return tags == null ? Collections.emptyList() : tags;
}, "Failed to retrieve list of tags for build: %s", buildInfo );
}
public List<KojiTagInfo> listTags( KojiNVR nvr, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
ListTagsResponse response =
xmlrpcClient.call( new ListTagsRequest( new KojiTagQuery( nvr ) ), ListTagsResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiTagInfo> tags = response.getTags();
return tags == null ? Collections.emptyList() : tags;
}, "Failed to retrieve list of tags for build: %s", nvr );
}
public List<KojiTagInfo> listTags( String nvr, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
ListTagsResponse response =
xmlrpcClient.call( new ListTagsRequest( new KojiTagQuery( nvr ) ), ListTagsResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiTagInfo> tags = response.getTags();
return tags == null ? Collections.emptyList() : tags;
}, "Failed to retrieve list of tags for build: %s", nvr );
}
public List<KojiTagInfo> listTags( int buildId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
ListTagsResponse response =
xmlrpcClient.call( new ListTagsRequest( new KojiTagQuery( buildId ) ), ListTagsResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
List<KojiTagInfo> tags = response.getTags();
return tags == null ? Collections.emptyList() : tags;
}, "Failed to retrieve list of tags for build: %s", buildId );
}
/**
* Get tags giving a list of build Ids. This uses multicall and is much faster than calling listTags(id) one by one.
* @return A Map where the build Id is the key and tags as value ( a list ).
*/
public Map<Integer, List<KojiTagInfo>> listTags( List<Integer> buildIds, KojiSessionInfo session )
throws KojiClientException
{
Map<Integer, List<KojiTagInfo>> ret = new HashMap<>();
List<List<KojiTagInfo>> l = new KojiClientHelper( this ).listTagsByIds( buildIds, session );
for ( int i = 0; i < buildIds.size(); i++ )
{
List<KojiTagInfo> list = l.get( i );
if ( list != null )
{
ret.put( buildIds.get( i ), list );
}
}
return ret;
}
public KojiArchiveInfo getArchiveInfo( int archiveId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( ()->{
GetArchiveResponse response = xmlrpcClient.call( new GetArchiveRequest( archiveId ),
GetArchiveResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getArchiveInfo();
}, "Failed to retrieve archive info for: %d", archiveId );
}
public KojiMavenArchiveInfo getMavenArchiveInfo( int archiveId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
GetMavenArchiveResponse response =
xmlrpcClient.call( new GetMavenArchiveRequest( archiveId ), GetMavenArchiveResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getMavenArchiveInfo();
}, "Failed to retrieve maven archive info for: %d", archiveId );
}
public KojiImageArchiveInfo getImageArchiveInfo( int archiveId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
GetImageArchiveResponse response =
xmlrpcClient.call( new GetImageArchiveRequest( archiveId ), GetImageArchiveResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getImageArchiveInfo();
}, "Failed to retrieve image archive info for: %d", archiveId );
}
public KojiWinArchiveInfo getWinArchiveInfo( int archiveId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( () -> {
GetWinArchiveResponse response =
xmlrpcClient.call( new GetWinArchiveRequest( archiveId ), GetWinArchiveResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response == null ? null : response.getWinArchiveInfo();
}, "Failed to retrieve win archive info for: %d", archiveId );
}
public int getArchiveCount( KojiArchiveQuery query, KojiSessionInfo session )
throws KojiClientException
{
if ( query.getQueryOpts() != null )
{
query.getQueryOpts().setCountOnly( true );
}
else
{
query.setQueryOpts( new KojiQueryOpts().withCountOnly( true ) );
}
return doXmlRpcAndThrow( ()->{
KojiQueryCountOnlyResponse response =
xmlrpcClient.call( new ListArchivesRequest( query ), KojiQueryCountOnlyResponse.class,
sessionUrlBuilder( session ), STANDARD_REQUEST_MODIFIER );
return response.getCount();
}, "Failed to retrieve count for query: %s", query );
}
public List<KojiArchiveInfo> listArchives( KojiArchiveQuery query, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( ()->{
ListArchivesResponse response = xmlrpcClient.call( new ListArchivesRequest( query ),
ListArchivesResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
List<KojiArchiveInfo> archives = response.getArchives();
return archives == null ? Collections.emptyList() : archives;
}, "Failed to retrieve list of artifacts matching archive query: %s", query );
}
public void enrichArchiveTypeInfo( List<KojiArchiveInfo> archives, KojiSessionInfo session )
throws KojiClientException
{
Map<KojiBtype, List<KojiArchiveInfo>> buildTypeMap = archives.stream().collect( Collectors.groupingBy( KojiArchiveInfo::getBuildType ) );
final AtomicReference<KojiClientException> err = new AtomicReference<>();
buildTypeMap.forEach( ( buildType, archiveInfos ) -> {
List<Object> archiveIds = archiveInfos.stream().map( KojiArchiveInfo::getArchiveId ).collect( Collectors.toList() );
try
{
switch ( buildType )
{
case maven:
List<KojiMavenArchiveInfo> mavenArchiveInfos =
multiCall( Constants.GET_MAVEN_ARCHIVE, archiveIds, KojiMavenArchiveInfo.class,
session );
for ( int i = 0; i < mavenArchiveInfos.size(); i++ )
{
archiveInfos.get( i ).addMavenArchiveInfo( mavenArchiveInfos.get( i ) );
}
break;
case image:
List<KojiImageArchiveInfo> imageArchiveInfos =
multiCall( Constants.GET_IMAGE_ARCHIVE, archiveIds, KojiImageArchiveInfo.class,
session );
for ( int i = 0; i < imageArchiveInfos.size(); i++ )
{
archiveInfos.get( i ).addImageArchiveInfo( imageArchiveInfos.get( i ) );
}
break;
case win:
List<KojiWinArchiveInfo> winArchiveInfos =
multiCall( Constants.GET_WIN_ARCHIVE, archiveIds, KojiWinArchiveInfo.class,
session );
for ( int i = 0; i < winArchiveInfos.size(); i++ )
{
archiveInfos.get( i ).addWinArchiveInfo( winArchiveInfos.get( i ) );
}
break;
}
}
catch ( KojiClientException e )
{
err.set( e );
}
});
if ( err.get() != null )
{
throw err.get();
}
}
public List<KojiArchiveInfo> listMavenArchivesMatching( String groupId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( ()->{
ListArchivesResponse response = xmlrpcClient.call( new ListArchivesRequest(
new KojiArchiveQuery().withMavenRef(
new KojiMavenRef().withGroupId( groupId ) ) ),
ListArchivesResponse.class, sessionUrlBuilder( session ),
STANDARD_REQUEST_MODIFIER );
List<KojiArchiveInfo> archives = response.getArchives();
return archives == null ? Collections.emptyList() : archives;
}, "Failed to retrieve list of Maven archives matching groupId: %s", groupId );
}
public List<KojiArchiveInfo> listMavenArchivesMatching( String groupId, String artifactId, KojiSessionInfo session )
throws KojiClientException
{
return doXmlRpcAndThrow( ()->{
ListArchivesResponse response = xmlrpcClient.call( new ListArchivesRequest(
new KojiArchiveQuery().withMavenRef(
new KojiMavenRef().withGroupId( groupId ).withArtifactId( artifactId ) ) ),
ListArchivesResponse.class, sessionUrlBuilder( session ),