KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmsMibComponents > LogicalInterfaceProviderComposition > mgmtSegImpl


1 /*====================================================================
2
3 This file was produced by the OpenCCM CIF_JIMPL generator.
4
5 OpenCCM: The Open CORBA Component Model Platform
6 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
7 Contact: openccm@objectweb.org
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA
23
24 Initial developer(s): Christophe Demarey.
25 Contributor(s): ______________________________________.
26
27 ====================================================================*/

28
29 package ist.coach.coachEmsMibComponents.LogicalInterfaceProviderComposition;
30
31 import intt.itu.itut_x780.CreateError;
32 import intt.itu.itut_x780.UIDType;
33
34 import intt.itu.itut_x780.ApplicationError;
35 import intt.itu.itut_x780.AttributeValueChangeType;
36 import intt.itu.itut_x780.AttributeValueType;
37 import intt.itu.itut_x780.SourceIndicatorType;
38 import intt.itu.itut_x780.OperationalStateTypeHelper;
39 import intt.itu.itut_x780.OperationalStateType;
40
41 import ist.coach.coachEmfCommon.Utils;
42 import ist.coach.coachEmfCommon.StateChangedEventImpl;
43 import ist.coach.coachEmfCommon.StateChangedEventImpl;
44 import ist.coach.coachEmfCommon.ObjectCreationImpl;
45 import ist.coach.coachEmfCommon.ObjectDeletionImpl;
46 import ist.coach.coachEmfCommon.ExceptionMessages;
47 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl;
48 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
49 import ist.coach.coachEmfCommon.DataTypeImpl;
50 import ist.coach.coachEmfServices.SnmpAdapter.DataType;
51 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError;
52
53 import ist.coach.coachEmsMib.LogicalInterfaceValueType;
54 //import ist.coach.coachEmsMib.LogicalInterface_F;
55
//import ist.coach.coachEmsMibComponents.LogicalInterfaceProviderHelper;
56

57 import ist.coach.coachEmsCommon.SnmpIdentifiers;
58 //import ist.coach.coachEmsCommon.LogicalInterfaceValueTypeImpl;
59

60 import org.omg.CosNaming.NameComponent JavaDoc;
61 import org.omg.CORBA.TCKind JavaDoc;
62
63 import org.opennms.protocols.snmp.SnmpSMI;
64
65 import java.util.Hashtable JavaDoc;
66
67 /**
68  * This is the CIDL-based implementation of the
69  * OMG IDL3 CIDL:coach.ist/coachEmsMibComponents/LogicalInterfaceProviderComposition/LogicalInterfaceProviderHome_impl/LogicalInterfaceProvider_impl/mgmtSeg:1.0 segment type.
70  *
71  * @author OpenCCM CIF_Jimpl Compiler.
72  */

73 public class mgmtSegImpl
74      extends ist.coach.coachEmsMibComponents.LogicalInterfaceProviderComposition.mgmtSeg
75 {
76     // ==================================================================
77
//
78
// Internal states.
79
//
80
// ==================================================================
81
org.omg.CORBA.ORB JavaDoc orb = null;
82     // ==================================================================
83
//
84
// Constructors.
85
//
86
// ==================================================================
87

88     public mgmtSegImpl()
89     {
90       orb = org.objectweb.ccm.CORBA.TheORB.getORB();
91     }
92
93     // ==================================================================
94
//
95
// Methods.
96
//
97
// ==================================================================
98

99     /**
100      * Implementation of the ::coachEmsMibComponents::LogicalInterfaceMgmt::create operation.
101      */

102     public void
103     create(org.omg.CosNaming.NameComponent JavaDoc[] name,
104           String JavaDoc objectClass,
105           String JavaDoc[] packages,
106           short deletePolicy,
107           intt.itu.itut_x780.SourceIndicatorType sourceIndicator,
108           org.omg.CosNaming.NameComponent JavaDoc[] superior,
109           int ifIndex,
110           byte[] mgmtIpAddress,
111           int supportedSnmpVersions,
112           int snmpPort,
113         String JavaDoc ifDescr)
114     throws intt.itu.itut_x780.ApplicationError,
115
116            intt.itu.itut_x780.CreateError
117     {
118          //
119
// DONE : implement
120
//
121
ist.coach.coachEmfServices.SnmpAdapter.SnmpTrapDaemon config = null;
122
123         if ((config = get_context().get_connection_config()) == null) {
124             CreateErrorInfoTypeImpl errorCode =
125                 new CreateErrorInfoTypeImpl();
126
127             errorCode.error = new UIDType(
128                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
129                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
130
131             errorCode.details = new String JavaDoc(ExceptionMessages.components_connect_error);
132             throw new intt.itu.itut_x780.CreateError(errorCode);
133         }
134
135         if (LogicalInterfaceProviderImpl.elements.containsKey(Utils.name2string(name))) {
136
137             CreateErrorInfoTypeImpl errorCode =
138                 new CreateErrorInfoTypeImpl();
139
140             errorCode.error = new UIDType(
141                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
142                 intt.itu.itut_x780.CreateErrorConst.duplicateName.value);
143
144             errorCode.details = new String JavaDoc(Utils.name2string(name) +
145              " object already exists.");
146             throw new intt.itu.itut_x780.CreateError(errorCode);
147         }
148
149       //System.err.println("LogicalInterface packages = " + packages.length);
150

151         LogicalInterfaceDataStructure logicalInterfaceData =
152             new LogicalInterfaceDataStructure(
153                 ifIndex,
154                 name,
155                 objectClass,
156                 packages,
157                 sourceIndicator,
158                 deletePolicy,
159                 new String JavaDoc(mgmtIpAddress),
160                 snmpPort,
161                 supportedSnmpVersions,
162                 ifDescr);
163
164         synchronized(LogicalInterfaceProviderImpl.elements) {
165           LogicalInterfaceProviderImpl.elements.put(Utils.name2string(name), logicalInterfaceData);
166         }
167         //System.err.println("LogicalInterfaceProvider setting data FINISHED...!");
168

169         //by digi
170
//ifDescrAny.insert_string(ifDescr);
171
try {
172           org.omg.CORBA.Any JavaDoc ifDescrAny = orb.create_any();
173           //System.err.println("LogicalInterfaceProvider setting any data for " + ifDescr);
174
org.omg.CORBA.OctetSeqHelper.insert(ifDescrAny, ifDescr.getBytes());
175
176             //System.err.println("Trying to register interface with description " +
177
// Utils.name2string(name));
178
config.registerValue(name, new String JavaDoc(mgmtIpAddress), ifDescrAny);
179         }
180         catch (ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) {
181
182             System.err.println("Could not register LogicalInterface " +
183                 Utils.name2string(name) + " to the SNMP Trap Service");
184             System.err.println("Reason = " + snmp_ex.reason);
185
186             ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl();
187
188             error_code.error = new UIDType(
189                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
190                 intt.itu.itut_x780.ApplicationErrorConst.downstreamError.value);
191
192             error_code.details = snmp_ex.reason;
193
194             throw new ApplicationError(error_code);
195         }
196         catch(Exception JavaDoc e) {
197           System.err.println("LogicalInterfaceProvider Exception caught: " + e.getMessage());
198           e.printStackTrace();
199        }
200
201         org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT (System.currentTimeMillis(),
202                     0, (short) 0, (short) 0);
203         get_context().push_objectCreation(new ObjectCreationImpl(eventTime,
204                                                 name,
205                                                 objectClass,
206                                                 LogicalInterfaceProviderImpl.getUniqueNotificationIdentifier(),
207                                                 //logicalInterfaceData.getUniqueNotificationIdentifier(),
208
sourceIndicator,
209                                                 new AttributeValueType[0]));
210
211     }
212
213     /**
214      * Implementation of the ::coachEmfServices::SnmpAdapter::TrapCallback::notifyTrap operation.
215      */

216     public void
217     notifyTrap(org.omg.CosNaming.NameComponent JavaDoc[] name, String JavaDoc community, int trapID, int trapType, ist.coach.coachEmfServices.SnmpAdapter.DataType[] trapData)
218     throws intt.itu.itut_x780.ApplicationError,
219
220            ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
221     {
222        //
223
// DONE : implement
224
//
225

226         String JavaDoc key = Utils.name2string(name);
227
228         if (LogicalInterfaceProviderImpl.elements.containsKey(Utils.name2string(name)) == false) {
229
230             ApplicationErrorInfoTypeImpl errorCode =
231                 new ApplicationErrorInfoTypeImpl();
232
233             errorCode.error = new UIDType(
234                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
235                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
236
237             errorCode.details = new String JavaDoc("object with name " +
238              key + " does not exists.");
239
240             //System.err.println("Object with name " + key + " does not exist!");
241

242             throw new intt.itu.itut_x780.ApplicationError(errorCode);
243         }
244
245         LogicalInterfaceDataStructure data =
246             (LogicalInterfaceDataStructure) LogicalInterfaceProviderImpl.elements.get(key);
247
248         intt.itu.itut_x780.OperationalStateType newValue = null;
249         intt.itu.itut_x780.OperationalStateType oldValue = null;
250
251         if (trapType == LogicalInterfaceProviderImpl.COACH_LINK_UP) {
252             newValue = intt.itu.itut_x780.OperationalStateType.enabled;
253             oldValue = intt.itu.itut_x780.OperationalStateType.disabled;
254         }
255         else
256         if (trapType == LogicalInterfaceProviderImpl.COACH_LINK_DOWN) {
257             newValue = intt.itu.itut_x780.OperationalStateType.disabled;
258             oldValue = intt.itu.itut_x780.OperationalStateType.enabled;
259         }
260         else {
261             System.err.println("LogicalInterface_F down not know how to handle trap of type " +
262                 trapType);
263
264             ApplicationErrorInfoTypeImpl error_code =
265                 new ApplicationErrorInfoTypeImpl();
266
267             error_code.error = new UIDType(
268                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
269                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
270             error_code.details = new String JavaDoc ("LogicalInterface_F does not know how to handle trap of type " + trapType + ".");
271
272             throw new ApplicationError(error_code);
273         }
274
275         long trapTime = 0;
276         boolean trapTimeFound = false;
277
278         for (int i = 0; i < trapData.length; i++) {
279             if (trapData[i].identifier.equals(SnmpIdentifiers.TIME_OID)) {
280                 //System.err.println("Found Time...");
281
org.omg.CORBA.Any JavaDoc value = trapData[i].value;
282
283                 if (value.type().kind().value() != TCKind._tk_longlong) {
284
285                     ApplicationErrorInfoTypeImpl error_code =
286                         new ApplicationErrorInfoTypeImpl();
287
288                     error_code.error = new UIDType(
289                         intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
290                         intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
291
292
293                     error_code.details = new String JavaDoc("Could not retrieve event time " +
294                         "for trap. Object with Snmp Object Identifier " + SnmpIdentifiers.TIME_OID +
295                         " is not of type long, as expected.");
296
297                     //System.err.println("Event time is not of type long, as expected...");
298

299                     throw new ApplicationError(error_code);
300                 }
301
302                 trapTime = value.extract_longlong();
303                 trapTimeFound = true;
304                 break;
305             }
306         }
307
308         if (trapTimeFound == false) {
309
310             System.err.println("Trap Time could not be determined. No such VarBinding");
311
312             ApplicationErrorInfoTypeImpl error_code =
313                 new ApplicationErrorInfoTypeImpl();
314
315             error_code.error = new UIDType(
316                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
317                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
318
319             error_code.details = new String JavaDoc("Could not retrieve event time " +
320                 "for trap.");
321
322             throw new ApplicationError(error_code);
323         }
324
325 // org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(trapTime, 0, (short) 0, (short) 0);
326
org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(),
327                         0,(short) 0,(short) 0);
328
329
330         //int notificationId = data.getUniqueNotificationIdentifier();
331
int notificationId = LogicalInterfaceProviderImpl.getUniqueNotificationIdentifier();
332
333         String JavaDoc sourceClass = data.objectclass;
334
335         SourceIndicatorType sourceIndicator = SourceIndicatorType.unknown;
336
337         org.omg.CORBA.Any JavaDoc oldValue_any = orb.create_any();
338         OperationalStateTypeHelper.insert(oldValue_any, oldValue);
339
340         org.omg.CORBA.Any JavaDoc newValue_any = orb.create_any();
341         OperationalStateTypeHelper.insert(newValue_any, newValue);
342
343         AttributeValueChangeType [] changedValues = new AttributeValueChangeType[1];
344
345         changedValues[0] = new AttributeValueChangeType(
346             "operationalState",
347             oldValue_any,
348             newValue_any);
349
350         StateChangedEventImpl stateChangedEvent = new StateChangedEventImpl(
351             eventTime,
352             name,
353             sourceClass,
354             notificationId,
355             sourceIndicator,
356             changedValues);
357         System.err.println("LogicalInterfaceProvider> Before pushing StateChange event with identifier " +
358             stateChangedEvent.notificationIdentifier + " for " +
359             Utils.name2string(stateChangedEvent.source) + " of objectclass " +
360             stateChangedEvent.sourceClass + " generated after SNMP agent " +
361             "has been up for " + stateChangedEvent.eventTime.time +
362             " caused by an action of type " + sourceIndicator + ".");
363         get_context().push_stateChange(stateChangedEvent);
364
365     }
366
367     /**
368      * Implementation of the ::coachEmfServices::SnmpAdapter::TrapCallback::facade_name operation.
369      */

370     public String JavaDoc
371     facade_name()
372     {
373         //
374
// TODO : Implement
375
//
376
return get_main_segment().facade_name();
377     }
378
379 }
380
Popular Tags