cloudify服务依赖于其他服务 [英] cloudify service dependsOn other service
问题描述
当我使用cloudify(2.7)部署一个应用程序时,它包含两个服务(例如service A dependsOn service B),这里是app-application.groovy
应用程序{
名称应用程序
服务{
名称=B
}
服务{
name =A
dependsOn = [B]
}
}
$ p $当服务B有2个实例时,其中一个服务B实例可用,服务A开始调用启动事件,但服务A依赖于所有服务实例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的可能值可以在这里找到: 因此,值为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 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屋!
https://github.com/CloudifySource/cloudify/blob/master/dsl/src/main/java/org/cloudifysource/dsl/internal/CloudifyConstants.java#L35
application {
name "app"
service {
name = "B"
}
service {
name = "A"
dependsOn = [ "B" ]
}
}