List of usage examples for org.apache.commons.vfs2.provider.url UrlFileName getURI
public String getURI()
From source file:org.pentaho.big.data.impl.cluster.NamedClusterImpl.java
/** * This method generates the URL from the specific NamedCluster using the specified scheme. * * @param scheme the name of the scheme to use to create the URL * @return the generated URL from the specific NamedCluster or null if an error occurs *///from ww w. j a v a2 s. c o m @VisibleForTesting String generateURL(String scheme, IMetaStore metastore, VariableSpace variableSpace) { String clusterURL = null; try { if (!Utils.isEmpty(scheme)) { String ncHostname = getHdfsHost() != null ? getHdfsHost() : ""; String ncPort = getHdfsPort() != null ? getHdfsPort() : ""; String ncUsername = getHdfsUsername() != null ? getHdfsUsername() : ""; String ncPassword = getHdfsPassword() != null ? getHdfsPassword() : ""; if (variableSpace != null) { variableSpace.initializeVariablesFrom(getParentVariableSpace()); if (StringUtil.isVariable(scheme)) { scheme = variableSpace.getVariable(StringUtil.getVariableName(scheme)) != null ? variableSpace.environmentSubstitute(scheme) : null; } if (StringUtil.isVariable(ncHostname)) { ncHostname = variableSpace.getVariable(StringUtil.getVariableName(ncHostname)) != null ? variableSpace.environmentSubstitute(ncHostname) : null; } if (StringUtil.isVariable(ncPort)) { ncPort = variableSpace.getVariable(StringUtil.getVariableName(ncPort)) != null ? variableSpace.environmentSubstitute(ncPort) : null; } if (StringUtil.isVariable(ncUsername)) { ncUsername = variableSpace.getVariable(StringUtil.getVariableName(ncUsername)) != null ? variableSpace.environmentSubstitute(ncUsername) : null; } if (StringUtil.isVariable(ncPassword)) { ncPassword = variableSpace.getVariable(StringUtil.getVariableName(ncPassword)) != null ? variableSpace.environmentSubstitute(ncPassword) : null; } } ncHostname = ncHostname != null ? ncHostname.trim() : ""; if (ncPort == null) { ncPort = "-1"; } else { ncPort = ncPort.trim(); if (Utils.isEmpty(ncPort)) { ncPort = "-1"; } } ncUsername = ncUsername != null ? ncUsername.trim() : ""; ncPassword = ncPassword != null ? ncPassword.trim() : ""; UrlFileName file = new UrlFileName(scheme, ncHostname, Integer.parseInt(ncPort), -1, ncUsername, ncPassword, null, null, null); clusterURL = file.getURI(); if (clusterURL.endsWith("/")) { clusterURL = clusterURL.substring(0, clusterURL.lastIndexOf("/")); } } } catch (Exception e) { clusterURL = null; } return clusterURL; }
From source file:org.pentaho.di.core.namedcluster.NamedClusterManager.java
/** * This method generates the URL from the specific NamedCluster using the specified scheme. * * @param scheme/* w ww. ja v a 2s. c o m*/ * the name of the scheme to use to create the URL * @param clusterName * the name of the NamedCluster to use to create the URL * @return the generated URL from the specific NamedCluster or null if an error occurs */ @VisibleForTesting String generateURL(String scheme, String clusterName, IMetaStore metastore, VariableSpace variableSpace) { String clusterURL = null; try { if (!Utils.isEmpty(scheme) && !Utils.isEmpty(clusterName) && metastore != null) { NamedCluster namedCluster = read(clusterName, metastore); if (namedCluster != null) { String ncHostname = namedCluster.getHdfsHost() != null ? namedCluster.getHdfsHost() : ""; String ncPort = namedCluster.getHdfsPort() != null ? namedCluster.getHdfsPort() : ""; String ncUsername = namedCluster.getHdfsUsername() != null ? namedCluster.getHdfsUsername() : ""; String ncPassword = namedCluster.getHdfsPassword() != null ? namedCluster.getHdfsPassword() : ""; if (variableSpace != null) { variableSpace.initializeVariablesFrom(namedCluster.getParentVariableSpace()); if (StringUtil.isVariable(scheme)) { scheme = variableSpace.getVariable(StringUtil.getVariableName(scheme)) != null ? variableSpace.environmentSubstitute(scheme) : null; } if (StringUtil.isVariable(ncHostname)) { ncHostname = variableSpace.getVariable(StringUtil.getVariableName(ncHostname)) != null ? variableSpace.environmentSubstitute(ncHostname) : null; } if (StringUtil.isVariable(ncPort)) { ncPort = variableSpace.getVariable(StringUtil.getVariableName(ncPort)) != null ? variableSpace.environmentSubstitute(ncPort) : null; } if (StringUtil.isVariable(ncUsername)) { ncUsername = variableSpace.getVariable(StringUtil.getVariableName(ncUsername)) != null ? variableSpace.environmentSubstitute(ncUsername) : null; } if (StringUtil.isVariable(ncPassword)) { ncPassword = variableSpace.getVariable(StringUtil.getVariableName(ncPassword)) != null ? variableSpace.environmentSubstitute(ncPassword) : null; } } ncHostname = ncHostname != null ? ncHostname.trim() : ""; if (ncPort == null) { ncPort = "-1"; } else { ncPort = ncPort.trim(); if (Utils.isEmpty(ncPort)) { ncPort = "-1"; } } ncUsername = ncUsername != null ? ncUsername.trim() : ""; ncPassword = ncPassword != null ? ncPassword.trim() : ""; UrlFileName file = new UrlFileName(scheme, ncHostname, Integer.parseInt(ncPort), -1, ncUsername, ncPassword, null, null, null); clusterURL = file.getURI(); if (clusterURL.endsWith("/")) { clusterURL = clusterURL.substring(0, clusterURL.lastIndexOf("/")); } } } } catch (Exception e) { clusterURL = null; } return clusterURL; }