Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/candidate-9.8.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon Smith <[email protected]>

# Conflicts:
#	commons-hpcc/pom.xml
#	dfsclient/pom.xml
#	pom.xml
#	wsclient/pom.xml
  • Loading branch information
GordonSmith committed Aug 30, 2024
2 parents 44414b1 + f52d617 commit 4501cc5
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hpccsystems.ws.client;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -159,24 +160,44 @@ private String getTargetHPCCBuildVersionString() throws Exception
if (wsconn == null)
throw new Exception("Cannot get target HPCC build version, client connection has not been initialized.");

String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws
String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws IOException if http != ok

if (response == null || response.isEmpty())
throw new Exception("Cannot get target HPCC build version, received empty " + wsconn.getBaseUrl() + " wssmc/activity response");

String header = response.substring(0, 100).trim(); //crude, but can prevent wasteful overhead
if (header.startsWith("<html"))
throw new Exception("Received invalid HTML response, expected XML HPCC build version: \"" + header + "\"...");

setUpBuildVersionParser();

String versionString = null;
Document document = null;
synchronized(m_XMLParser)
try
{
document = m_XMLParser.parse(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8)));
synchronized(m_XMLParser)
{
document = m_XMLParser.parse(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8)));
}
}
catch (Exception e)
{
throw new Exception("Could not parse XML HPCC Version response: \"" + response.substring(0, 100) + "\"...", e);
}

if (document == null)
throw new Exception("Cannot parse HPCC build version response.");
throw new Exception("Could not parse XML HPCC Version response: \"" + response.substring(0, 100) + "\"...");

return (String) m_buildVersionXpathExpression.evaluate(document,XPathConstants.STRING);
try
{
versionString = (String) m_buildVersionXpathExpression.evaluate(document,XPathConstants.STRING);
}
catch (XPathExpressionException e)
{
throw new Exception("Could not extract build version from HPCC Build/Version response: \"" + response + "\"");
}

return versionString;
}

public SpanBuilder getWsClientSpanBuilder(String spanName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ public ProgressResponseWrapper sprayVariable(DelimitedDataOptions options, DropZ

SprayVariable request = new SprayVariable();
request.setSourceIP(targetDropZone.getNetAddress());
request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName);
request.setSourcePath(Utils.appendPathSections(targetDropZone.getPath(), sourceFileName));
request.setDestGroup(destGroup);
request.setDestLogicalName(targetFileName);
request.setOverwrite(overwrite);
Expand Down Expand Up @@ -1161,7 +1161,7 @@ public ProgressResponseWrapper sprayXML(DropZoneWrapper targetDropZone, String s

request.setDestGroup(destGroup);
request.setSourceIP(targetDropZone.getNetAddress());
request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName);
request.setSourcePath(Utils.appendPathSections(targetDropZone.getPath(), sourceFileName));
request.setDestLogicalName(targetFileName);
request.setOverwrite(overwrite);
request.setSourceFormat(format.getValue());
Expand Down Expand Up @@ -1317,7 +1317,7 @@ public ProgressResponseWrapper sprayFixed(DropZoneWrapper targetDropZone, String
request.setDestGroup(destGroup);
request.setSourceRecordSize(recordSize);
request.setSourceIP(targetDropZone.getNetAddress());
request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName);
request.setSourcePath(Utils.appendPathSections(targetDropZone.getPath(), sourceFileName));
request.setDestLogicalName(targetFileLabel);
request.setOverwrite(overwrite);
request.setPrefix(prefix);
Expand Down
101 changes: 101 additions & 0 deletions wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,107 @@ public static String ensureTrailingPathSlash(String path, char slash)
return path;
}

/**
* Constructs new path based on provided pre and post path sections
* Ensures resulting path is properly delimited at the point of concatenation
* Uses Linux path style path separator
*
* @param prefixPath - the prefix path
* @param postfixPath - the postfix path
* @return - new path comprised of path prefix a linux style path separator and path postfix
*/
public static String appendLinuxPathSections(String prefixPath, String postfixPath)
{
return appendPathSections(prefixPath, LINUX_SEP, postfixPath);
}

/**
* Constructs new path based on provided pre and post path sections
* Ensures resulting path is properly delimited at the point of concatenation
* Uses Windows path style path separator
*
* @param prefixPath - the prefix path
* @param postfixPath - the postfix path
* @return - new path comprised of path prefix a windows style path separator and path postfix
*/
public static String appendWindowsPathSections(String prefixPath, String postfixPath)
{
return appendPathSections(prefixPath, WIN_SEP, postfixPath);
}

/**
* Constructs new path based on provided pre and post path sections
* Ensures resulting path is properly delimited at the point of concatenation
* Infers proper path separator on presence of Linux or Windows style path separator in prefix path
*
* @param prefixPath - the prefix path
* @param postfixPath - the postfix path
* @return - new path comprised of path prefix a path separator and path postfix
* @throws Exception - Invalid paths, indiscernible path style
*/
public static String appendPathSections(String prefixPath, String postfixPath) throws Exception
{
if (prefixPath == null)
prefixPath = "";

if (postfixPath == null)
postfixPath = "";

if (prefixPath.length() == 0 && postfixPath.length() == 0)
return "";

try
{
char pathSep = inferPathSeperatorType(prefixPath.length() != 0 ? prefixPath : postfixPath);
return appendPathSections(prefixPath, pathSep, postfixPath);
}
catch (Exception e)
{
throw new Exception("Could not append path sections, ensure original path sections are valid and contain path seperator");
}
}

/**
* Constructs new path based on provided pre and post path sections
* Ensures resulting path is properly delimited at the point of concatenation
* Uses provided char as delimiter between pre and post path sections
*
* @param prefixPath - the prefix path
* @param slash - separator to use when appending path sections
* @param postfixPath - the postfix path
* @return - new path comprised of path prefix a path separator and path postfix
*/
public static String appendPathSections(String prefixPath, char slash, String postfixPath)
{
prefixPath = trimTrailing(prefixPath);

if (prefixPath.length() == 0 || prefixPath.charAt(prefixPath.length()-1) != slash)
prefixPath = prefixPath + slash;

postfixPath = postfixPath.trim();

if (postfixPath.length() > 0 && postfixPath.charAt(0) == slash)
prefixPath = prefixPath + postfixPath.substring(1);
else
prefixPath = prefixPath + postfixPath;

return prefixPath;
}

/**
* Infers path style (linux/windows) based on presence of Linux separator
* @param path - the path
* @return - new path comprised of path prefix a path separator and path postfix
* @throws Exception - Invalid paths, indiscernible path style
*/
public static char inferPathSeperatorType(String path) throws Exception
{
if (path.length() == 0)
throw new Exception("Zero len path detected!");

return path.contains(Character.toString(LINUX_SEP)) ? LINUX_SEP : WIN_SEP;
}

/**
* Removes trailing whitespace characters from a string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@

public class UtilsTest
{

@Test
public void testappendPathSections() throws Exception
{
//appendWindowsPathSections
assertEquals(Character.toString(Utils.WIN_SEP), Utils.appendWindowsPathSections("", ""));
assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some\\ ", " \\path\\"));
assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some", " path\\"));

//appendLinuxPathSections
assertEquals(Character.toString(Utils.LINUX_SEP), Utils.appendLinuxPathSections("", ""));
assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path ", " relative/path"));
assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path/ ", " /relative/path"));
assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path"));
assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path"));
assertEquals("/relative/path", Utils.appendLinuxPathSections("/", " /relative/path"));

//appendPathSections
assertEquals("/relative/path", Utils.appendPathSections("/", " /relative/path"));
assertEquals("/root/path/relative/path", Utils.appendPathSections("/root/path ", " relative/path"));
assertEquals("/root/path/relative/path", Utils.appendPathSections("/root/path/ ", " /relative/path"));
assertEquals("/relative/path", Utils.appendPathSections("/ ", "/relative/path"));
assertEquals("/relative/path", Utils.appendPathSections("/ ", "/relative/path"));
assertEquals("/relative/path", Utils.appendPathSections("/", " /relative/path"));

assertEquals("C:\\some\\path\\", Utils.appendPathSections("C:\\some\\ ", " \\path\\"));
assertEquals("C:\\some\\path", Utils.appendPathSections("C:\\some", " path"));
}

@Test
public void testEnsureTrailingSlashTrailingWhiteSpace()
{
Expand Down

0 comments on commit 4501cc5

Please sign in to comment.