cloudify服务依赖于其他服务 [英] cloudify service dependsOn other service

查看:135
本文介绍了cloudify服务依赖于其他服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用cloudify(2.7)部署一个应用程序时,它包含两个服务(例如service A dependsOn service B),这里是app-application.groovy

 应用程序{
名称应用程序

服务{
名称=B
}

服务{
name =A
dependsOn = [B]
}
}
解决方案

https://groups.google.com/forum/#!topic/cloudify-developers/TZzwfzY-rLY

Cloudify 2.7中的默认行为是在至少有一个运行实例e所依赖的所有服务。
如果您想等待其他服务的所有实例(或其他依赖性逻辑),则应在生命周期脚本中实现此功能。您可以使用服务上下文API访问其他服务的状态:
http:/ /getcloudify.org/guide/2.7/developing/the_service_context_api.html



例如,您可以添加使用waitForInstances()的'preInstall'事件, API等待所需数量的实例。请注意,此API可让您访问尚未启动的实例。您可以通过调用来检查实例的当前状态:
$ b $ serviceInstance.getMonitors(USM_State)

USM_State的可能值可以在这里找到:
https://github.com/CloudifySource/cloudify/blob/master/dsl/src/main/java/org/cloudifysource/dsl/internal/CloudifyConstants.java#L35


因此,值为2表示正在运行的实例。


When I use cloudify(2.7) to deploy an application,it includs two services(e.g. service A dependsOn service B),here is the app-application.groovy

application {
    name "app"

    service {
        name = "B"
    }

    service {
        name = "A"
        dependsOn = [ "B" ]
    }
}

when the service B has 2 instances,one of the instances of service B is available,the service A begin to invoke the start event,but the service A dependsOn all instance of service B, Does it have some configuration to solve it ?

解决方案

Copying my answer from https://groups.google.com/forum/#!topic/cloudify-developers/TZzwfzY-rLY:

The default behavior in Cloudify 2.7 is to start a service once there is at-least one running instance of all of the services it depends on. If you would like to wait for all instances of another service (or some other dependency logic) you should implement this in your lifecycle scripts. You can access the state of other services using the service context API: http://getcloudify.org/guide/2.7/developing/the_service_context_api.html

For example, you could add a 'preInstall' event that uses the waitForInstances() API to wait for the required number of instances. Note that this API gives you access to instances that may not have started yet. You can check the current state of an instance by calling:

serviceInstance.getMonitors("USM_State")

The possible values of USM_State are available here: https://github.com/CloudifySource/cloudify/blob/master/dsl/src/main/java/org/cloudifysource/dsl/internal/CloudifyConstants.java#L35

So a value of 2 indicates a running instance.

这篇关于cloudify服务依赖于其他服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆