How can I change the Hive-beeline history file location - hadoop

I'm using beeline to connect to HIVE server.
Logged In user doesn't have access to its default HOME directory.
So after login I'm manually changing the ENV VAR HOME to the location where I have access.
However beeline is not honoring the HOME ENV-variable I've set.
Is there a way that I can set HISTORY FILE location to something else other than /home/{user}/.beeline

Here is a code defining beeline history file location:
/**
* The save directory if HOME/.beeline/ on UNIX, and
* HOME/beeline/ on Windows.
*/
public File saveDir() {
String dir = System.getProperty("beeline.rcfile");
if (dir != null && dir.length() > 0) {
return new File(dir);
}
File f = new File(System.getProperty("user.home"),
(System.getProperty("os.name").toLowerCase()
.indexOf("windows") != -1 ? "" : ".") + "beeline")
.getAbsoluteFile();
try {
f.mkdirs();
} catch (Exception e) {
}
return f;
}
You can only change Hive-beeline history file location by running beeline JVM with -Duser.home=/new/home/dir option.

Related

Spring Boot - get current configuration file path in runtime

I need to get absolute path to current active configuration file in Spring boot that don't locate in classpath or resources
It can be located in default place - project folder, subfolder "config", set via spring.config.location and in random place, also in another disk
Something like "E:\projects\configs\myProject\application.yml"
Assume that you have these application-{env}.yml config profiles in resources folder, and we are going to activate the dev configuration.
application.yml
application-dev.yml
application-prod.yml
application-test.yml
...
There are two ways you can activate the dev :
modify your application.yml,
spring:
profiles:
active: dev
or by command line when you want to start your application :
java -jar -Dspring.profiles.active=dev application.jar
Then, try this code in your program:
// get the active config dynamically
#Value("${spring.profiles.active}")
private String activeProfile;
public String readActiveProfilePath() {
try {
URL res = getClass().getClassLoader().getResource(String.format("application-%s.yml", activeProfile));
if (res == null) {
res = getClass().getClassLoader().getResource("application.yml");
}
File file = Paths.get(res.toURI()).toFile();
return file.getAbsolutePath();
} catch (Exception e) {
// log the error.
return "";
}
}
The output will be an absolute path of application-dev.yml
Someday I found same question here, but cant find it now
So here my solution, maybe someone needs it
#Autowired
private ConfigurableEnvironment env;
private String getYamlPath() throws UnsupportedEncodingException {
String projectPath = System.getProperty("user.dir");
String decodedPath = URLDecoder.decode(projectPath, "UTF-8");
//Get all properies
MutablePropertySources propertySources = env.getPropertySources();
String result = null;
for (PropertySource<?> source : propertySources) {
String sourceName = source.getName();
//If configuration loaded we can find properties in environment with name like
//"Config resource '...[absolute or relative path]' via ... 'path'"
//If path not in classpath -> take path in brackets [] and build absolute path
if (sourceName.contains("Config resource 'file") && !sourceName.contains("classpath")) {
String filePath = sourceName.substring(sourceName.indexOf("[") + 1, sourceName.indexOf("]"));
if (Paths.get(filePath).isAbsolute()) {
result = filePath;
} else {
result = decodedPath + File.separator + filePath;
}
break;
}
}
//If configuration not loaded - return default path
return result == null ? decodedPath + File.separator + YAML_NAME : result;
}
Not the best solution I suppose but it works
If you have any idea how to improve it I would really appreciate it

Using wildcard in Gradle Files then copy if it exists

In very brief, I want to find all files that ends with *.sql and copy them if they exist.
There might be 0 or more files in etc directory.
File sqlfiles = file('etc/' + '*.sql')
logger.info("Looking for SQL files: " + sqlfiles);
if (sqlfiles.exists())
{
logger.info("Found log SQL file: " + sqlfiles);
copy
{
from sqlfiles
into "$rpmStoredir"
}
}
else
{
logger.warn("No SQL file found - skipping");
}
With my code, the wildcard is not working here.
So adding "include" to the copy as in the below is working but I just want to figure how to add a logger if the file does not exist
copy
{
from "etc/"
include "*.sql"
into "$rpmStoredir"
}
file(...) is the wrong method to use as this returns a single java.io.File
You could do something like
FileTree myTree = fileTree('etc') {
include '*.sql'
}
if (myTree.empty) {
...
} else {
copy {
from myTree
...
}
}
See Project.fileTree(Object, Closure) and FileTree

Pages automation: You don’t have permission

I want to export "pages" file format to "pdf". My JXA script:
function run(argv) {
var pagesApp = Application('Pages');
try{
var doc = pagesApp.open('/Users/testas/Documents/test.pages')
pagesApp.export(doc, {to: '/Users/testas/Desktop/exported.pdf', as: 'PDF'})
} finally {
doc.close({saving: 'no'})
}
}
Running this script with:
osascript -l JavaScript cara.js
Output:
cara.js:135:216: execution error: Error on line 5: Error: The document “test.pages” could not be exported as “exported”. You don’t have permission. (6)
Same result even for the root user. What permission I don't have?
Working example:
function run(argv) {
var pagesApp = Application('Pages')
try{
var doc = pagesApp.open(new Path('/Users/testas/Documents/test.pages'))
pagesApp.export(doc, {to: new Path('/Users/testas/Documents/exported.pdf'), as: 'PDF'})
} finally {
doc.close({saving: 'no'})
}
}

Why doesn't gradle exec work with scripts?

Is there any way to make gradle exec work like a shell exec? ie - understand executable files in the path?
We have code that needs to work on windows and unix - and many many scripts that are obviously different on both machines. While I can do a hack like this:
npmCommand = Os.isFamily(Os.FAMILY_WINDOWS) ? 'npm.cmd' : '/usr/local/bin/npm'
and then run that command - the paths for some scripts are not necessarily set in stone - and it's just horrible code.
Is there any way to fix the problem - ie extend the exec task to find executable files in the path and run them?
How about something like:
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows'))
{
commandLine 'cmd', '/c', 'commandGoesHere'
}
else
{
commandLine 'sh', '-c', 'commandGoesHere'
}
I'd love a better way - but I made a simple function that I put in our common that you use like this:
exec {
commandLine command("npm"), "install"
}
the function looks like this:
//
// find a command with this name in the path
//
String command( String name )
{
def onWindows = (System.env.PATH==null);
def pathBits = onWindows ? System.env.Path.split(";") : System.env.PATH.split(":");
def isMatch = onWindows ? {path ->
for (String extension : System.env.PATHEXT.split(";"))
{
File theFile = new File( path, name + extension);
if (theFile.exists())
return theFile;
}
return null;
} : {path -> def file = new File(path,name);if (file.exists() && file.canExecute()) return file;return null;}
def foundLocal = isMatch(file("."));
if (foundLocal)
return foundLocal;
for (String pathBit : pathBits)
{
def found = isMatch(pathBit);
if (found)
return found;
}
throw new RuntimeException("Failed to find " + name + " in the path")
}

Set HDFS connection timeout in Java application

I use the Hadoop's FileSystem class for deleting some HDFS files. The problem now is, that the client gets a Connection Timeout after a too long duration, I need to shrink the time to wait until the timeout, so that the user gets faster responses, if he/she is outside the network!
Here my codes snippet:
try {
System.setProperty("HADOOP_USER_NAME", "test");
Configuration conf = new Configuration();
File csvFile = new File(pathCsvFile);
FileSystem hdfs = FileSystem.get(new URI(csvFile.getPath(), conf);
if(hdfs.exists(new Path(filterValuesPath))) {
hdfs.delete(new Path(filterValuesPath), true);
setInfo("File deleted!");
} else {
setInfo("No file to delete!");
}
} catch (Exception ex) { // the timeout is too high!!!
ex.printStackTrace();
setInfo("No connection or no files to delete!");
}
Where and how can I set the timeout for my application? I don't want to change this in any Hadoop config files, just locally for my Java app. Thank you!

Resources