首页 文章 精选 留言 我的

精选列表

搜索[api网关],共10000篇文章
优秀的个人博客,低调大师

Hadoop hdfs 基础操作 client Api(1)

1. 初始化连接 @Before public void setup() throws Exception { configuration = new Configuration(); System.out.println(); configuration.set("dfs.replication", "1"); // configuration.set("hadoop.tmp.dir","/home/hadoop0/data/tmp"); Iterator iterator = configuration.iterator(); while(iterator.hasNext() ){ System.out.println(iterator.next()); //打印所有配置或默认参数 } fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, HDFS_USER); System.out.println("--------------setup-------------"); } @After public void teardown(){ try { fileSystem.close(); } catch (IOException e) { e.printStackTrace(); } configuration = null; System.out.println("--------------teardown-------------"); } 2. 新增 2.1 创建文件夹 @Test public void mkDir() throws Exception{ System.out.println(fileSystem.mkdirs(new Path("/Complete"))); } 2.2 创建文件并写入 @Test public void create() throws Exception{ FSDataOutputStream out = fileSystem.create(new Path("/HDFSApp/write/2.txt")); out.writeUTF("hello! first wirte to HDFS file!"); out.flush(); out.close(); } 2.3 拷贝本地文件到远程 @Test public void copyFromLocal() throws IOException { Path localFile = new Path("F:/校验大师_2.7.5.1632.zip"); Path remoteFile = new Path("/HDFSApp/write/校验大师_2.7.5.1632.zip"); fileSystem.copyFromLocalFile(localFile, remoteFile); } 2.4 拷贝大文件,带进度条 @Test public void copyFromLocalLargeFile(){ String localFile = "F:/校验大师_2.7.5.1632.zip"; Path remoteFile = new Path("/HDFSApp/write/校验大师_2.7.5.1633.zip"); InputStream in = null; FSDataOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(localFile)); out = fileSystem.create(remoteFile, new Progressable() { @Override public void progress() { System.out.println("!"); } }); } catch (IOException e) { e.printStackTrace(); System.out.println("创建输入输出流失败!"); } if(in != null && out != null){ try { IOUtils.copyBytes(in, out,2048, true); } catch (IOException e) { e.printStackTrace(); System.out.println("上传过程中失败!"); } } } 3. 查询检索 3.1 读文件内容 @Test public void text() throws Exception{ FSDataInputStream in = fileSystem.open(new Path("/output/part-r-00000")); IOUtils.copyBytes(in, System.out, 1024); } 3.2 下载hdfs文件到本地 @Test public void copyToLocal() throws IOException { Path localFile = new Path("F:/"); Path remoteFile = new Path("/HDFSApp/write/校验大师_2.7.5.1632.zip"); fileSystem.copyToLocalFile(remoteFile, localFile); } 3.3 获取路径下内容 @Test public void listFiles() throws IOException { Path path = new Path("/HDFSApp/write"); FileStatus[] files = fileSystem.listStatus(path); for (FileStatus file:files) { String type = file.isDirectory() ? "文件夹" : "文件"; String permission = file.getPermission().toString(); short replication = file.getReplication(); String filePath = file.getPath().toString(); System.out.println(type + "\t" + permission + "\t" + replication + "\t" + filePath); } } 3.4 深层遍历路径下文件 @Test public void listFilesRecursive() throws IOException { Path path = new Path("/"); RemoteIterator<LocatedFileStatus> remoteIterator = fileSystem.listFiles(path, true); while(remoteIterator.hasNext()){ LocatedFileStatus file = remoteIterator.next(); String type = file.isDirectory() ? "文件夹" : "文件"; String permission = file.getPermission().toString(); short replication = file.getReplication(); String filePath = file.getPath().toString(); System.out.println(type + "\t" + permission + "\t" + replication + "\t" + filePath); } } 3.5 获取文件block信息 @Test public void getBlocksInfo() throws IOException { Path path = new Path("/HDFSApp/write/校验大师_2.7.5.1632.zip"); FileStatus fileStatus = fileSystem.getFileStatus(path); BlockLocation[] blockLocations = fileSystem.getFileBlockLocations(fileStatus, 0 , fileStatus.getLen()); for (BlockLocation block: blockLocations) { for (String name :block.getNames()) { System.out.println(name + ":" + block.getOffset() +"," + block.getLength()); } } } 4. 修改 4.1 修改文件名 @Test public void rename() throws IOException { Path oPath = new Path("/HDFSApp/write/0.txt"); Path nPath = new Path("/HDFSApp/write/3.txt"); boolean res = fileSystem.rename(oPath, nPath); System.out.println(res); } 5. 删除 5.1 删除文件或目录 public void delete() throws IOException { Path path = new Path("/HDFSApp/write/校验大师_2.7.5.1632.zip"); boolean res = fileSystem.delete(path, false); System.out.println(res); }

优秀的个人博客,低调大师

Java 调用Jenkins API远程触发部署

第一步:引入相关的包 // Jenkins-client compile group: 'com.offbytwo.jenkins', name: 'jenkins-client', version: '0.3.6' 第二步:写代码 JenkinsServer jenkins = new JenkinsServer(new URI("此处是Jenkins访问路径,eg:http://localhost:8088/"), "此处是用户名,eg: zhangsan", "此处是用户密码:eg: 110110"); // 判断jenkins是否running if(jenkins.isRunning()){ // 获取jenkins构建脚本 String jobXml = jenkins.getJobXml("jobName"); // 修改构建脚本 jenkins.updateJob("jobName",newJobXml); // 构建对应的job jenkins.getJob("jobName").build(); // 获取html格式日志 jenkins.getJob("jobName").getLastBuild().details().getConsoleOutputHtml() // 获取text格式日志 jenkins.getJob("jobName").getLastBuild().details().getConsoleOutputText() // 获取执行结果(是否成功) jenkins.getJob("jobName").getLastBuild().details().getResult() } 遇到的问题在调用build的时候一定要确保jenkins的全局配置文件的这个地方要正确: 该地址为jenkins的访问地址;否则执行build的时候会无法链接Jenkins 参考链接:http://blog.chenmiao.cf/2016/12/28/java%E8%B0%83%E7%94%A8jenkins%E8%BF%9C%E7%A8%8Bapi,%E9%99%84%E4%BB%A3%E7%A0%81/

优秀的个人博客,低调大师

远程连接docker daemon,Docker Remote API

当我们的docker安装好之后,运行sudo docker ps查看是否运行成功。 sudo groupadd docker # 创建docker组 sudo usermod -aG docker whoami # 将当前用户添加到docker组 重启docker服务,注销登录,再次登录,这样就可以免去每次输入sudo的烦恼了。 ok,我们安装好之后,docker宿主程序默认是通过非网络的Unix套接字运行,是只能够进行本地通信(/var/run/docker.sock),是不能够直接远程连接docker的。需要修改其配置: 先创建文件夹 mkdir -p /etc/systemd/system/docker.service.d/ 编写文件 vim /etc/systemd/system/docker.service.d/override.conf [Service] ExecStart= ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 重启docker服务 systemctl daemon-reload systemctl restart docker.service 验证是否配置成功 [root@Ieat1 ~]# docker -H tcp://127.0.0.1:2375 ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 01ec6c9e3cb9 docker.elastic.co/kibana/kibana:6.2.4 "/bin/bash /usr/lo..." 33 hours ago Up 33 hours 0.0.0.0:5601->5601/tcp kibaba_kibana_1 ea57c86d7fd8 nginx "nginx -g 'daemon ..." 2 days ago Up 2 days 80/tcp, 0.0.0.0:80->80/tcp nginx_dev 当然这暴露了docker远程访问端口,实际上是不安全的,建议修改默认端口2375为其他端口,下一步研究如何配置安全认证证书才能远程访问。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册