您的位置:首页 > 运维架构 > Apache

Apache Stratos探究: Apache Stratos的Mock IaaS模块

2015-11-18 10:26 471 查看
     如果要运行Apache Stratos,则可能需要建立一个IaaS或者购买IaaS服务。个人自己建立IaaS服务的话,需要购置相当数量的资源硬件,而购买在线的IaaS服务,比如亚马逊的EC2等,则也是需要花钱的。
     自从Apache Stratos引入了Docker/Kubernetes等Linux Container的支持,这些问题在某些程度上得到解决。然而建立Kubernetes集群同样需要多个虚拟/物理上的机器。而且设置一个puppet master(或则其他的管理)平台也很费时费力。
     Apache Stratos开发团队最近引入了“Mock IaaS”这一特性,可以用来模拟Apache Stratos从IaaS平台所需要的基本特性。 

    


图1:Mock IaaS模块架构         

Stratos提供了一层虚拟的IaaS服务,具有下列特色:
1.运行一个实例
2.发送用户数据等参数给实例
3.给实例绑定上网络接口
4.给网络接口分配IP地址
5.给实例分配存储
6.停止一个实例
     在Stratos 4.0中,该mock模块并没有提供一些直接通过JClouds计算服务API激活的能与IaaS通信的方法。
引入Mock IaaS模块之后,全部用来与IaaS通信的方法已经转移到了IaaS接口中,然后与jclouds相关的逻辑已经转移到了一个专门的类JclousIaas中。
IaaS接口已经被Mock IaaS client和Jclouds IaaS client实现。Jclouds IaaS client可更深入的扩展,支持EC2,OpenStack,VCloud,CloudStack,Docker.
Mock IaaS是如何工作的
   
Mock IaaS服务利用一个线程来模仿一个实例的生命周期。每一个实例都有一个单独的线程用来将instance status events发送给message broker和health statics给Complex Event Processsor(CEP).当一个mock member thread启动后,将会发送一个Instance Started event给message broker,之后过了几秒以后,将会发送Instance Activated event.此后,health statics
publisher将被启动,它将从单例的health statistics map中读取数据,health statistics map中的数据由health statistic generator产生。
     Health statistics generator根据定义在Mock IaaS配置文件中的statistic patterns来更新health statistis map.下面的Mock IaaS配置文件片段,展示了这些patterns如何为不同的cartridge工作的。 
<mock-iaas enabled="true">
<health-statistics>
<cartridge type="tomcat">
<!-- factor:memory-consumption|load-average|request-in-flight-->
<!-- mode:loop|continue|stop -->
<!-- Mode defines the action needs to be taken after the last sample value:
loop: start from beginning
continue: continue the last sample value
stop: stop publishing statistics -->
<pattern factor="memory-consumption" mode="continue">
<!-- Sample values -->
<sampleValues>20,30,40,50,60,70,50,40,30,20</sampleValues>
<!-- Duration of each sample value in seconds -->
<sampleDuration>60</sampleDuration>
</pattern>
<pattern factor="load-average" mode="continue">
<!-- Sample values -->
<sampleValues>20</sampleValues>
<!-- Duration of each sample value in seconds -->
<sampleDuration>60</sampleDuration>
</pattern>
</cartridge>
</health-statistics>
</mock-iaas>


在上面的代码中,我们为tomcat cartridge定义了一个health statistics generation pattern。与此相似,我们可以为不用的cartridge定义多种health statistics generation pattern。
     在每一个cartridge中,可以定义三种可不同的autoscaling factor:
   
1.memory-consumption
    2.load-average
   
3.request-in-flight.
   Mock health statistics generator会为每一个factor产生数据并且更新中心的health statistics map。在每一个pattern mode中(即上面的第10行),定义了当最后一个sample的值达到时需要采取的动作。如果设置成loop,则mock health statistics
generator会循环会到第一个值。如果被设置成continue,则最后的sample的值则会继续被使用。如果设置成stop, 则health statistics generator进程会停止,最终导致health statistics publishing 进程也会停止。最后,集群中的数据将产生错误。 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  云计算