zStack 扩展开发流程-zstack-java部分

来源:互联网 发布:睡觉流口水 知乎 编辑:程序博客网 时间:2024/06/05 00:52

本部分接上一部分zstack-dashboard部分的开发。
由于账户管理与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

0 0
原创粉丝点击