当前位置:   article > 正文

python华为corba接口_Huawei T2000 Corba 接口客户端开发

python 调用corba

步骤1:

1、根据idl生成客户端代理(stub)和服务器框架(skeleton)

idl来源《OptiX iManager T2000 V200R007C03 Northbound CORBA Interface Reference Guide》

执行下面的命令来生成客户端代理(stub)和服务器框架(skeleton):

idlj -f all myIDL.idl

-f参数用来指定生成的内容,all包括客户端的本地代理和服务器框架。如果不加-f all参数的话,不会生成POA那个类。

"%JAVA_HOME%"\bin\idlj.exe -f all CosEventChannelAdmin.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosEventComm.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNaming.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotification.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotifyChannelAdmin.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotifyComm.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotifyFilter.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosTrading.idl

"%JAVA_HOME%"\bin\idlj.exe -f all orb.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CircuitCutMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all common.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosEventChannelAdmin.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosEventComm.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNaming.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotification.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotifyChannelAdmin.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotifyComm.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosNotifyFilter.idl

"%JAVA_HOME%"\bin\idlj.exe -f all CosTrading.idl

"%JAVA_HOME%"\bin\idlj.exe -f all emsMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all emsSession.idl

"%JAVA_HOME%"\bin\idlj.exe -f all emsSessionFactory.idl

"%JAVA_HOME%"\bin\idlj.exe -f all encapsulationLayerLink.idl

"%JAVA_HOME%"\bin\idlj.exe -f all equipment.idl

"%JAVA_HOME%"\bin\idlj.exe -f all flowDomain.idl

"%JAVA_HOME%"\bin\idlj.exe -f all flowDomainFragment.idl

"%JAVA_HOME%"\bin\idlj.exe -f all globaldefs.idl

"%JAVA_HOME%"\bin\idlj.exe -f all guiCutThrough.idl

"%JAVA_HOME%"\bin\idlj.exe -f all HW_controlPlaneMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all HW_mstpInventoryMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all HW_mstpProtectionMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all HW_mstpServiceMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all HW_securityMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all maintenanceOps.idl

"%JAVA_HOME%"\bin\idlj.exe -f all managedElement.idl

"%JAVA_HOME%"\bin\idlj.exe -f all managedElementManager.idl

"%JAVA_HOME%"\bin\idlj.exe -f all mtnmVersion.idl

"%JAVA_HOME%"\bin\idlj.exe -f all multiLayerSubnetwork.idl

"%JAVA_HOME%"\bin\idlj.exe -f all nmsSession.idl

"%JAVA_HOME%"\bin\idlj.exe -f all notifications.idl

"%JAVA_HOME%"\bin\idlj.exe -f all orb.idl

"%JAVA_HOME%"\bin\idlj.exe -f all performance.idl

"%JAVA_HOME%"\bin\idlj.exe -f all protection.idl

"%JAVA_HOME%"\bin\idlj.exe -f all session.idl

"%JAVA_HOME%"\bin\idlj.exe -f all subnetworkConnection.idl

"%JAVA_HOME%"\bin\idlj.exe -f all terminationPoint.idl

"%JAVA_HOME%"\bin\idlj.exe -f all topologicalLink.idl

"%JAVA_HOME%"\bin\idlj.exe -f all topologyManagementMgr.idl

"%JAVA_HOME%"\bin\idlj.exe -f all trafficDescriptor.idl

"%JAVA_HOME%"\bin\idlj.exe -f all transmissionParameters.idl

由于flowDomain.idl存在bug,因此需要修正。

搜索flowDomain.idl中的关键字flowDomain

找到

void getFlowDomain(

in globaldefs::NamingAttributes_T fdName,

out FlowDomain_T flowDomain)

raises(globaldefs::ProcessingFailureException);

再找

void getFDfromMFD(

in globaldefs::NamingAttributes_T mfdName,

out FlowDomain_T flowDomain )

raises(globaldefs::ProcessingFailureException);

将红体字的flowDomain修改为flowDomains

2、eclipse中新建java项目,将生成的java文件复制到src目录下

3、新建类test/NmsSessionImpl.java,父类为NmsSession_IPOA

4、新建类test/ClientTest.java,选中“public static void main(String args[])”

内容如下:

package test

import java.io.UnsupportedEncodingException;

import java.util.Date;

import managedElement.ManagedElementIterator_IHolder;

import managedElement.ManagedElementList_THolder;

import managedElement.ManagedElement_T;

import managedElementManager.ManagedElementMgr_I;

import managedElementManager.ManagedElementMgr_IHelper;

import multiLayerSubnetwork.SubnetworkIterator_IHolder;

import multiLayerSubnetwork.SubnetworkList_THolder;

import nmsSession.NmsSession_I;

import nmsSession.NmsSession_IPOA;

import notifications.EventIterator_IHolder;

import notifications.EventList_THolder;

import notifications.PerceivedSeverity_T;

import org.omg.CORBA.Any;

import org.omg.CORBA.IntHolder;

import org.omg.CORBA.ORB;

import org.omg.CORBA.Policy;

import org.omg.CORBA.SystemException;

import org.omg.PortableServer.POA;

import org.omg.PortableServer.POAHelper;

import org.omg.PortableServer.POAManagerPackage.AdapterInactive;

import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;

import org.omg.PortableServer.POAPackage.InvalidPolicy;

import common.Common_IHolder;

import CosNaming.NameComponent;

import CosNaming.NamingContext;

import CosNaming.NamingContextHelper;

import CosNotification.Property;

import CosNotification.StructuredEvent;

import CosNotifyChannelAdmin.AdminLimitExceeded;

import CosNotifyChannelAdmin.AdminNotFound;

import CosNotifyChannelAdmin.ClientType;

import CosNotifyChannelAdmin.ConsumerAdmin;

import CosNotifyChannelAdmin.EventChannel;

import CosNotifyChannelAdmin.EventChannelHolder;

import CosNotifyChannelAdmin.ProxySupplier;

import CosNotifyChannelAdmin.StructuredProxyPushSupplier;

import CosNotifyChannelAdmin.StructuredProxyPushSupplierHelper;

import emsMgr.EMSMgr_I;

import emsMgr.EMSMgr_IHelper;

import emsMgr.EMS_T;

import emsMgr.EMS_THolder;

import emsSession.EmsSession_I;

import emsSession.EmsSession_IHolder;

import emsSession.EmsSession_IPackage.managerNames_THolder;

import emsSessionFactory.EmsSessionFactory_I;

import emsSessionFactory.EmsSessionFactory_IHelper;

import equipment.EquipmentInventoryMgr_I;

import globaldefs.NameAndStringValue_T;

import globaldefs.ProcessingFailureException;

public class ClientTest {

static ORB orb;

static EMSMgr_I emsMgr = null;

static EquipmentInventoryMgr_I equipmentInventoryMgr = null;

static EmsSession_I emsSession=null;

static EMS_THolder emsHolder = null;

static EMS_T ems = null;

static EventChannel notifChannel = null;

static EventChannelHolder chanHolder = new EventChannelHolder();

static ConsumerAdmin cadmin = null;

static IntHolder id = null;

static ProxySupplier baseSupplier = null;

static StructuredProxyPushSupplier structuredProxyPushSupplier = null;

static ManagedElementMgr_I managedElementMgr=null;

static StructuredPushConsumerImpl structProxyPushConsumer = null;

static POA rpoa = null;

static POA poa = null;

static Date start_time=new Date();

static Date end_time=new Date();

public static void testCorba() throws UnsupportedEncodingException{

//建立连接登录、建立消息通道

try {

String[] args = new String[2];

args[0] = "-ORBInitRef";

args[1] = "NameService=corbaloc::10.0.1.1:12001/NameService";

orb = org.omg.CORBA.ORB.init(args, null);

} catch (SystemException ex) {

System.out.println("初始化ORB对象异常!");

}

NamingContext namingContext = null;

org.omg.CORBA.Object objRef = null;

try {

objRef = orb.resolve_initial_references("NameService");

namingContext = NamingContextHelper.narrow(objRef);

System.out.println("获取取名字服务成功:"+namingContext);

}catch (org.omg.CORBA.ORBPackage.InvalidName ex) {

System.out.println("获取名字服务索引异常!");

ex.printStackTrace();

}

NameComponent[] path = new NameComponent[5];

path[0] = new NameComponent("TMF_MTNM", "Class");

path[1] = new NameComponent("HUAWEI", "Vendor");

path[2] = new NameComponent("Huawei/T2000", "EmsInstance");

path[3] = new NameComponent("2.0", "Version");

path[4] = new NameComponent("Huawei/T2000", "EmsSessionFactory_I");

EmsSessionFactory_I emsSessionFactory_I = null;

org.omg.CORBA.Object obj = null;

try{

obj = namingContext.resolve(path);

System.out.println("obj=>"+obj);

emsSessionFactory_I = EmsSessionFactory_IHelper.narrow(obj);

System.out.println("emsSessionFactory_I=>"+emsSessionFactory_I);

}catch(Exception e){

e.printStackTrace();

}

EmsSession_IHolder sessionHolder = new EmsSession_IHolder();

//Log In and Retrieve EmsSession

try {

NmsSession_IPOA pNmsSessionServant = new NmsSessionImpl();

NmsSession_I nmsSession = pNmsSessionServant._this(orb);

//用户名,密码

if (emsSessionFactory_I != null){

emsSessionFactory_I.getEmsSession("test","test", nmsSession, sessionHolder);

System.out.println("NMSsession ---" + nmsSession.toString()+"\nVersion:"+emsSessionFactory_I.getVersion());

emsSession = sessionHolder.value;

}

else{

return;

}

}catch (globaldefs.ProcessingFailureException ex) {

System.out.println("获取EmsSession引用对象,异常!---ProcessingFailureException---");

System.out.println("可能是用户名或者密码错误,或者权限不够[Corba OSS用户],或者已登陆的用户还未退出!");

System.out.println(ex.toString());

showMessage(ex.errorReason);

}

Common_IHolder common_IHolder = new Common_IHolder();

try {

//Retrieve List of Managers

managerNames_THolder supportedManagerList = new managerNames_THolder();

emsSession.getSupportedManagers(supportedManagerList);

String []managers=supportedManagerList.value;

for (int i = 0; i < managers.length; i++ )

{

System.out.print("Manager ");

System.out.print(i);

System.out.println(" " + managers[i]);

}

//返回所有网元

emsSession.getManager("ManagedElement",common_IHolder);

managedElementMgr=ManagedElementMgr_IHelper.narrow(common_IHolder.value);

ManagedElementList_THolder meList=new ManagedElementList_THolder();

ManagedElementIterator_IHolder meIt=new ManagedElementIterator_IHolder();

managedElementMgr.getAllManagedElements(how_many, meList, meIt);

ManagedElement_T[] me= meList.value;

for (int i = 0; i < me.length; i++ ) {

String nativeEMSName=me[i].nativeEMSName;

String procuctName=me[i].productName;

NameAndStringValue_T[] name=me[i].name;

showMessage(nativeEMSName+","+procuctName+","+name[0].name+"|"+name[0].value+","+name[1].name+"|"+name[1].value);

}

/*

//获取网元信息

emsSession.getManager("EquipmentInventory",common_IHolder);

equipmentInventoryMgr = EquipmentInventoryMgr_IHelper.narrow(common_IHolder.value);

emsHolder = new EMS_THolder();

NameAndStringValue_T[] meOrHolderName=new NameAndStringValue_T[2];

meOrHolderName[0]=new NameAndStringValue_T();

meOrHolderName[0].name="EMS";

meOrHolderName[0].value="Huawei/T2000";

meOrHolderName[1]=new NameAndStringValue_T();

meOrHolderName[1].name="ManagedElement";

meOrHolderName[1].value="3145790";

EquipmentOrHolderList_THolder eqList=new EquipmentOrHolderList_THolder();

EquipmentOrHolderIterator_IHolder eqIt=new EquipmentOrHolderIterator_IHolder();

start_time=new Date();

equipmentInventoryMgr.getAllEquipment(meOrHolderName, how_many, eqList, eqIt);

end_time=new Date();

System.out.println("getAllEquipment:"+start_time.toString()+"-"+end_time.toString());

EquipmentOrHolder_T[] equipments=eqList.value;

for (int i=0;i< equipments.length;i++ ){

try{

EquipmentHolder_T equipmentHolder=equipments[i].holder();

String holderType=equipmentHolder.holderType;

String nativeEMSName=equipmentHolder.nativeEMSName;

NameAndStringValue_T[] name=equipmentHolder.name;

showMessage(holderType+","+nativeEMSName+","+name[0].name+"|"+name[0].value+","+name[1].name+"|"+name[1].value);

}

catch(Exception e){

continue;

}

}

*/

/*

//查询网管系统中所有未结束的告警和未结束的TCA 事件

String[] excludeProbCauseList=new String[0];

PerceivedSeverity_T[] excludeSeverityList=new PerceivedSeverity_T[0];

EventList_THolder eventList=new EventList_THolder();

EventIterator_IHolder eventIt=new EventIterator_IHolder();

how_many=10;

start_time=new Date();

emsMgr.getAllEMSAndMEActiveAlarms(excludeProbCauseList, excludeSeverityList, how_many, eventList, eventIt);

end_time=new Date();

System.out.println("getAllEMSAndMEActiveAlarms:"+start_time.toString()+"-"+end_time.toString());

StructuredEvent[] events= eventList.value;

for (int i=0;i

Property[] propertyList= events[i].filterable_data;

showMessage("event:"+i);

for (int j=0;j

try{

showMessage(""+propertyList[j].name+","+ propertyList[j].value);

Object prop_obj=propertyList[j].value.extract_Object();

}

catch(Exception e){

continue;

}

}

}

*/

} catch (ProcessingFailureException e) {

System.out.println("Processing Exception" + e.getMessage());

e.printStackTrace();

showMessage(e.errorReason);

}

finally{

emsSession.endSession();

}

}

/**

* @param msg

* @throws UnsupportedEncodingException

* 编码转换,以显示中文

*/

public static void showMessage(String msg) throws UnsupportedEncodingException {

byte[] bytes=msg.getBytes("ISO-8859-1");

String rlt = new String(bytes, "GBK");

System.out.println(rlt);

}

public static String decodeText(String src) throws UnsupportedEncodingException {

byte[] bytes=src.getBytes("ISO-8859-1");

String rlt = new String(bytes, "GBK");

return rlt;

}

public static void main(String[] args) throws UnsupportedEncodingException {

testCorba();

}

}

/**

* 前提:

* 1.license支持Corba

* 2.Corba服务开启:12001,12002,12003端口

* 3.可正常访问系统的用户名及密码(该用户当前未登陆)

* 4.客户端程序所在客户机的IP在“访问控制列表”允许的范围内

*

*/

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/496842
推荐阅读
相关标签
  

闽ICP备14008679号