Skip to content

Commit f052733

Browse files
committed
Merge remote-tracking branch 'origin/candidate-9.4.x' into candidate-9.6.x
Signed-off-by: Gavin Halliday <[email protected]>
2 parents 9e974c9 + cbbe7b4 commit f052733

File tree

2 files changed

+144
-17
lines changed

2 files changed

+144
-17
lines changed

wsclient/src/main/java/org/hpccsystems/ws/client/HPCCWsFileIOClient.java

+97-4
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,14 @@ public boolean ping() throws Exception
232232
}
233233

234234
/**
235-
* Creates the HPCC file.
235+
* @deprecated Due to change in server behavior
236+
* Use boolean createHPCCFile(String fileName, String targetLandingZone, boolean overwritefile, String lzAddress) instead
237+
* Creates an HPCC file.
236238
*
237239
* @param fileName
238240
* - The target HPCC file name
239241
* @param targetLandingZone
240-
* - The "netaddress" of the target landing, can be localhost, should be fetched from landingzones in filesprayclient
242+
* - The LZ name, no longer the netaddress of the LZ. should be fetched from landingzones in filesprayclient
241243
* @param overwritefile
242244
* - If the file exists, should it be overwritten?
243245
* @return true, if successful
@@ -247,17 +249,47 @@ public boolean ping() throws Exception
247249
* the array of esp exception wrapper
248250
*/
249251
public boolean createHPCCFile(String fileName, String targetLandingZone, boolean overwritefile) throws Exception, ArrayOfEspExceptionWrapper
252+
{
253+
return createHPCCFile(fileName, targetLandingZone, overwritefile, null);
254+
}
255+
256+
/**
257+
* Creates an HPCC file.
258+
*
259+
* @param fileName
260+
* - The target HPCC file name
261+
* @param targetLandingZone
262+
* - The LZ name, no longer the netaddress of the LZ. should be fetched from landingzones in filesprayclient
263+
* @param overwritefile
264+
* - If the file exists, should it be overwritten?
265+
* @param lzAddress
266+
* - The Landing zone address
267+
* @return true, if successful
268+
* @throws java.lang.Exception
269+
* - Caller should handle exception in case of errors
270+
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
271+
* the array of esp exception wrapper
272+
*/
273+
public boolean createHPCCFile(String fileName, String targetLandingZone, boolean overwritefile, String lzAddress) throws Exception, ArrayOfEspExceptionWrapper
250274
{
251275
boolean success = false;
252276
log.debug("Attempting to create HPCC File: " + fileName);
253277

278+
if (targetLandingZone == null || targetLandingZone.isEmpty())
279+
throw new Exception("HPCCWsFileIOClient::createHPCCFile: targetLandingZone required!");
280+
281+
if (fileName == null || fileName.isEmpty())
282+
throw new Exception("HPCCWsFileIOClient::createHPCCFile: fileName required!");
283+
254284
verifyStub(); // Throws exception if stub failed
255285

256286
CreateFileRequest request = new CreateFileRequest();
257287

258288
request.setDestDropZone(targetLandingZone);
259289
request.setDestRelativePath(fileName);
260290
request.setOverwrite(overwritefile);
291+
if (lzAddress != null && !lzAddress.isEmpty())
292+
request.setDestNetAddress(lzAddress);
261293

262294
CreateFileResponse resp = null;
263295
try
@@ -298,13 +330,15 @@ public boolean createHPCCFile(String fileName, String targetLandingZone, boolean
298330
* - At what offset should this be written - Specify 0 if necessary
299331
* @param uploadchunksize
300332
* - Chunksize to upload the data
333+
* @param lzAddress
334+
* - The Landing zone address
301335
* @return true, if successful
302336
* @throws java.lang.Exception
303337
* the exception
304338
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
305339
* the array of esp exception wrapper
306340
*/
307-
public boolean writeHPCCFileData(byte[] data, String fileName, String targetLandingZone, boolean append, long offset, int uploadchunksize)
341+
public boolean writeHPCCFileData(byte[] data, String fileName, String targetLandingZone, boolean append, long offset, int uploadchunksize, String lzAddress)
308342
throws Exception, ArrayOfEspExceptionWrapper
309343
{
310344
boolean success = true;
@@ -318,6 +352,8 @@ public boolean writeHPCCFileData(byte[] data, String fileName, String targetLand
318352
request.setDestDropZone(targetLandingZone);
319353
request.setDestRelativePath(fileName);
320354
request.setOffset(offset);
355+
if (lzAddress != null && !lzAddress.isEmpty())
356+
request.setDestNetAddress(lzAddress);
321357

322358
int dataindex = 0;
323359
int limit = uploadchunksize <= 0 ? defaultUploadChunkSize : uploadchunksize;
@@ -368,6 +404,35 @@ public boolean writeHPCCFileData(byte[] data, String fileName, String targetLand
368404
return success;
369405
}
370406

407+
/**
408+
* @deprecated Due to change in server behavior
409+
* Use boolean writeHPCCFileData(byte[] data, String fileName, String targetLandingZone, boolean append, long offset, int uploadchunksize, String lzAddress) instead
410+
* Write HPCC file data.
411+
*
412+
* @param data
413+
* - The data to write
414+
* @param fileName
415+
* - The target HPCC file to write to
416+
* @param targetLandingZone
417+
* - The "netaddress" of the target landing, can be localhost, should be fetched from landingzones in filesprayclient
418+
* @param append
419+
* - Should this data be appended?
420+
* @param offset
421+
* - At what offset should this be written - Specify 0 if necessary
422+
* @param uploadchunksize
423+
* - Chunksize to upload the data
424+
* @return true, if successful
425+
* @throws java.lang.Exception
426+
* the exception
427+
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
428+
* the array of esp exception wrapper
429+
*/
430+
public boolean writeHPCCFileData(byte[] data, String fileName, String targetLandingZone, boolean append, long offset, int uploadchunksize)
431+
throws Exception, ArrayOfEspExceptionWrapper
432+
{
433+
return writeHPCCFileData(data, fileName, targetLandingZone, append, offset, uploadchunksize, null);
434+
}
435+
371436
/**
372437
* Read file data.
373438
*
@@ -379,19 +444,23 @@ public boolean writeHPCCFileData(byte[] data, String fileName, String targetLand
379444
* the datasize
380445
* @param offset
381446
* the offset
447+
* @param dropzoneAddress
448+
* the dropzone address (not needed in containerized mode)
382449
* @return the string
383450
* @throws java.lang.Exception
384451
* the exception
385452
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
386453
* the array of esp exception wrapper
387454
*/
388-
public String readFileData(String dropzone, String fileName, long datasize, long offset) throws Exception, ArrayOfEspExceptionWrapper
455+
public String readFileData(String dropzone, String fileName, long datasize, long offset, String dropzoneAddress) throws Exception, ArrayOfEspExceptionWrapper
389456
{
390457
ReadFileDataRequest readFileDataRequest = new ReadFileDataRequest();
391458
readFileDataRequest.setDestDropZone(dropzone);
392459
readFileDataRequest.setDestRelativePath(fileName);
393460
readFileDataRequest.setDataSize(datasize);
394461
readFileDataRequest.setOffset(offset);
462+
if (dropzoneAddress != null && !dropzoneAddress.isEmpty())
463+
readFileDataRequest.setDestNetAddress(dropzoneAddress);
395464

396465
ReadFileDataResponse resp = null;
397466
try
@@ -426,4 +495,28 @@ public String readFileData(String dropzone, String fileName, long datasize, long
426495

427496
return data;
428497
}
498+
499+
/**
500+
* @deprecated Due to change in server behavior
501+
* Use String readFileData(String dropzone, String fileName, long datasize, long offset, String dropzoneAddress) instead
502+
* Read file data.
503+
*
504+
* @param dropzone
505+
* the dropzone
506+
* @param fileName
507+
* the file name
508+
* @param datasize
509+
* the datasize
510+
* @param offset
511+
* the offset
512+
* @return the string
513+
* @throws java.lang.Exception
514+
* the exception
515+
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
516+
* the array of esp exception wrapper
517+
*/
518+
public String readFileData(String dropzone, String fileName, long datasize, long offset) throws Exception, ArrayOfEspExceptionWrapper
519+
{
520+
return readFileData(dropzone, fileName, datasize, offset, null);
521+
}
429522
}

wsclient/src/test/java/org/hpccsystems/ws/client/WSFileIOClientTest.java

+47-13
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,24 @@ HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
4343
public class WSFileIOClientTest extends BaseRemoteTest
4444
{
4545
private final static HPCCWsFileIOClient client = wsclient.getWsFileIOClient();
46-
46+
private static boolean isContainerized = false;
4747
private final static String testfilename = System.getProperty("lztestfile", "myfilename.txt");
48-
private final static String targetLZ = System.getProperty("lzname", "localhost");
48+
private final static String targetLZ = System.getProperty("lzname", "mydropzone"); //targetLZ accepted the address "localhost" once upon a time.
4949
private final static String targetLZPath = System.getProperty("lzpath", "/var/lib/HPCCSystems/mydropzone");
50-
private final static String HPCC_30117 = System.getProperty("HPCC30117", "fixed");
50+
private final static String targetLZAddress = System.getProperty("lzaddress", ".");
5151

5252
static
5353
{
54+
try
55+
{
56+
if (client.isTargetHPCCContainerized())
57+
isContainerized = true;
58+
}
59+
catch (Exception e)
60+
{
61+
System.out.println("Could not determine if target service is containerized, default: 'false'");
62+
}
63+
5464
if (System.getProperty("lztestfile") == null)
5565
System.out.println("lztestfile not provided - defaulting to myfilename.txt");
5666

@@ -60,20 +70,18 @@ public class WSFileIOClientTest extends BaseRemoteTest
6070
if (System.getProperty("lzpath") == null)
6171
System.out.println("lzpath not provided - defaulting to /var/lib/HPCCSystems/mydropzone");
6272

63-
if (System.getProperty("HPCC30117") == null)
64-
System.out.println("HPCC30117 status not provided - defaulting to fixed");
65-
else
66-
System.out.println("HPCC30117 status: '" + HPCC_30117 + "'");
73+
if (System.getProperty("lzaddress") == null)
74+
System.out.println("lzaddress not provided - defaulting to '.'");
6775
}
6876

6977
@Test
7078
public void copyFile() throws Exception
7179
{
7280
String lzfile=System.currentTimeMillis() + "_csvtest.csv";
7381
String hpccfilename="temp::" + lzfile;
74-
client.createHPCCFile(lzfile, targetLZ, true);
82+
client.createHPCCFile(lzfile, targetLZ, true, isContainerized ? null : targetLZAddress);
7583
byte[] data = "Product,SKU,Color\r\nBike,1234,Blue\r\nCar,2345,Red\r\n".getBytes();
76-
client.writeHPCCFileData(data, lzfile, targetLZ, true, 0, 20);
84+
client.writeHPCCFileData(data, lzfile, targetLZ, true, 0, 20, isContainerized ? null : targetLZAddress);
7785
try
7886
{
7987
System.out.println("Starting file spray.");
@@ -152,23 +160,49 @@ public void copyFile() throws Exception
152160
@Test
153161
public void AcreateHPCCFile() throws Exception, ArrayOfEspExceptionWrapper
154162
{
155-
System.out.println("Creating file: '" + testfilename + "' on LandingZone: '" + targetLZ + "' on HPCC: '" + super.connString +"'");
156-
Assert.assertTrue(client.createHPCCFile(testfilename, targetLZ, true));
163+
if (isContainerized)
164+
{
165+
System.out.println("Creating file: '" + testfilename + "' on LandingZone: '" + targetLZ + "' on HPCC: '" + super.connString +"'");
166+
System.out.println("Target HPCC is containerized, not providing targetLZAddress");
167+
Assert.assertTrue(client.createHPCCFile(testfilename, targetLZ, true, null));
168+
}
169+
else
170+
{
171+
System.out.println("Creating file: '" + testfilename + "' on LandingZone: '" + targetLZ + "' targetLZaddress: '" + targetLZAddress + "' on HPCC: '" + super.connString +"'");
172+
System.out.println("Target HPCC is NOT containerized, providing targetLZAddress");
173+
Assert.assertTrue(client.createHPCCFile(testfilename, targetLZ, true, targetLZAddress));
174+
}
157175
}
158176

159177
@Test
160178
public void BwriteHPCCFile() throws Exception, ArrayOfEspExceptionWrapper
161179
{
180+
System.out.println("Writing data to file: '" + testfilename + "' on LandingZone: '" + targetLZ + "' on HPCC: '" + super.connString +"'");
162181
byte[] data = "HELLO MY DARLING, HELLO MY DEAR!1234567890ABCDEFGHIJKLMNOPQRSTUVXYZ".getBytes();
163-
Assert.assertTrue(client.writeHPCCFileData(data, testfilename, targetLZ, true, 0, 20));
182+
if (isContainerized)
183+
{
184+
Assert.assertTrue(client.writeHPCCFileData(data, testfilename, targetLZ, true, 0, 20, null));
185+
}
186+
else
187+
{
188+
Assert.assertTrue(client.writeHPCCFileData(data, testfilename, targetLZ, true, 0, 20, targetLZAddress));
189+
}
164190
}
165191

166192
@Test
167193
public void CreadHPCCFile() throws Exception, ArrayOfEspExceptionWrapper
168194
{
169195
System.out.println("reading data from file: '" + testfilename + "' on LandingZone: '" + targetLZ + "' on HPCC: '" + super.connString +"'");
170196
byte[] data = "HELLO MY DARLING, HELLO MY DEAR!1234567890ABCDEFGHIJKLMNOPQRSTUVXYZ".getBytes();
171-
String response = client.readFileData(targetLZ, testfilename, data.length, 0);
197+
String response = null;
198+
if (isContainerized)
199+
{
200+
response = client.readFileData(targetLZ, testfilename, data.length, 0, null);
201+
}
202+
else
203+
{
204+
response = client.readFileData(targetLZ, testfilename, data.length, 0, targetLZAddress);
205+
}
172206
Assert.assertNotNull(response);
173207
Assert.assertArrayEquals(data, response.getBytes());
174208
}

0 commit comments

Comments
 (0)