开发cloudify配方文件- Service Context API

The Service Context API

The Service Context API提供在生命周期事件处理程序中可以访问所有和特定服务实例

从事件程序中获取Service Context

使用theServiceContextFactory类来获取Service Context,例如:

getServiceContext.groovy

import org.cloudifysource.dsl.context.ServiceContextFactory;

def context = ServiceContextFactory.getServiceContext()

 

获取到service context后,使用waitForService方法来访问服务实例,例如:

wait4Cassandra.groovy

def serviceName = "cassandra"

def service = context.waitForService(serviceName, 20, TimeUnit.SECONDS)

也可以使用context.serviceName来获取服务实例

服务的方法

服务对象提供下列方法:

serviceMethods.groovy

public String getName();

public int getNumberOfPlannedInstances();

public int getNumberOfActualInstances();

public ServiceInstance[] waitForInstances(final int howmany,

            final long timeout, final TimeUnit timeUnit);

public ServiceInstance[] getInstances();

服务实例的方法

服务实例对象可以使用服务对象的 getInstances()方法来获取。

获取当前实例ID context.getInstanceId().

服务实例对象提供下列方法:

serviceInstanceMethods.groovy

public int getInstanceID();

public String getHostAddress();

public String getHostName();

   

//Invoke a custom command

public void invoke(String commandName);

   

//get the service instances detail

public Object getDetails(String serviceDetailsKey);

   

//get the service instance monitor

public Object getMonitors(String serviceMonitorsKey);

转载于:https://my.oschina.net/OQKuDOtsbYT2/blog/121765

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值