forked from hpcc-systems/hpcc4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHPCCFileSprayClient.java
2277 lines (2049 loc) · 85.9 KB
/
HPCCFileSprayClient.java
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
package org.hpccsystems.ws.client;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.Stub;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.Copy;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.CopyResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DFUWorkunitsActionResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DeleteDropZoneFilesRequest;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.Despray;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DesprayResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DropZone;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DropZoneFileSearchRequest;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DropZoneFileSearchResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DropZoneFilesRequest;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.DropZoneFilesResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.EspSoapFault;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.EspStringArray;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.FileListRequest;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.FileListResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.FileSprayPingRequest;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.FileSprayStub;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.GetDFUWorkunit;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.GetDFUWorkunitResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.GetDFUWorkunits;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.GetDFUWorkunitsResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.PhysicalFileStruct;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.ProgressRequest;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.ProgressResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.Rename;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.RenameResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.SprayFixed;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.SprayFixedResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.SprayResponse;
import org.hpccsystems.ws.client.gen.axis2.filespray.latest.SprayVariable;
import org.hpccsystems.ws.client.platform.Version;
import org.hpccsystems.ws.client.utils.Connection;
import org.hpccsystems.ws.client.utils.DelimitedDataOptions;
import org.hpccsystems.ws.client.utils.EqualsUtil;
import org.hpccsystems.ws.client.utils.HashCodeUtil;
import org.hpccsystems.ws.client.utils.Sftp;
import org.hpccsystems.ws.client.utils.Utils;
import org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper;
import org.hpccsystems.ws.client.wrappers.EspSoapFaultWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.DFUWorkunitsActionResponseWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.DesprayResponseWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.DesprayWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.DropZoneFilesRequestWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.DropZoneFilesResponseWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.DropZoneWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.EspExceptionWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.GetDFUWorkunitResponseWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.GetDFUWorkunitsResponseWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.PhysicalFileStructWrapper;
import org.hpccsystems.ws.client.wrappers.gen.filespray.ProgressResponseWrapper;
import org.w3c.dom.Document;
import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
/**
* Facilitates File Spray related activities.
* This includes listing available dropzones, uploading files to dropzone, listing files in a dropzone,
* spraying files from dropzone and more.
* This class can be enhanced to provide further service calls.
*/
public class HPCCFileSprayClient extends BaseHPCCWsClient
{
private static final String FILESPRAYWSDLURI = "/FileSpray";
private static final String UPLOADURI = FILESPRAYWSDLURI + "/UploadFile?upload_";
private static final String DOWNLOAD_URI = FILESPRAYWSDLURI + "/DownloadFile?";
private static final long MAX_FILE_WSUPLOAD_SIZE = 2000000000;
private int BUFFER_LENGTH = 1024;
List<DropZoneWrapper> localDropZones = null;
private static Logger log = LogManager.getLogger(HPCCFileSprayClient.class);
private static int DEFAULTSERVICEPORT = -1;
private static String WSDLURL = null;
private static final PhysicalFileStruct[] NO_FILES = {};
public static final Version TrailingSlashPathHPCCVer = new Version(7, 12, 98); //First known HPCC version in which DZ paths are
//expected to contain trailing slash
/**
* Load WSDLURL.
*/
private static void loadWSDLURL()
{
try
{
WSDLURL = getServiceWSDLURL(new FileSprayStub());
DEFAULTSERVICEPORT = (new URL(WSDLURL)).getPort();
}
catch (AxisFault | MalformedURLException e)
{
log.error("Unable to establish original WSDL URL");
log.error(e.getLocalizedMessage());
}
}
/**
* Gets the service URI.
*
* @return the service URI
*/
public String getServiceURI()
{
return FILESPRAYWSDLURI;
}
/**
* Gets the service WSDLURL.
*
* @return the service WSDLURL
*/
public static String getServiceWSDLURL()
{
if (WSDLURL == null)
{
loadWSDLURL();
}
return WSDLURL;
}
/**
* Gets the service WSDL port.
*
* @return the service WSDL port
*/
public static int getServiceWSDLPort()
{
if (WSDLURL == null)
{
loadWSDLURL();
}
return DEFAULTSERVICEPORT;
}
/*
* (non-Javadoc)
*
* @see org.hpccsystems.ws.client.BaseHPCCWsClient#getDefaultStub()
*/
/** {@inheritDoc} */
@Override
public Stub getDefaultStub() throws AxisFault
{
return new FileSprayStub();
}
// from HPCC-Platform/dali/dfu/dfuwu.hpp DFUfileformat
/**
* Used to declare variable data format of file to be sprayed
*
*/
public enum SprayVariableFormat
{
DFUff_fixed (0),
DFUff_csv (1),
DFUff_ascii (1),
DFUff_utf8 (2),
DFUff_utf8n (3),
DFUff_utf16 (4),
DFUff_utf16le (5),
DFUff_utf16be (6),
DFUff_utf32 (7),
DFUff_utf32le (8),
DFUff_utf32be (9),
DFUff_variable (10),
DFUff_recfmvb (11),
DFUff_recfmv (12),
DFUff_variablebigendian (13);
private final int id;
/**
* Instantiates a new spray variable format.
*
* @param id
* the id
*/
SprayVariableFormat(int id)
{
this.id = id;
}
/**
* Gets the value.
*
* @return the value
*/
public int getValue()
{
return id;
}
private final static HashMap<String, SprayVariableFormat> mapVariableSprayFormatNameCode = new HashMap<String, SprayVariableFormat>();
static
{
mapVariableSprayFormatNameCode.put("csv", SprayVariableFormat.DFUff_csv);
mapVariableSprayFormatNameCode.put("ascii", SprayVariableFormat.DFUff_ascii);
mapVariableSprayFormatNameCode.put("utf8", SprayVariableFormat.DFUff_utf8);
mapVariableSprayFormatNameCode.put("utf16", SprayVariableFormat.DFUff_utf16);
mapVariableSprayFormatNameCode.put("utf16le", SprayVariableFormat.DFUff_utf16le);
mapVariableSprayFormatNameCode.put("utf16be", SprayVariableFormat.DFUff_utf16be);
mapVariableSprayFormatNameCode.put("utf32", SprayVariableFormat.DFUff_utf32);
mapVariableSprayFormatNameCode.put("utf32le", SprayVariableFormat.DFUff_utf32le);
mapVariableSprayFormatNameCode.put("utf32be", SprayVariableFormat.DFUff_utf32be);
mapVariableSprayFormatNameCode.put("variable", SprayVariableFormat.DFUff_variable);
mapVariableSprayFormatNameCode.put("recfmvb", SprayVariableFormat.DFUff_recfmvb);
mapVariableSprayFormatNameCode.put("recfmv", SprayVariableFormat.DFUff_recfmv);
mapVariableSprayFormatNameCode.put("variablebigendian", SprayVariableFormat.DFUff_variablebigendian);
mapVariableSprayFormatNameCode.put("fixed", SprayVariableFormat.DFUff_fixed);
}
/**
* Convert var spray format name 2 code.
*
* @param varSprayFormatName
* the var spray format name
* @return the spray variable format
*/
public static SprayVariableFormat convertVarSprayFormatName2Code(String varSprayFormatName)
{
String lower = varSprayFormatName.toLowerCase();
if (mapVariableSprayFormatNameCode.containsKey(lower))
return mapVariableSprayFormatNameCode.get(lower);
else
return SprayVariableFormat.DFUff_fixed;
}
}
/**
* Gets a HPCCFileSprayClient connected to target HPCC Systems
* as described by connection object.
*
* @param connection
* the connection
* @return the HPCC file spray client
*/
public static HPCCFileSprayClient get(Connection connection)
{
return new HPCCFileSprayClient(connection);
}
/**
* Gets a HPCCFileSprayClient connected to target HPCC Systems
* as described by connection parameters.
*
* @param protocol
* the protocol
* @param targetHost
* the target host
* @param targetPort
* the target port
* @param user
* the user
* @param pass
* the pass
* @return the HPCC file spray client
*/
public static HPCCFileSprayClient get(String protocol, String targetHost, String targetPort, String user, String pass)
{
Connection conn = new Connection(protocol, targetHost, targetPort);
conn.setCredentials(user, pass);
return new HPCCFileSprayClient(conn);
}
/**
* Gets a HPCCFileSprayClient connected to target HPCC Systems
* as described by connection parameters.
*
* @param protocol
* the protocol
* @param targetHost
* the target host
* @param targetPort
* the target port
* @param user
* the user
* @param pass
* the pass
* @param timeout
* the timeout
* @return the HPCC file spray client
*/
public static HPCCFileSprayClient get(String protocol, String targetHost, String targetPort, String user, String pass, int timeout)
{
Connection conn = new Connection(protocol, targetHost, targetPort);
conn.setCredentials(user, pass);
conn.setConnectTimeoutMilli(timeout);
conn.setSocketTimeoutMilli(timeout);
return new HPCCFileSprayClient(conn);
}
/**
* Instantiates a new HPCC file spray client.
*
* @param baseConnection
* the base connection
*/
protected HPCCFileSprayClient(Connection baseConnection)
{
initWsFileSprayStub(baseConnection);
}
/**
* Initializes the service's underlying soap proxy. Should only be used by constructors
*
* @param connection
* -- All connection settings included
*/
private void initWsFileSprayStub(Connection connection)
{
initBaseWsClient(connection, true); //Fetch HPCC build Version and conatinerized mode
try
{
stub = setStubOptions(new FileSprayStub(connection.getBaseUrl() + FILESPRAYWSDLURI), connection);
}
catch (AxisFault e)
{
initErrMessage += "\nCould not initialize FileSprayStub - Review all HPCC connection values";
}
}
/**
* Sends ping request to WsFileSpray service on target HPCC Systems instance.
*
* @return true, if successful
* @throws java.lang.Exception
* the exception
*/
public boolean ping() throws Exception
{
verifyStub();
FileSprayPingRequest request = new FileSprayPingRequest();
try
{
((FileSprayStub) stub).ping(request);
}
catch (Exception e)
{
log.error(e.getLocalizedMessage());
return false;
}
return true;
}
/**
* Gets the file upload read buffer length.
*
* @return the upload file buffer length
*/
public int getFileUploadReadBufferLength()
{
return BUFFER_LENGTH;
}
/**
* Set the buffer length used to read files during upload process.
*
* @param length
* the new file upload read buffer length
*/
public void setFileUploadReadBufferLength(int length)
{
BUFFER_LENGTH = length;
}
/**
* Handle spray response.
*
* @param progressResponseWrapper
* the progress response wrapper
* @param maxRetries
* the max retries
* @param milliesBetweenRetry
* the millies between retry
* @return true, if successful
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public boolean handleSprayResponse(ProgressResponseWrapper progressResponseWrapper, int maxRetries, int milliesBetweenRetry)
throws Exception, org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
{
boolean success = false;
ProgressResponseWrapper progressResponse = null;
org.hpccsystems.ws.client.wrappers.gen.filespray.ArrayOfEspExceptionWrapper exceptions = progressResponseWrapper.getExceptions();
if (exceptions != null)
{
for (EspExceptionWrapper espexception : exceptions.getException())
{
log.error("Error spraying file: " + espexception.getSource() + espexception.getMessage());
}
}
else
{
verifyStub();
log.debug("Spray file DWUID: " + progressResponseWrapper.getWuid());
progressResponse = getDfuProgress(progressResponseWrapper.getWuid());
if (progressResponse.getExceptions() != null)
{
log.error("Spray progress status fetch failed.");
}
else
{
String state = progressResponse.getState();
log.debug(progressResponse.getState());
if (!state.equalsIgnoreCase("FAILED"))
{
// this should be in a dedicated thread.
for (int i = 0; i < maxRetries && progressResponse.getPercentDone() < 100
&& !progressResponse.getState().equalsIgnoreCase("FAILED"); i++)
{
log.debug(progressResponse.getProgressMessage());
progressResponse = getDfuProgress(progressResponseWrapper.getWuid());
try
{
if (milliesBetweenRetry <= 0) milliesBetweenRetry = 100;
Thread.sleep(milliesBetweenRetry);
}
catch (InterruptedException e)
{
throw new RuntimeException("Unexpected interrupt", e);
}
}
log.debug(progressResponse.getProgressMessage());
success = true;
}
else
{
log.error("Spray failed.");
}
log.debug("Final summary from server: " + progressResponse.getSummaryMessage());
log.info("Spray attempt completed, verify DWUID: " + progressResponseWrapper.getWuid());
}
}
return success;
}
/**
* Convenience static method, crates new delimited data format descriptor. Parameters not provided are csv defaulted
*
* @param recordTerminator
* the record terminator
* @param fieldDelimiter
* the field delimiter
* @param escapeSequence
* the escape sequence
* @param quote
* the quote
* @return the delimited data options
*/
static public DelimitedDataOptions createDelimitedDataOptionsObject(String recordTerminator, String fieldDelimiter, String escapeSequence,
String quote)
{
return new DelimitedDataOptions(recordTerminator, fieldDelimiter, escapeSequence, quote);
}
/*
* sample response:
* <?xml version="1.0" encoding="utf-8"?>
* <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
* xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
* <soap:Body>
* <DropZoneFilesResponse xmlns="urn:hpccsystems:ws:filespray">
* <NetAddress>10.0.2.15</NetAddress>
* <Path>/var/lib/HPCCSystems/mydropzone/</Path>
* <OS>1</OS>
* <DropZones>
* <DropZone>
* <Name>mydropzone</Name>
* <NetAddress>10.0.2.15</NetAddress>
* <Path>/var/lib/HPCCSystems/mydropzone</Path>
* <Computer>localhost</Computer>
* <Linux>true</Linux>
* </DropZone>
* </DropZones>
* <Files>
* <PhysicalFileStruct>
* <name>eula.1028.txt</name>
* <isDir>0</isDir>
* <filesize>17734</filesize>
* <modifiedtime>2014-04-03 15:17:54</modifiedtime>
* </PhysicalFileStruct>
* </Files>
* </DropZoneFilesResponse>
* </soap:Body>
* </soap:Envelope>
*/
/**
* Fetch local drop zones.
*
* @return List of all local drop zones on target HPCC system
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public List<DropZoneWrapper> fetchLocalDropZones() throws Exception, ArrayOfEspExceptionWrapper
{
return fetchDropZones("localhost");
}
/**
* Fetch drop zones.
*
* @param dropzoneNetAddress
* the dropzone net address
* @return list of all dropzones on dropzoneNetAddress
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public List<DropZoneWrapper> fetchDropZones(@SpanAttribute String dropzoneNetAddress) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
DropZoneFilesRequest request = new DropZoneFilesRequest();
request.setNetAddress(dropzoneNetAddress);
request.setDirectoryOnly(false);
DropZoneFilesResponse resp = null;
try
{
resp = ((FileSprayStub) stub).dropZoneFiles(request);
}
catch (RemoteException e)
{
throw new Exception("HPCCFileSprayClient.fetchDropzones(" + dropzoneNetAddress + ") encountered RemoteException.", e);
}
catch (EspSoapFault e)
{
handleEspSoapFaults(new EspSoapFaultWrapper(e), "Could Not FetchDropzones");
}
if (resp.getExceptions() != null) handleEspExceptions(new ArrayOfEspExceptionWrapper(resp.getExceptions()), "Could Not FetchDropzones");
List<DropZoneWrapper> dropZonesWrapper = null;
if (resp.getDropZones() != null)
{
dropZonesWrapper = new ArrayList<DropZoneWrapper>();
DropZone[] dropZone = resp.getDropZones().getDropZone();
for (int i = 0; i < dropZone.length; i++)
{
DropZoneWrapper currentDZ = new DropZoneWrapper(dropZone[i]);
if(compatibilityCheck(TrailingSlashPathHPCCVer))
{
currentDZ.setPath(Utils.ensureTrailingPathSlash(currentDZ.getPath(), currentDZ.getLinux()));
}
dropZonesWrapper.add(currentDZ);
}
}
return dropZonesWrapper;
}
/**
* Copy file.
*
* @param from
* the from
* @param to
* the to
* @param overwrite
* the overwrite
* @return the string
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public String copyFile(@SpanAttribute String from, @SpanAttribute String to, @SpanAttribute boolean overwrite) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
Copy cp = new Copy();
cp.setSourceLogicalName(from);
cp.setDestLogicalName(to);
cp.setOverwrite(overwrite);
CopyResponse resp = null;
try
{
resp = ((FileSprayStub) stub).copy(cp);
}
catch (RemoteException e)
{
throw new Exception("HPCCFileSprayClient.copy(from,to,overwrite) encountered RemoteException.", e);
}
catch (EspSoapFault e)
{
handleEspSoapFaults(new EspSoapFaultWrapper(e), "Could Not copy file");
}
if (resp != null && resp.getExceptions() != null)
handleEspExceptions(new ArrayOfEspExceptionWrapper(resp.getExceptions()), "Could Not Copy File");
return resp.getResult();
}
/**
* Fetch drop zones.
*
* @param dzname
* the dzname
* @param netaddress
* the netaddress
* @param os
* the os
* @param path
* the path
* @param subfolder
* the subfolder
* @param dironly
* the dironly
* @param watchvisibleonely
* the watchvisibleonely
* @return the drop zone files response wrapper
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public DropZoneFilesResponseWrapper fetchDropZones(@SpanAttribute String dzname, @SpanAttribute String netaddress, @SpanAttribute String os, @SpanAttribute String path, String subfolder, boolean dironly,
boolean watchvisibleonely) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
DropZoneFilesRequest request = new DropZoneFilesRequest();
request.setDirectoryOnly(dironly);
request.setDropZoneName(dzname);
request.setECLWatchVisibleOnly(watchvisibleonely);
request.setNetAddress(netaddress);
request.setOS(os);
request.setPath(path);
request.setSubfolder(subfolder);
return fetchDropZones(new DropZoneFilesRequestWrapper(request));
}
/**
* Fetch drop zones.
*
* @param szrequest
* the szrequest
* @return the drop zone files response wrapper
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public DropZoneFilesResponseWrapper fetchDropZones(DropZoneFilesRequestWrapper szrequest) throws Exception, ArrayOfEspExceptionWrapper
{
if (szrequest == null) throw new Exception("DropZoneFilesRequestWrapper null detected");
verifyStub();
DropZoneFilesResponse resp = null;
try
{
resp = ((FileSprayStub) stub).dropZoneFiles(szrequest.getRaw());
}
catch (RemoteException e)
{
throw new Exception("HPCCFileSprayClient.fetchDropzones(DropZoneFilesRequestWrapper) encountered RemoteException.", e);
}
catch (EspSoapFault e)
{
handleEspSoapFaults(new EspSoapFaultWrapper(e), "Could Not FetchDropzones");
}
if (resp != null && resp.getExceptions() != null)
handleEspExceptions(new ArrayOfEspExceptionWrapper(resp.getExceptions()), "Could Not FetchDropzones");
return new DropZoneFilesResponseWrapper(resp);
}
/**
* Perform HPCC Drop Zone file search.
*
* @param dzname
* - Required, the name of the Drop Zone to query
* @param netaddr
* - Required, the netaddress of the Drop Zone node to query
* @param namefilter
* - Required, the wildcard based name-filter to query
* @return the physical file struct[]
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public PhysicalFileStruct[] dzFileSearch(@SpanAttribute String dzname, @SpanAttribute String netaddr, @SpanAttribute String namefilter) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
DropZoneFileSearchRequest request = new DropZoneFileSearchRequest();
request.setDropZoneName(dzname);
request.setNameFilter(namefilter);
request.setServer(netaddr);
DropZoneFileSearchResponse resp = null;
try
{
resp = ((FileSprayStub) stub).dropZoneFileSearch(request);
}
catch (RemoteException e)
{
throw new Exception("HPCCFileSprayClient.dzFileSearch(...) encountered RemoteException.", e);
}
catch (EspSoapFault e)
{
handleEspSoapFaults(new EspSoapFaultWrapper(e), "Could Not perform DZFileSearch");
}
if (resp.getExceptions() != null) handleEspExceptions(new ArrayOfEspExceptionWrapper(resp.getExceptions()), "Could Not perform DZFileSearch");
if (resp.getFiles() == null) return NO_FILES;
return resp.getFiles().getPhysicalFileStruct();
}
/**
* Fetch list of files on a given dropzone's machine on the target HPCC System
* Note: a logical dropzone can contain multiple machines.
*
* @param netAddress
* - Address of specific dropzone instance
* @param path
* - The dropzone zone path on the local filesystem
* @param OS
* - Optional, OS code
* @return - Array of file descriptors
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public List<PhysicalFileStructWrapper> listFiles(@SpanAttribute String netAddress, @SpanAttribute String path, @SpanAttribute String OS) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
FileListRequest request = new FileListRequest();
request.setNetaddr(netAddress);
request.setPath(path);
if (OS != null) request.setOS(OS);
FileListResponse resp = null;
try
{
resp = ((FileSprayStub) stub).fileList(request);
}
catch (RemoteException e)
{
throw new Exception("HPCCFileSprayClient.listFiles(...) encountered RemoteException.", e);
}
catch (EspSoapFault e)
{
handleEspSoapFaults(new EspSoapFaultWrapper(e), "Could Not ListFiles");
}
if (resp.getExceptions() != null) handleEspExceptions(new ArrayOfEspExceptionWrapper(resp.getExceptions()), "Could Not ListFiles");
List<PhysicalFileStructWrapper> physicalFileStructWrappers = new ArrayList<PhysicalFileStructWrapper>();
if (resp.getFiles() != null)
{
PhysicalFileStruct[] physicalFileStruct = resp.getFiles().getPhysicalFileStruct();
if (physicalFileStruct != null && physicalFileStruct.length > 0)
{
for (int i = 0; i < physicalFileStruct.length; i++)
{
physicalFileStructWrappers.add(new PhysicalFileStructWrapper(physicalFileStruct[i]));
}
}
}
return physicalFileStructWrappers;
}
/**
* * Spray default CSV variable/delimited HPCC file, from the given dropzone address onto given cluster group.
*
* @param dropzoneNetAddress
* the dropzone net address
* @param sourceFileName
* the source file name
* @param targetFileName
* the target file name
* @param prefix
* the prefix
* @param destGroup
* the dest group
* @param overwrite
* the overwrite
* @return - Progress response at time of request
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper sprayVariable(String dropzoneNetAddress, String sourceFileName, String targetFileName, String prefix,
String destGroup, boolean overwrite) throws Exception, ArrayOfEspExceptionWrapper
{
return sprayVariable(dropzoneNetAddress, DelimitedDataOptions.DefaultCSVDataOptions, sourceFileName, targetFileName, prefix, destGroup, overwrite);
}
/**
* Spray variable/delimited HPCC file described in the give delimited data options, from the given dropzone address onto given cluster group.
*
* @param dropzoneNetAddress
* the dropzone net address
* @param options
* the options
* @param sourceFileName
* the source file name
* @param targetFileName
* the target file name
* @param prefix
* the prefix
* @param destGroup
* the dest group
* @param overwrite
* the overwrite
* @return - Progress response at time of request
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper sprayVariable(String dropzoneNetAddress, DelimitedDataOptions options, String sourceFileName,
String targetFileName, String prefix, String destGroup, boolean overwrite) throws Exception, ArrayOfEspExceptionWrapper
{
List<DropZoneWrapper> targetDropZones = fetchDropZones(dropzoneNetAddress);
if (targetDropZones == null)
throw new Exception("Could not fetch target Dropzone");
return sprayVariable(options, targetDropZones.get(0), sourceFileName, targetFileName, prefix, destGroup, overwrite);
}
/**
* Spray variable/delimited HPCC file described in the give delimited data options, from local dropzone onto given cluster group.
*
* @param options
* the options
* @param sourceFileName
* the source file name
* @param targetFileName
* the target file name
* @param prefix
* the prefix
* @param destGroup
* the dest group
* @param overwrite
* the overwrite
* @param format
* - SprayVariableFormat object describing the file format
* @return - Progress response at time of request
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper sprayVariableLocalDropZone(DelimitedDataOptions options, String sourceFileName, String targetFileName,
String prefix, String destGroup, boolean overwrite, SprayVariableFormat format) throws Exception, ArrayOfEspExceptionWrapper
{
if (localDropZones == null)
localDropZones = fetchLocalDropZones();
return sprayVariable(options, localDropZones.get(0), sourceFileName, targetFileName, prefix, destGroup, overwrite, format, null, null, null, null, null, null, null);
}
/**
* Spray variable/delimited HPCC file described in the give delimited data options, from given dropzone onto given cluster group.
*
* @param options
* the options
* @param targetDropZone
* the target drop zone
* @param sourceFileName
* the source file name
* @param targetFileName
* the target file name
* @param prefix
* the prefix
* @param destGroup
* the dest group
* @param overwrite
* the overwrite
* @return - Progress response at time of request
* @throws java.lang.Exception
* the exception
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper sprayVariable(DelimitedDataOptions options, DropZoneWrapper targetDropZone, String sourceFileName,
String targetFileName, String prefix, String destGroup, boolean overwrite) throws Exception, ArrayOfEspExceptionWrapper
{
return sprayVariable(options, targetDropZone, sourceFileName, targetFileName, prefix, destGroup, overwrite, SprayVariableFormat.DFUff_csv,
null, null, null, null, null, null, null);
}
/**
* Spray variable/delimited HPCC file described in the give delimited data options, from given dropzone onto given cluster group.
*
* @param options
* the options
* @param targetDropZone
* the target drop zone
* @param sourceFileName
* the source file name
* @param targetFileName
* the target file name
* @param prefix
* the prefix
* @param destGroup
* the dest group
* @param overwrite
* the overwrite
* @param format
* - SprayVariableFormat object describing the file format
* @param sourceMaxRecordSize
* the source max record size
* @param maxConnections
* the max connections
* @param compress
* the compress
* @param replicate
* the replicate
* @param failIfNoSourceFile
* the fail if no source file
* @param recordStructurePresent
* the record structure present
* @param expireDays
* the expire days
* @return - Progress response at time of request