Cloud Foundry service broker开发部署实例解析(下),foundrybroker


通过上篇,我们得到service broker的程序包,之后我们将其部署到CF上,得到真正能使用的市场服务。

发布应用程序

  • 将源代码中的application.properties里的spring.jpa.hibernate.ddl-auto配置为create,编译打包发布到CF上:
cf push samplebroker -p ./cf-sample-servicebroker.jar
  • 创建一个MySQL服务实例,并绑定到此应用上:
cf cs p-mysql 100m-dev samplebrokerdb
cf bs samplebroker samplebrokerdb
cf restart samplebroker
  • 将源代码中的application.properties里的spring.jpa.hibernate.ddl-auto配置为validate,重新编译打包发布到CF上:
cf push samplebroker -p ./cf-sample-servicebroker.jar

初始化服务信息

  • 用ssh登陆Ops Manager的ubuntu,获取服务ID,其中的adminpassword就是Ops Manager的Elastic Runtime的credential页里的UAA模块admin的密码,samplebroker.open.mydomain.com是上一步发布的应用的域名
curl -i -H "Content-type: application/json" -b cookies.txt -X GET http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog
  • 为对应的服务ID添加3个服务计划,其中的GUID是上一步中获取的,具体计划的详细信息请根据实际的资源情况进行修改
curl -i -H "Content-type: application/json" -b cookies.txt -X POST http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans -d '{"name" : "bronze","description" : "all apps share 1 RV node","metadata" : {"max_size" : "10240M","connections" : 100,"bullets" : ["Each app has its own credential","100 apps at most"],"displayName":"Bronze"}}'
curl -i -H "Content-type: application/json" -b cookies.txt -X POST http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans -d '{"name" : "silver","description" : "10 apps share 1 RV node","metadata" : {"max_size" : "20480M","connections" : 10,"bullets" : ["Each app has its own credential","10 apps for 1 RV node at most"],"displayName":"Silver"}}'
curl -i -H "Content-type: application/json" -b cookies.txt -X POST http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans -d '{"name" : "gold","description" : "Each apps has its own RV node","metadata" : {"max_size" : "30720M","connections" : 1,"bullets" : ["Each app has its own credential","1 app for 1 RV node at most"],"displayName":"Gold"}}'
  • 根据前三条命令的输出里的ID信息为每个服务计划添加单价
curl -i -H "Content-type: application/json" -b cookies.txt -X PUT http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans/29cf4cb9-4d85-42a2-89b8-65db630357c5/costs -d '{"amount":{"usd":1.0},"unit":"day"}'
curl -i -H "Content-type: application/json" -b cookies.txt -X PUT http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans/12dd3ed1-7076-409e-8a64-568c3edd82e4/costs -d '{"amount":{"usd":10.0},"unit":"day"}'
curl -i -H "Content-type: application/json" -b cookies.txt -X PUT http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans/b4897b00-b6cc-4295-9dbb-bf4084fe4c97/costs -d '{"amount":{"usd":100.0},"unit":"day"}'
  • 对于每一个服务计划,添加资源池,其中的资源信息按照实际情况进行修改
curl -i -H "Content-type: application/json" -b cookies.txt -X PUT http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans/29cf4cb9-4d85-42a2-89b8-65db630357c5/pool -d '{"kcxpaddr":"10.23.119.61","kcxpport":"21000","rvipaddr":"10.23.119.57","rvport":"7500","username":"sxiang","password":"888888"}'
curl -i -H "Content-type: application/json" -b cookies.txt -X PUT http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans/12dd3ed1-7076-409e-8a64-568c3edd82e4/pool -d '{"kcxpaddr":"10.23.119.61","kcxpport":"21000","rvipaddr":"10.23.119.57","rvport":"7500","username":"sxiang","password":"888888"}'
curl -i -H "Content-type: application/json" -b cookies.txt -X PUT http://admin:adminpassword@samplebroker.open.mydomain.com/v2/catalog/services/590017dc-1fd2-4cbc-99e6-ae668107cc7a/plans/b4897b00-b6cc-4295-9dbb-bf4084fe4c97/pool -d '{"kcxpaddr":"10.23.119.61","kcxpport":"21000","rvipaddr":"10.23.119.57","rvport":"7500","username":"sxiang","password":"888888"}'

发布service

  • 创建service broker
cf create-service-broker p-sample admin adminpassword https://samplebroker.open.mydomain.com
  • 获取3个服务计划的GUID
cf curl /v2/service_plans
  • 将3个服务计划设置为可见
cf curl /v2/service_plans/54beb2e7-a5c5-40c4-9a9b-e12c8edef4be -X PUT -d '{"public":true}'

扩容

  • 扩容时,需要使用a步增加资源池的容量,然后修改MySQL中的数据,再重启service broker应用

到此为止,在CLI或者GUI的maketplace里,就能找到这个p-sample的服务了。声明,本文中的源代码来源于github的开源代码,笔者进行了修正和完善。

相关内容