2019独角兽企业重金招聘Python工程师标准>>>
一项服务由服务描述文件和其支持的文件组成。
服务描述文件(Service Descriptor File)
描述了以下信息:
- General: 描述服务的 name, service type, number of service instances, and the service icon filename
- Compute: 指定供应machines时的template名称。 这个名字与cloud driver中定义的template名字相一致。描述machine池中可用于服务实例的machine硬件配置文件。硬件配置文件映射到一个特定的硬件设置和镜像大小(e.g. 在Amazon EC2将映射为镜像大小相关的硬件id[m1.small, c1.medium, etc.] and an ami id). 这可以与云环境中应用recipe运行的machine进行清晰的区别开。更多的可以参见 Cloud Drivers.
- Lifecycle Events: Maps events to handling scripts or closures and, as such, is the most important part of the service recipe. An event handler can be an external Groovy script, a shell script, or a batch file (depending on the operating system). The handlers must reside in the service folder
Cloudify can use the same recipe for different operating systems, as long as you specify the relevant instructions for each within the recipe, or the instructions are generic to all of them. The use of handler files is optional. For example, if a post-installation script is not specified in the service recipe, then Cloudify does not execute a handler after the service has been installed.
- Custom Commands: Maps custom commands to handling scripts that can be invoked as commands using the Cloudify shell
- Probes: For monitoring service configuration, performance, and availability
- UI Layout: Describes the layout to use for displaying the collected metrics in the Cloudify web management console
In future releases, Cloudify will also support “provided services”. These services are not provisioned by Cloudify and are only monitored for availability.
General Section
The General section describes the following attributes:
name
服务名称是相对各种Cloudify管理和监控工具,用于标识服务。因此,相同的Cloudify controller管理的所有应用的名称必须是唯一的。
icon
使用可选的图像文件作为Application Map中的服务务图标,将会显示在 Cloudify web management console.
It is recommended that the image will not exceed the size of 20×20 pixels, as this can burden the image loading within the Web Management Console, thus resulting in slower performance. Images exceeding the specified dimensions will be scaled to fit regardless.
type
服务类型,Cloudify web management console 在Application Map中定位服务。 If you do not specify an icon
in this section, the service type is used to determine the default icon to display in the Application Map. 以下是可支持的类型:
- WEB_SERVER
- APP_SERVER
- DATABASE
- NOSQL_DB
- MESSAGE_BUS
- ESB_SERVER
- LOAD_BALANCER
- SECURITY_SERVER
numInstances
当服务启动时,供应初始的实例数。
General section示例如下:
service {
name "jboss-service"
icon "jboss.jpg"
type "APP_SERVER"
numInstances 2
//recipe body here
}
Isolation SLA (Multi Tenant Deployment)
Cloudify 允许在同一主机中部署多项服务。
此举的目的是,在基于BYON云时,将物理机最大化利用。支持以下四种模式:
- dedicated (default) – 该主机仅专用于一种服务实例。其它服务不能在该主机上部署。
- global – 该主机可能被所有的应用和租户共享。在 Isolation SLA部分配置其共享容量。
- appShared – 同一应用的服务可以共享machines。
- tenantShared – 同一租户(相同的安全验证组)的服务可共享machines。
在当前版本中,在managent machines中安装服务/应用仅允许global mode.
例子:
service {
name "groovy"
type "WEB_SERVER"
elastic true
numInstances 2
maxAllowedInstances 2
// define SLA requirements for each service instance with regards to isolation from other services
// if this is not defined - defaults to dedicated mode. which means each service instance is insalled on a dedicated VM.
isolationSLA {
global { // global - meaning each service instance can be installed on any VM that answer the requirements below.
// allowing services to share VM's. Note: VM's running management process are not included.
instanceCpuCores 0 // no CPU requirements, this way instances can be installed on the same VM even if it has just one CPU(can also define 0.5 CPU requirements and so on...)
instanceMemoryMB 128 // each instance needs 128MB to be allocated for him on the VM.
useManagement true // Enables installing services/applications on the management machines. Defaults to false.
}
}
可以定义在 -service.groovy :
isolationSLA {
appShared { // services belonging to the same application may share machines
instanceCpuCores 0
instanceMemoryMB 128
}
}
isolationSLA {
global { // all services may share machines
instanceCpuCores 0
instanceMemoryMB 128
}
}
isolationSLA {
tenantShared { // service belonging to the same authenticationGroup may share machines
instanceCpuCores 0
instanceMemoryMB 128
}
}
如果没有对其定义,那么a dedicated isolation 将被使用,即服务实例不能共享machines。
这项特性仅在 BYON Cloud Driver上做过测试。
Prior to using this, please read how to set the reserved memory capacity.
从一个文件加载 Sections
描述文件中的任一sections可以从外部文件中加载服务信息到描述文件中。这样,某一sections可以被多个服务的描述文件共享。
在服务描述文件中,定义在General section的Groovy参数可以被外部文件使用。
例如,定义一个标准的web management console metrics布局, 如下:
- 在一个外部文件中定义
userInterface
section。userInterface {
metricGroups = [
metricGroup{
name = "process"
metrics = ["cpu", "memory"]
}
]
widgetGroups = [
widgetGroup{
name ="cpu"
widgets = [
balanceGauge{metric = "cpu"},
barLineChart{metric = "cpu"}
]
},
widgetGroup {
name = "memory"
widgets = [
balanceGauge { metric = "memory" },
barLineChart{ metric = "memory"
axisYUnit Unit.PERCENTAGE
}
]
}
]
}
- 在服务文件中可加载外部文件。
service {
name "myService"
...
userInterface load("userInterface.groovy")
}