本文主要介绍cloud foundry的service框架,上接(http://blog.csdn.net/zdq0394/article/details/8464269),主要内容包括(5)Cloud Controller和Service Gateway的交互过程 (6)Service Gateway和Service Node的交互过程。
Cloud Controller和Service Gateway之间的交互主要通过Rest HTTP接口。
1)服务注册(心跳)
Service Gateway会周期性的向cloud controller发送心跳信息(注册信息)。
请求uri: post 'services/v1/offerings' => 'services#create', :as => :service_create
请求内容:
@svc_json = { :label => @service[:label], 服务的标签由服务名称和版本号两部分构成:mysql-5.1 :url => @service[:url], Service gateway服务器的host:port,用来接收create/delete服务实例等操作 :plans => @service[:plans], Service gateway提供的plans,比如改服务由免费和付费两种等 :cf_plan_id => @service[:cf_plan_id], :tags => @service[:tags], :active => true, :description => @service[:description], :plan_options => @service[:plan_options], :acls => @service[:acls], :timeout => @service[:timeout], }
请求响应:
无论成功还是失败,service gateway都会记录log
cloud controller在收到该请求后,会在数据库services表中增加一条记录。
2)服务注销
当service gateway退出时会向cloud controller注销该服务,注意不包括bin/vcap_dev stop 命令,因为该命令采用kill -9方式。
请求uri: post 'services/v1/offerings' => 'services#create', :as => :service_create
请求内容:
@deact_json = { :label => @service[:label], 服务的标签由服务名称和版本号两部分构成:mysql-5.1 :url => @service[:url], Service gateway服务器的host:port,用来接收create/delete服务实例等操作 :active => false 操作的关键标志 }请求响应:
3)service gateway从cloud controller处获取所有服务实例(handles)
Service gateway启动后要从cloud controller同步所有的服务实例
请求uri: get 'services/v1/offerings/:label/handles' => 'services#list_handles', :as => :service_list_handles
请求内容:
请求响应:
service gateway获取服务的所有服务实例。每个实例(handle)包括service_id、configuration和credentials三部分。
handles=>[ { :service_id => cfg.name, :configuration => cfg.data, :credentials => cfg.credentials } ]
请求uri: post 'services/v1/offerings/:label/handles/:id' => 'services#update_handle', :as => :service_update_handle
请求内容:
请求内容至少包括以下字段信息
:service_id => cfg.name, :configuration => cfg.data, :credentials => cfg.credentials
1)create 服务实例
post '/gateway/v1/configurations'
2)删除服务实例
delete '/gateway/v1/configurations/:service_id'
3)绑定服务实例
post '/gateway/v1/configurations/:service_id/handles'
4)解绑服务实例
delete '/gateway/v1/configurations/:service_id/handles/:handle_id'
5)创建服务快照
post "/gateway/v1/configurations/:service_id/snapshots"
6)获取服务快照详情
get "/gateway/v1/configurations/:service_id/snapshots/:snapshot_id"
7)列举所有服务快照
get "/gateway/v1/configurations/:service_id/snapshots"
8)将某服务(:service_id)回滚到某个快照(:snapshot_id)
put "/gateway/v1/configurations/:service_id/snapshots/:snapshot_id"
9)删除指定快照
delete "/gateway/v1/configurations/:service_id/snapshots/:snapshot_id"
10)为快照创建序列化的url
post "/gateway/v1/configurations/:service_id/serialized/url/snapshots/:snapshot_id"
11)获取某个服务实例快照的url
get "/gateway/v1/configurations/:service_id/serialized/url/snapshots/:snapshot_id"
12)service gateay从给定url获取序列化数据
put "/gateway/v1/configurations/:service_id/serialized/url"
13)service gateway从请求中获取序列化数据
put "/gateway/v1/configurations/:service_id/serialized/data"
14)获取某个job的详情
get "/gateway/v1/configurations/:service_id/jobs/:job_id"
Service Gateway和Service Node之间的交互主要通过NATS消息。
3)创建服务实例:
#{service_name}.provision.#{@node_id}
4)删除服务实例
#{service_name}.unprovision.#{@node_id}
5)绑定服务实例
#{service_name}.bind.#{@node_id}
6)解绑服务实例
#{service_name}.unbind.#{@node_id}
7)
#{service_name}.restore.#{@node_id}
8)
#{service_name}.purge_orphan.#{@node_id}
1)service node的注册消息
#{service_name}.announce
2)检查孤立实例
#{service_name}.node_handles