1973
Posts
1225
Kudos Received
124
Solutions
My Accepted Solutions
| Title | Views | Posted |
|---|---|---|
| 1845 | 04-03-2024 06:39 AM | |
| 2878 | 01-12-2024 08:19 AM | |
| 1585 | 12-07-2023 01:49 PM | |
| 2349 | 08-02-2023 07:30 AM | |
| 3242 | 03-29-2023 01:22 PM |
12-28-2016
06:33 PM
5 Kudos
Create a Box.com Application https://YourCompany.app.box.com/developers/services/ Get your client api, client secret, developer token, use server authentication with OAuth 2.0 + JWT, Add a public key from your developer machine and server. This takes a few steps and you have to create a Private and Public key. openssl genrsa -aes256 -out private_key.pem 2048
openssl rsa -pubout -in private_key.pem -out public_key.pem Anatomy of a Box.com Directory https://myenterprise.app.box.com/files/0/f/26783331215/NIFITEST You need the bolded # for accessing that directory, it is the Folder ID. Box.Com Java SDK <dependency>
<groupId>com.box</groupId>
<artifactId>box-java-sdk</artifactId>
<version>2.1.1</version>
</dependency> Create a New Java Maven Application mvn archetype:generate -DgroupId=com.yourenterprise -DartifactId=boxapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false Java Code package com.dataflowdeveloper;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import com.box.sdk.BoxAPIConnection;
import com.box.sdk.BoxFile;
import com.box.sdk.BoxFolder;
import com.box.sdk.BoxItem;
import com.box.sdk.BoxUser;
public final class Main {
// developer token expires in an hour
private static final String DEVELOPER_TOKEN = "somelongtokenlasts1hour";
private static final int MAX_DEPTH = 1;
private Main() { }
public static void main(String[] args) {
Logger.getLogger("com.box.sdk").setLevel(Level.ALL);
BoxAPIConnection api = new BoxAPIConnection(DEVELOPER_TOKEN);
BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo();
System.out.format("Welcome, %s <%s>!\n\n", userInfo.getName(), userInfo.getLogin());
// the example code lists everything from your root folder down, that could be
// alot, I have 75K files
// BoxFolder rootFolder = BoxFolder.getRootFolder(api);
// listFolder(rootFolder, 0);
BoxFile file = null;
// this is the id of the folder, you can get this two ways from either the URL or
// looking at the output of the root crawl
BoxFolder folder = new BoxFolder(api, "15296958056");
for (BoxItem.Info itemInfo : folder) {
if (itemInfo instanceof BoxFile.Info) {
BoxFile.Info fileInfo = (BoxFile.Info) itemInfo;
// lets look at all the attributes, many are null
System.out.println("File:" + fileInfo.getCreatedAt() + "," +
fileInfo.getDescription() + "," +
fileInfo.getExtension() + ",name=" +
fileInfo.getName() + ",id=" +
fileInfo.getID() + "," +
fileInfo.getCreatedBy() + "," +
fileInfo.getSize() + "," +
fileInfo.getVersion().getName() + "," +
fileInfo.getCreatedAt() + "," +
fileInfo.getModifiedAt() + "," +
fileInfo.getModifiedBy() +
"");
// download all the pdfs
if ( fileInfo.getName() != null && fileInfo.getID() != null && fileInfo.getName().endsWith(".pdf")) {
file = new BoxFile(api, fileInfo.getID());
FileOutputStream stream = null;
try {
stream = new FileOutputStream(fileInfo.getName());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
file.download(stream); // downloads to current directory specified in above fileoutputstream
//Input stream for the file in local file system to be written to HDFS
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(fileInfo.getName()));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try{
System.out.println("Save to HDFS " + fileInfo.getName());
//Destination file in HDFS
Configuration conf = new Configuration();
String dst = "hdfs://yourserver:8020/box/" + fileInfo.getName();
FileSystem fs = FileSystem.get(URI.create(dst), conf);
OutputStream out = fs.create(new Path(dst));
//Copy file from local to HDFS
IOUtils.copyBytes(in, out, 4096, true);
java.nio.file.Path path = FileSystems.getDefault().getPath(fileInfo.getName());
Files.delete(path);
}catch(Exception e){
e.printStackTrace();
System.out.println("File not found");
}
}
}
}
}
private static void listFolder(BoxFolder folder, int depth) {
for (BoxItem.Info itemInfo : folder) {
String indent = "";
for (int i = 0; i < depth; i++) {
indent += " ";
}
// you need this ID for accessing a folder
System.out.println(indent + itemInfo.getName() + ",ID=" + itemInfo.getID() );
if (itemInfo instanceof BoxFolder.Info) {
BoxFolder childFolder = (BoxFolder) itemInfo.getResource();
if (depth < MAX_DEPTH) {
listFolder(childFolder, depth + 1);
}
}
}
}
} Caveats By default you can only use the Developer Token which only lasts for 1 hour and as soon as you save it will vanish from the screen, so copy it first. Reference:
http://opensource.box.com/box-java-sdk/ https://github.com/box/box-java-sdk/blob/master/doc/authentication.md
https://github.com/box/box-java-sdk/blob/master/doc/folders.md
https://github.com/box/box-java-sdk/blob/master/doc/files.md
https://github.com/tspannhw/boxprocessor
https://docs.box.com/v2.0/docs/configuring-box-platform
https://docs.box.com/docs/app-auth https://github.com/box/box-java-sdk/blob/master/src/example/java/com/box/sdk/example/Main.java https://github.com/box/box-java-sdk/blob/master/doc/folders.md#get-a-folders-items https://github.com/box/box-java-sdk/blob/master/doc/files.md#download-a-file
... View more
Labels:
04-28-2017
07:08 AM
Hi @Timothy Spann can you help solve this issue? When I tried install HDF 2.0 with ambari. I got following error, it seems like the version of srorm in HDF repo is not matched with install script. did anyone get it? p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color: #333333; -webkit-text-stroke: #333333; background-color: #f5f5f5} span.s1 {font-kerning: none} Traceback (most recent call last): File "/var/lib/ambari-agent/cache/common-services/STORM/0.9.1/package/scripts/drpc_server.py", line 139, in <module> DrpcServer().execute() File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 280, in execute method(env) File "/var/lib/ambari-agent/cache/common-services/STORM/0.9.1/package/scripts/drpc_server.py", line 43, in install self.install_packages(env) File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 567, in install_packages retry_count=agent_stack_retry_count) File "/usr/lib/python2.6/site-packages/resource_management/core/base.py", line 155, in __init__ self.env.run() File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 160, in run self.run_action(resource, action) File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 124, in run_action provider_action() File "/usr/lib/python2.6/site-packages/resource_management/core/providers/package/__init__.py", line 54, in action_install self.install_package(package_name, self.resource.use_repos, self.resource.skip_repos) File "/usr/lib/python2.6/site-packages/resource_management/core/providers/package/yumrpm.py", line 49, in install_package self.checked_call_with_retries(cmd, sudo=True, logoutput=self.get_logoutput()) File "/usr/lib/python2.6/site-packages/resource_management/core/providers/package/__init__.py", line 83, in checked_call_with_retries return self._call_with_retries(cmd, is_checked=True, **kwargs) File "/usr/lib/python2.6/site-packages/resource_management/core/providers/package/__init__.py", line 91, in _call_with_retries code, out = func(cmd, **kwargs) File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 71, in inner result = function(command, **kwargs) File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 93, in checked_call tries=tries, try_sleep=try_sleep) File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 141, in _call_wrapper result = _call(command, **kwargs_copy) File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 294, in _call raise Fail(err_msg) resource_management.core.exceptions.Fail: Execution of '/usr/bin/yum -d 0 -e 0 -y install storm_2_1_2_0_10' returned 1. Error: Nothing to do [root@ochadoop07 /]# yum list | grep storm ranger-storm-plugin.noarch 0.6.0.2.0.2.0-17.el6 HDF-2.0 ranger_2_0_2_0_17-storm-plugin.x86_64 0.6.0.2.0.2.0-17.el6 HDF-2.0 storm.noarch 1.0.1.2.0.2.0-17.el6 HDF-2.0 storm-slider-client.noarch 1.0.1.2.0.2.0-17.el6 HDF-2.0 storm_2_0_2_0_17.x86_64 1.0.1.2.0.2.0-17.el6 HDF-2.0 storm_2_0_2_0_17-slider-client.x86_64 1.0.1.2.0.2.0-17.el6 HDF-2.0
... View more
12-27-2016
01:22 AM
I uninstalled everything, rebooted. Reinstalled and everything worked great. Perhaps a typo in my install.
... View more
12-25-2016
03:49 AM
had to uninstall ambari Then I manually installed postgresql, chmod on the directories and ran sysctl enable and started postgresql
... View more
01-03-2017
09:41 PM
Alicia, please see my answer above on Oct 24. If you are running Spark on YARN you will have to go through the YARN RM UI to get to the Spark UI for a running job. Link for YARN UI is available from Ambari YARN service. For a completed job, you will need to go through Spark History Server. Link for Spark history server is available from the Ambari Spark service.
... View more
12-22-2016
09:10 PM
6 Kudos
Setting up a Websocket Client and Server with Apache NiFi 1.1. I wanted to test out the new WebSocket Listener in Apache NiFi 1.1, but I needed a server to serve up my HTML client. So I ran that web server with NiFi as well. So my full solution is hosted and runs through Apache NiFi. This simple WebSockets Server and Client does the hello world of web sockets, Echo! Whatever the client sends, we send it back. My Suggested Use Cases for WebSockets WebSocket Client to Slack Interface WebSocket Client to Email WebSocket Chat stored to Apache Phoenix WebSocket To Communicate From Mobile Web Apps WebSocket To Send Detailed Log Details From Enterprise Web Applications Directly To Log Ingest Platform, bypassing local filesystem. Step 1: HandleHTTPRequest This accepts the HTTP calls from browsers Step 2: ExecuteStreamCommand Returns HTML page (could do getfile or any number of other ways of getting the HTML as a flowfile) Step 3: HandleHttpResponse this serves up our web page to browsers. A StandardHTTPContextMap is required to store HTTP requests and responses to share them through the stream. Step 4: PutFile Just to keep logs of what's going on, I saw all the flow files to the local file system. Step 5: ListenWebSocket This is the actual web socket server listener, it is what our client will talk to. Step 6: PutWebSocket This is the reply to the web socket client. Web Sockets Server Web Sockets Client (Static HTML5 Page with Javascript) Hosted on NiFi Web Socket Conversation On the Client Side A Shell Script to Output The HTML5 Javascript WebSocket Client ➜ nifi-1.1.0.2.1.1.0-2 cat server.sh
cat /Volumes/Transcend/Apps/nifi-1.1.0.2.1.1.0-2/wsclient.html
➜ nifi-1.1.0.2.1.1.0-2 cat wsclient.html
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function WebSocketTest()
{
if ("WebSocket" in window)
{
alert("WebSocket is supported by your Browser!");
// Let us open a web socket
var ws = new WebSocket("ws://localhost:9998/echo");
ws.send("MSG: NIFI IS AWESOME");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send("Message to send");
alert("Message is sent...");
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
alert("Message is received...");
};
ws.onclose = function()
{
// websocket is closed.
alert("Connection is closed...");
};
}
else
{
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
</script>
</head>
<body>
<div id="sse">
<a href="javascript:WebSocketTest()">Run WebSocket</a>
</div>
</body>
</html> Construct a Visual Web Server to Server up Static HTML 5 WebSocket Client Page https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.http.StandardHttpContextMap/index.html https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.HandleHttpRequest/index.html https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.HandleHttpRequest/additionalDetails.html https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.HandleHttpResponse/index.html https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.HandleHttpResponse/additionalDetails.html Listen For Websocket https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.websocket.ListenWebSocket/index.html Put Message Back https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.websocket.PutWebSocket/index.html Reference: http://www.infoworld.com/article/2609720/application-development/9-killer-uses-for-websockets.html https://en.wikipedia.org/wiki/WebSocket https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API https://tools.ietf.org/html/rfc6455 NiFi Template (This is for Apache NiFi 1.1.x) websockets.xml
... View more
Labels:
03-03-2017
08:37 PM
We could have NiFi rewrite, update and add to the sonicPI code so the music is constantly changing
... View more
01-03-2017
11:22 AM
The command that worked : *Most conservative, takes the least cluster /usr/hdp/current/spark2-client/bin/spark-submit --class samples.FuelModel--master yarn --deploy-mode cluster --executor-memory 4g--driver-memory 8g spark-assembly-1.0.jar The time taken is too long(40+ minutes) to be acceptable, I tried increasing the no. of cores and executors but it didn't help much. I guess the overhead exceeds the performance benefit due to the processing a small file(< 200MB) on 2 nodes. I would be glad if you can provide any pointers.
... View more
12-22-2016
10:16 PM
Without the full exception stack trace its difficult to know what happened. If you are instantiating hive then you may need to add hive-site.xml and the data-nucleus jars to the job. e.g. like --jars /usr/hdp/current/spark-client/lib/datanucleus-api-jdo-3.2.6.jar,/usr/hdp/current/spark-client/lib/datanucleus-rdbms-3.2.9.jar,/usr/hdp/current/spark-client/lib/datanucleus-core-3.2.10.jar --files /usr/hdp/current/spark-client/conf/hive-site.xml
... View more
03-15-2018
07:47 PM
In destinationName put this queue:///myQueue?targetClient=1 That works for me.
... View more