SimpleDao

参考

https://github.com/cloudera/cm_ext

https://github.com/cloudera/cm_csds

生成parcel

  1. # 需要在目标文件夹内新建meta文件,并在meta中新建文件parcel.json,文件内容需要自己参考资料填写
  2. # 验证文件
  3. java -jar cm_ext/validator/target/validator.jar -p HELLO-1.0/meta/parcel.json
  4. # 验证目录
  5. java -jar cm_ext/validator/target/validator.jar -d HELLO-1.0
  6. # 打包parcel
  7. tar zcvf HELLO-1.0-el6.parcel HELLO-1.0 --owner=root --group=root
  8. # 验证
  9. java -jar cm_ext/validator/target/validator.jar -f HELLO-1.0-el6.parcel

对外提供http的parcel服务

  1. # 生成manifest.json
  2. python cm_ext/make_manifest/make_manifest.py /data/root
  3. # 提供http服务
  4. python -m SimpleHTTPServer 10001

配置cm的parcel

添加上述http地址,即可分发parcel

生成CSD

  1. # 新建目录,内部结构为
  2. ├── descriptor
  3. └── service.sdl
  4. └── scripts
  5. └── control.sh
  6. # 文件内容需要自己参考资料填写
  7. #验证
  8. java -jar cm_ext/validator/target/validator.jar -s csd/HELLO-1.0/descriptor/service.sdl
  9. # 打包
  10. jar -cvf HELLO-1.0.jar *
  11. # 复制到csd目录
  12. ~~~cp HELLO-1.0.jar /opt/cloudera/csd/
  13. ### 重启cm服务即可生效
  14. ### 示例
  15. HELLO-1.0/meta/parcel.json
  16. ~~~ json
  17. {
  18. "schema_version":1,
  19. "name":"HELLO",
  20. "version":"1.0",
  21. "setActiveSymlink":true,
  22. "conflicts":"",
  23. "provides":[
  24. "hello"
  25. ],
  26. "scripts":{
  27. "defines":"hello_env.sh"
  28. },
  29. "packages":[
  30. {
  31. "name":"hello",
  32. "version":"1.0"
  33. }
  34. ],
  35. "components":[
  36. {
  37. "name":"hello",
  38. "version":"1.0",
  39. "pkg_version":"1.0",
  40. "pkg_release":"1.0"
  41. }
  42. ],
  43. "users":{},
  44. "groups":[]
  45. }

HELLO-1.0/meta/hello_env.sh

  1. HELLO_DIRNAME=${PARCEL_DIRNAME}
  2. export CDH_HELLO_HOME=$PARCELS_ROOT/$HELLO_DIRNAME

cat descriptor/service.sdl

  1. {
  2. "name":"HELLO",
  3. "label":"Hello",
  4. "description":"The hello service",
  5. "version":"1.1",
  6. "runAs":{
  7. "user":"root",
  8. "group":"root"
  9. },
  10. "compatibility":{
  11. "generation":1
  12. },
  13. "icon":"images/icon.png",
  14. "parcel" : {
  15. "requiredTags" : [ "hello" ],
  16. "optionalTags" : [ "hello-plugin" ]
  17. },
  18. "parameters":[
  19. {
  20. "name":"service_var1",
  21. "label":"Service Var1 Label",
  22. "description":"Service Var1 Description",
  23. "configName":"service.var1.config",
  24. "type":"string",
  25. "default":"this is a default"
  26. }
  27. ],
  28. "roles":[
  29. {
  30. "name":"HELLO_SERVICE",
  31. "label":"hello service",
  32. "pluralLabel":"hello services",
  33. "parameters":[
  34. {
  35. "name":"init_content",
  36. "label":"conf1",
  37. "description":"conf",
  38. "type":"string",
  39. "default": "defaultiii"
  40. }
  41. ],
  42. "startRunner":{
  43. "program":"scripts/control.sh",
  44. "args":[
  45. "start"
  46. ],
  47. "environmentVariables":{
  48. "PORT": "10002"
  49. }
  50. }
  51. }
  52. ]
  53. }

scripts/control.sh

  1. #!/bin/bash
  2. CMD=$1
  3. export HELLO_HOME=${HELLO_HOME:-$CDH_HELLO_HOME}
  4. case $CMD in
  5. (start)
  6. echo "Starting Hello123"
  7. exec python $HELLO_HOME/src/hello.py
  8. ;;
  9. (*)
  10. echo "Don't understand [$CMD]"
  11. ;;
  12. esac