zStack 扩展开发流程-zstack-java部分
2016-12-07 16:16
447 查看
本部分接上一部分zstack-dashboard部分的开发。
由于账户管理与zstack中的identity一致,因此直接在上面进行扩展。如果想单独做一个完全独立的模块,流程也差不多。
举例:
APICreatePubAccountMsg
根据其他范例,补充完成APIQueryPubAccountReply.class,PubAccountInventory.class。
identity模块的manager函数为AccountManagerImpl。这类的函数需要继承service类。
在其中添加处理新消息的handle函数。
Notice :只有在所有的API消息都有对应的handle函数之后,才能通过编译
updating
由于账户管理与zstack中的identity一致,因此直接在上面进行扩展。如果想单独做一个完全独立的模块,流程也差不多。
API注册
文件位置 zStack/conf/serviceConfig/identity.xml,在其中添加需要有的API。<?xml version="1.0" encoding="UTF-8"?> <service xmlns="http://zstack.org/schema/zstack"> <id>identity</id> <interceptor>AccountManager</interceptor> <!--ID 是唯一的,唯一标识一类服务--> <interceptor>PubAccountApiInterceptor</interceptor> <!-- PubAccountApiInterceptor需要实现,主要处理API的请求--> <message> <name>org.zstack.header.identity.APIQueryPubAccountMsg</name> <serviceId>query</serviceId> </message> <message> <name>org.zstack.header.identity.APICreatePubAccountMsg</name> </message> <message> <name>org.zstack.header.identity.APIDeletePubAccountMsg</name> </message> </service>
创建对应消息的JAVA类
在zStack/header/src/main/java/org/zstack/header/identity文件夹下面分别创建上述消息的类。举例:
APICreatePubAccountMsg
package org.zstack.header.identity; import org.zstack.header.query.APIQueryMessage; import org.zstack.header.query.AutoQuery; /** * Created by frank on 7/14/2015. */ @AutoQuery(replyClass = APIQueryPubAccountReply.class, inventoryClass = PubAccountInventory.class) public class APIQueryPubAccountMsg extends APIQueryMessage { }
根据其他范例,补充完成APIQueryPubAccountReply.class,PubAccountInventory.class。
添加handle函数
一般一个模块,会有一个主manager类来处理这个模块的所有信息。因此如果我们要处理新添加的消息,则需要在对应的manager类中添加handle函数。identity模块的manager函数为AccountManagerImpl。这类的函数需要继承service类。
在其中添加处理新消息的handle函数。
private void handleApiMessage(APIMessage msg) { if (msg instanceof APICreateAccountMsg) { handle((APICreateAccountMsg) msg); }else if (msg instanceof APICreatePubAccountMsg) { //这里就是新添加的方法 handle((APICreatePubAccountMsg) msg); } else if (msg instanceof APIListAccountMsg) { handle((APIListAccountMsg) msg); } else if (msg instanceof APIListUserMsg) { handle((APIListUserMsg) msg); } else if (msg instanceof APIListPolicyMsg) { handle((APIListPolicyMsg) msg); } else if (msg instanceof APILogInByAccountMsg) { handle((APILogInByAccountMsg) msg); } else if (msg instanceof APILogInByUserMsg) { handle((APILogInByUserMsg) msg); } else if (msg instanceof APILogOutMsg) { handle((APILogOutMsg) msg); } else if (msg instanceof APIValidateSessionMsg) { handle((APIValidateSessionMsg) msg); } else if (msg instanceof APICheckApiPermissionMsg) { handle((APICheckApiPermissionMsg) msg); } else if (msg instanceof APIGetResourceAccountMsg) { handle((APIGetResourceAccountMsg) msg); } else if (msg instanceof APIChangeResourceOwnerMsg) { handle((APIChangeResourceOwnerMsg) msg); } else { bus.dealWithUnknownMessage(msg); }
数据库
添加了新的模块,一般也要添加数据库的表。添加数据库
在zStack/conf/db/下的sql文件中添加数据库的描述性文件。添加presis配置文件
在zStack/conf/persistence.xml中添加新的表。Notice :只有在所有的API消息都有对应的handle函数之后,才能通过编译
updating
相关文章推荐
- php7 扩展类的写法[2]
- php7 类的方法传参[3]
- php7 读取php.ini[4]
- C#、ASP.NET通用扩展工具类之TypeParse
- Lua编程示例(二):面向对象、metatable对表进行扩展
- Windows Powershell扩展类型系统
- C#、ASP.NET通用扩展工具类之LogicSugar
- SQL Server下几个危险的扩展存储过程
- jQuery 学习第七课 扩展jQuery的功能 插件开发
- 运行Node.js的IIS扩展iisnode安装配置笔记
- 基于MySql的扩展功能生成全局ID
- jquery通过扩展select控件实现支持enter或focus选择的方法
- 一个扩展时间段的dir命令的vbs脚本
- Ruby中使用SWIG编写ruby扩展模块实例
- php安装php_rar扩展实现rar文件读取和解压的方法
- PHP memcache扩展的三种安装方法
- PHP基于mssql扩展远程连接MSSQL的简单实现方法
- 用C/C++扩展你的PHP 为你的php增加功能
- .NET 扩展实现代码
- Node.js Addons翻译(C/C++扩展)