1、public class HyperSlaves extends Plugin implements Describable<HyperSlaves>

  (1)、init():初始化containerDriverFactory,其中的containerDriverFactory是一个抽象类ContainerDriverFactory类型的变量,我们可以调用它的forJob(Job context)方法获得一个ContainerDriver类型的抽象类。

  (2)、createStandardJobProvisionerFactory(job): 其中调用return new HyperProvisionerFactory.StandardJob(...)来返回一个HyperProvisionerFactory的抽象类

2、public abstract class HyperProvisionerFactory

作用:准备workspace,再返回一个HyperProvisioner实例

  (1)、其中包含一个抽象方法public abstract HyperProvisioner createProvisioner(TaskListener slaveListener),其中内部类StandardJob实现了本抽象类,其中的createProvisioner函数先创建一个JobBuildsContainersContext类的实例context,再调用prepareWorkspace(job, context),最后调用return new HyperProvisioner(context, slaveListener, driver, job, spec)

3、public abstract class OneShotSlave extends Slave implements EphemeralNode

作用:A slave that is designed to be used only once, for a specific hudson.model.Run,and as such has a life cycle to fully match the Run's one

provisioning such a slave should be a lightweight process, so one can provision them at any time and concurrently to match hudson.model.Queue load.

Typically usage is Docker container based Jenkins agents

Actual launch of the Slave is postponed until a Run is created, so we can have a 1:1 match between Run and Executor lifecycle:

  dump the launch log in build log

  mark the build as NOT_BUILD on launch failed

  shut down and remove the Executor on build completion

变量:private transient Queue.Executable executable

private final ComputerLauncher realLauncher;

private boolean provisioningFailed = false;

  (1)、public Launcher createLauncher(TaskListener listener):该函数先调用provision(listener),再调用return super.createLauncher(listener)

  // Assign a Queue.Executable to this OneShotSlave.By design, only one Queue.Executable can be assigned, then slave is shut down.

  This method has to be called just as the Run as been created. It run the actual launch of the executor

  and use Run's hudson.model.BuildListener as computer launcher listener to collect the startup log as part of the build

  Delaying launch of the executor until the Run is actually started allows to fail the build on launch failure

  so we have a strong 1:1 relation between a Run and its Executor

  (2)、首先调用创建 Executor类:executor = Executor.currentExecutor(),再调用realLauncher.launch(this.getComputer(), listener)启动一个slave容器

     如果之后调用getComputer().isActuallyOffline()为true,则调用provisionFailed(new IllegalStateException("Computer is offline after launch"))

     最后,如果没有异常发生,则调用executable = executor.getCurrentExecutable()

  

3、public class HyperSlave extends OneShotSlave

// EphemeralNode使用hyper container来运行build process,Slave只专注于一个特定的Job,最好专注于一个特定的build,但是在本类刚刚创建的时候,因为jenkins的生存周期,build还不存在。

private final HyperProvisionerFactory provisionerFactory

  (1)、构造函数为:public HyperSlave(String name, String nodeDescription, String labelString, HyperProvisionerFactory provisionerFactory):

      先调用super(name.replaceAll("/", ">>"), nodeDescription, SLAVE_ROOT, labelString, new HyperComputerLauncher())初始化父类

  (2)、public HyperComputer createComputer():该函数只是简单地调用new HyperComputer(this, provisionerFactory)

    // Create a custom Launcher which relies on "docker run" to start a new process

  (3)、public Launcher createLauncher(TaskListener listener):该方法先调用c = getComputer()获取HyperComputer类,再调用super.createLauncher(listener),最后调用launcher = new HyperLauncher(listener, c.getChannel(), c.isUnix(), c.getProvisioner()).decorateFor(this),生成一个launcher并返回。

3、public abstract class OneShotComputer extends SlaveComputer

private final OneShotSlave slave

  (1) 、构造函数:public OneShotComputer(OneShotSlave slave):调用super(slave)构造父类,再调用this.slave = slave

    // Claim we are online so we get task assigned to the executor, so a Run is created then can actually launch and report provisioning status in the build log

  (2)、public boolean isOffline():当slave不为空时,如果slave.hasProvisioningFailed()为true,则返回true,否则如果slave.hasExecutable()为false,则返回false

      否则,return isAcutallyOffline()

  (3)、public boolean isAcutallyOffline():仅仅调用return super.isOffline()

4、public class HyperComputer extends OneShotComputer

private final HyperSlave slave;

private final HyperProvisionerFactory provisionerFactory;

private HyperProvisioner

  (1)、构造函数为:public HyperComputer(HyperSlave slave, HyperProvisionerFactory provisionerFactory),利用slave初始化父类,再分别给slave和provisionerFactory赋值

   // Create a container provisioner to setup this Jenkins "computer" (aka executor)

  (2)、public HyperProvisioner createProvisioner():该函数调用 provisioner = provisionerFactory.createProvisioner(getListener()),并返回provisioner

  (3)、public ComputerLauncher createComputerLauncher():该函数仅仅new并返回一个HyperComputerLauncher()

5、public class HyperProvisioner

作用:创建slave容器,并且之后的exec操作也是通过本类进行

protected final JobBuildsContainersContext context;

protected final TaskListener slaveListener;

protected final ContainerDriver driver;

protected final Launcher launcher;

protected final ContainerSetDefinition spec;

  (1)、构造函数为:public HyperProvisioner(JobBuildsContainersContext context, TaskListener slaveListenerm, ContainerDriver driver, Job job, ContainerSetDefinition spec)

     该类中的多数变量都直接赋值,其中this.launcher = new Launcher.LocalLauncher(slaveListener)

  (2)、public void prepareAndLaunchSlaveContainer(final SlaveComputer computer, TaskListener listener):该函数先判断slave container是否存在,如果存在则重用。

     否则,首先获取buildImage和containerSize,再调用final ContainerInstance slaveContainer = driver.createAndLaunchSlaveContainer(computer, launcher, buildImage,  containerSize)生成一个容器实例,最后调用context.setSlaveContainer(slaveContainer)将slave container加入上下文。

  (3)、public Proc launchBuildProcess(Launcher.ProcStarter procStarter, TaskListener):该函数仅仅调用return driver.execInSlaveContainer(launcher, context.getSlaveContainer().getId(), procStarter)

6、public class HyperComputerLauncher extends ComputerLauncher

作用:启动slave容器

  (1)、public void launch(final SlaveComputer computer, TaskListener listener):launch容器的之前之后,添加一些log,再调用launch((HyperComputer) computer, listener)

  (2)、public void launch(final HyperComputer computer, TaskListener listener):该函数先调用provisioner=computer.createProvisioner()的HyperProvisioner类的实例,再调用provisioner.prepareAndLaunchSlaveContainer(computer, listener)来生成slave container

7、public class HyperLauncher extends Launcher.DecoratedLauncher

作用:Process launcher which uses docker exec instead of execve

Jenkins relies on remoting channel to run commands/process on executor.As Docker can as well be used to run a process remotely ,we can just bypass remoting

private final HyperProvisioner provisioner

  (1)、构造函数为:public HyperLauncher(TaskListener listener, VirtualChannel channel, boolean isUnix, HyperProvisioner provisioner):

    首先调用super(new Launcher.RemoteLauncher(listener, channel, isUnix))对父类进行构造,再调用this.provisioner = provisioner

  (2)、public Proc launch(ProcStarter starter):该方法仅仅调用return provisioner.launchBuildProcess(starter, listener)

-----------------------------------------------------------------------------  jenkins 源码 -------------------------------------------------------------------------------------------

1、public class CommandLauncher extends Computer

private final String agentCommand; // Command line to launch the agent, like "ssh myslave java -jar /path/to/hudson-remoting.jar"

private final EnvVars env; // Optional environment variables to add the current environment. Can be null

  (1)、public void launch(SlaveComputer computer, fijnal TaskListener listener):首先调用Slave node = computer.getNode(),当node为null时报错

    构建ProcessBuilder pb = new ProcessBuilder(Util.tokenize(getCommand())),再在其中注入HUDSON_URL, JENKINS_URL, SLAVEJAR_URL等环境变量

    调用final Process proc = _proc = pb.start(),最后调用computer.setChannel(proc.getInputStream(), proc.getOutputStream(), listener.getLogger(), new Channel.Listener() {...})建立channel

  

2、

Jenkins插件hyper slaves源码分析的更多相关文章

  1. Android Small插件化框架源码分析

    Android Small插件化框架源码分析 目录 概述 Small如何使用 插件加载流程 待改进的地方 一.概述 Small是一个写得非常简洁的插件化框架,工程源码位置:https://github ...

  2. Unity时钟定时器插件——Vision Timer源码分析之二

      Unity时钟定时器插件——Vision Timer源码分析之二 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处:http.dsqiu.iteye.com 前面的已经介绍了vp_T ...

  3. Mybatis 插件使用及源码分析

    Mybatis 插件 Mybatis插件主要是通过JDK动态代理实现的,插件可以针对接口中的方法进行代理增强,在Mybatis中比较重要的接口如下: Executor :sql执行器,包含多个实现类, ...

  4. Jenkins插件及 测试源码

    Jenkins 插件: https://updates.jenkins-ci.org/download/plugins/ 小米的一份android源码,测试工具,用于抢红包: https://gith ...

  5. Unity时钟定时器插件——Vision Timer源码分析之一

    因为项目中,UI的所有模块都没有MonBehaviour类(纯粹的C#类),只有像NGUI的基本组件的类是继承MonoBehaviour.因为没有继承MonoBehaviour,这也不能使用Updat ...

  6. Bootstrap源码分析之dropdown

    源码分析: Dropdowns.scss:下拉框模块 Javascripts/bootstrap/dropdown.js:实现下拉框响应 实现功能及原理: 下拉选项卡,默认不能实现显示选中项的功能 原 ...

  7. 插件开发之360 DroidPlugin源码分析(五)Service预注册占坑

    请尊重分享成果,转载请注明出处: http://blog.csdn.net/hejjunlin/article/details/52264977 在了解系统的activity,service,broa ...

  8. 插件开发之360 DroidPlugin源码分析(四)Activity预注册占坑

    请尊重分享成果,转载请注明出处: http://blog.csdn.net/hejjunlin/article/details/52258434 在了解系统的activity,service,broa ...

  9. 插件开发之360 DroidPlugin源码分析(二)Hook机制

    转载请注明出处:http://blog.csdn.net/hejjunlin/article/details/52124397 前言:新插件的开发,可以说是为插件开发者带来了福音,虽然还很多坑要填补, ...

随机推荐

  1. sql server 2008出现评估期已过的问题

    我的sql server2008用来半年吧,那天的昨天还能用,到了180天后,就不能用了,具体问题如下: 出了这个问题后,就打不开sql server了 解决方法: 1.打开安装中心,升级sql se ...

  2. 重大发现Discuz DB层跨库映射关系表名前缀BUG

    本文更新:http://www.cnblogs.com/x3d/p/3916198.html 场景: 在Discuz中创建Table模型,但该Table所在库与Discuz不在同一个库. Discuz ...

  3. 邻接矩阵c源码(构造邻接矩阵,深度优先遍历,广度优先遍历,最小生成树prim,kruskal算法)

    matrix.c #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include < ...

  4. Angularjs,WebAPI 搭建一个简易权限管理系统 —— 系统业务与实现(三)

    目录 前言 Angularjs名词与概念 Angularjs 基本功能演示 系统业务与实现 WebAPI项目主体结构 Angularjs 前端主体结构 系统业务与实现(二) 上一章我们讲解的 Angu ...

  5. percona 5.6升级到5.7相关error及解决方法

    今早,把开发环境的mysql升级到了5.7.15,5.6数据导入后,启动一切正常,检查.err日志,发现有如下异常: 2016-10-31T00:29:33.187073Z 0 [Warning] S ...

  6. [Architecture Design] CLK Architecture

    CLK.Prototype.Architecture 最近找数据,看到了博客园在不久之前,办了一个架构分享的活动:.Net项目分层与文件夹结构大全.看完之后觉得获益良多,接着也忍不住手痒,开始整理属于 ...

  7. JS 面向对象 编程设计

    面向对象的语言有一个标志,即拥有类的概念,抽象实例对象的公共属性与方法,基于类可以创建任意多个实例对象,一般具有封装.继承.多态的特性!但JS中对象与纯面向对象语言中的对象是不同的,ECMA标准定义J ...

  8. 微信jssdk,实现多图上传的一点心得

    一.首先在common.js里封装一个函数,在需要调用jsSDK的页面引用此方法即可实现微信的信息配置function signatureJSSDK() { var url = window.loca ...

  9. elasticsearch索引的增删改查入门

    为了方便直观我们使用Head插件提供的接口进行演示,实际上内部调用的RESTful接口. RESTful接口URL的格式: http://localhost:9200/<index>/&l ...

  10. SQL注入技术专题—由浅入深【精华聚合贴】

    SQL注入技术专题—由浅入深[精华聚合贴] 不管用什么语言编写的Web应用,它们都用一个共同点,具有交互性并且多数是数据库驱动.在网络中,数据库驱动的Web应用随处可见,由此而存在的SQL注入是影响企 ...