KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmsMibComponents > IpNodeProviderComposition > 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.IpNodeProviderComposition;
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.ManagedObjectValueType;
36 import intt.itu.itut_x780.AttributeValueChangeType;
37 import intt.itu.itut_x780.AttributeValueType;
38 import intt.itu.itut_x780.SourceIndicatorType;
39 import intt.itu.itut_x780.OperationalStateTypeHelper;
40
41 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
42
43 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl;
44 import ist.coach.coachEmfCommon.Utils;
45 import ist.coach.coachEmfCommon.ExceptionMessages;
46 import ist.coach.coachEmfCommon.ObjectCreationImpl;
47 import ist.coach.coachEmfCommon.StateChangedEventImpl;
48
49 import ist.coach.coachEmsCommon.SnmpIdentifiers;
50 import org.omg.CORBA.TCKind JavaDoc;
51 /**
52  * This is the CIDL-based implementation of the
53  * OMG IDL3 CIDL:coach.ist/coachEmsMibComponents/IpNodeProviderComposition/IpNodeProviderHome_impl/IpNodeProvider_impl/mgmtSeg:1.0 segment type.
54  *
55  * @author OpenCCM CIF_Jimpl Compiler.
56  */

57 public class mgmtSegImpl
58      extends ist.coach.coachEmsMibComponents.IpNodeProviderComposition.mgmtSeg
59 {
60     // ==================================================================
61
//
62
// Internal states.
63
//
64
// ==================================================================
65
org.omg.CORBA.ORB JavaDoc orb = null;
66     // ==================================================================
67
//
68
// Constructors.
69
//
70
// ==================================================================
71

72     public mgmtSegImpl()
73     {
74         orb = org.objectweb.ccm.CORBA.TheORB.getORB();
75     }
76
77     // ==================================================================
78
//
79
// Methods.
80
//
81
// ==================================================================
82

83     /**
84      * Implementation of the ::coachEmsMibComponents::IpNodeMgmt::create operation.
85      */

86
87     public void
88     create( org.omg.CosNaming.NameComponent JavaDoc[] name,
89                 String JavaDoc objectClass,
90                 java.lang.String JavaDoc[] packages,
91                 short deletePolicy,
92                 intt.itu.itut_x780.SourceIndicatorType sourceIndicator,
93                 java.lang.String JavaDoc domainName,
94                 java.lang.String JavaDoc hostname,
95                 byte[] managementIPAddress,
96                 int supportedSnmpVersions,
97                 intt.itu.itut_x780.AdministrativeStateType administrativeState,
98                 java.lang.String JavaDoc userLabel,
99                 java.lang.String JavaDoc vendorName,
100                 java.lang.String JavaDoc version,
101                 java.lang.String JavaDoc locationName,
102                 int snmpPort,
103                 java.lang.String JavaDoc sysName,
104                 java.lang.String JavaDoc sysContact)
105     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError
106     {
107         //
108
// DONE : implement
109
//
110
ist.coach.coachEmfServices.SnmpAdapter.SnmpTrapDaemon config = null;
111                 if ((config = get_context().get_connection_config()) == null) {
112             CreateErrorInfoTypeImpl errorCode =
113                 new CreateErrorInfoTypeImpl();
114
115             errorCode.error = new UIDType(
116                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
117                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
118
119             errorCode.details = new String JavaDoc(ExceptionMessages.components_connect_error);
120             throw new intt.itu.itut_x780.CreateError(errorCode);
121         }
122         boolean sysInfoSetPackageIsSupported = false;
123
124
125         if (IpNodeProviderImpl.elements.containsKey(Utils.name2string(name))) {
126
127             CreateErrorInfoTypeImpl errorCode =
128                 new CreateErrorInfoTypeImpl();
129
130             errorCode.error = new UIDType(
131                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
132                 intt.itu.itut_x780.CreateErrorConst.duplicateName.value);
133
134             errorCode.details = new String JavaDoc(Utils.name2string(name) +
135                 " object already exists.");
136             throw new intt.itu.itut_x780.CreateError(errorCode);
137
138         }
139
140         IpNodeDataStructure ipNodeData = new IpNodeDataStructure(
141                                                 domainName,
142                                                 hostname,
143                                                 managementIPAddress,
144                                                 name,
145                                                 packages,
146                                                 supportedSnmpVersions,
147                                                 administrativeState,
148                                                 userLabel,
149                                                 vendorName,
150                                                 version,
151                                                 locationName,
152                                                 snmpPort,
153                                                 sysName,
154                                                 sysContact,
155                                                 objectClass,
156                                                 deletePolicy,
157                                                 sourceIndicator,
158                                                 intt.itu.itut_x780.OperationalStateType.enabled);
159         synchronized(IpNodeProviderImpl.elements) {
160           IpNodeProviderImpl.elements.put(Utils.name2string(name), ipNodeData);
161         }
162         //System.err.println("IpNodeFacade>Before registering to the SNMP Trap service");
163

164         String JavaDoc ipAddress = new String JavaDoc();
165         if (managementIPAddress != null)
166             ipAddress = new String JavaDoc(managementIPAddress);
167
168         try {
169             config.registerIP(name, ipAddress);
170         }
171         catch( ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) {
172             System.err.println("Could not register IpNode " +
173                 Utils.name2string(name) + " to the SNMP Trap Service");
174             System.err.println("Reason= " + snmp_ex.reason);
175             ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl();
176             error_code.error = new UIDType(
177                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
178                 intt.itu.itut_x780.ApplicationErrorConst.downstreamError.value);
179
180             error_code.details = snmp_ex.reason;
181
182             throw new ApplicationError(error_code);
183         }
184
185         org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(),
186                     0,(short) 0,(short) 0);
187
188         //System.err.println("IpNodeProvider attempts to push object creation alarm...");
189
get_context().push_objectCreation(new ObjectCreationImpl(eventTime, name,
190                                         objectClass,
191                                         IpNodeProviderImpl.getUniqueNotificationIdentifier(),
192                                         //ipNodeData.getUniqueNotificationIdentifier(),
193
sourceIndicator,
194                                         new AttributeValueType[0]));
195
196         //System.err.println("IpNodeProvider finished create operations...");
197
}
198
199     /**
200      * Implementation of the ::coachEmfServices::SnmpAdapter::TrapCallback::notifyTrap operation.
201      */

202     public void
203     notifyTrap(org.omg.CosNaming.NameComponent JavaDoc[] name,
204                 java.lang.String JavaDoc community,
205                 int trapID, int trapType,
206             ist.coach.coachEmfServices.SnmpAdapter.DataType[] trapData)
207     throws intt.itu.itut_x780.ApplicationError, ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
208     {
209         //
210
// DONE : implement
211
//
212

213         System.err.println("IpNode_F: Notify trap is called for " +
214             Utils.name2string(name));
215
216         String JavaDoc key = Utils.name2string(name);
217
218         if (IpNodeProviderImpl.elements.containsKey(key) == false) {
219
220             ApplicationErrorInfoTypeImpl error_code =
221                 new ApplicationErrorInfoTypeImpl();
222
223             error_code.error = new UIDType(
224                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
225                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
226
227             error_code.details = new String JavaDoc ("object with name" +
228             key + " does not exist.");
229
230             throw new ApplicationError(error_code);
231         }
232
233         IpNodeDataStructure data = (IpNodeDataStructure) IpNodeProviderImpl.elements.get(key);
234
235         intt.itu.itut_x780.OperationalStateType oldValue = data.operationalState;
236
237         intt.itu.itut_x780.OperationalStateType newValue = null;
238
239
240         if (trapType == IpNodeProviderImpl.COLDSTART_TRAP) {
241
242             newValue = intt.itu.itut_x780.OperationalStateType.enabled;
243
244         }
245         else
246         if (trapType == IpNodeProviderImpl.NETSNMP_SHUTDOWN_TRAP) {
247
248             newValue = intt.itu.itut_x780.OperationalStateType.disabled;
249
250         }
251         else {
252
253             System.err.println("IpNode_F does not know how to handle trap of type " +
254                 trapType);
255
256             ApplicationErrorInfoTypeImpl error_code =
257                 new ApplicationErrorInfoTypeImpl();
258
259             error_code.error = new UIDType(
260             intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
261             intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
262
263             error_code.details = new String JavaDoc ("IpNode_F does not know how to handle" +
264             " trap of type " + trapType + ".");
265
266             throw new ApplicationError(error_code);
267
268         }
269
270         if (newValue == oldValue) {
271
272             //System.err.println("No value change occured. Old value is equal to new one.");
273

274             ApplicationErrorInfoTypeImpl error_code =
275                 new ApplicationErrorInfoTypeImpl();
276
277             error_code.error = new UIDType(
278             intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
279             intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
280
281             error_code.details = new String JavaDoc (" Cannot emmit StateChange Event when no" +
282                 " state change has occured for IpNode with name " +
283                 Utils.name2string(name));
284
285             throw new ApplicationError(error_code);
286         }
287
288         data.operationalState = newValue;
289
290         long trapTime = 0;
291         boolean trapTimeFound = false;
292
293         for (int i = 0; i < trapData.length; i++) {
294
295             if (trapData[i].identifier.equals(SnmpIdentifiers.TIME_OID)) {
296
297                 org.omg.CORBA.Any JavaDoc value = trapData[i].value;
298
299                 if(value.type().kind().value() != TCKind._tk_longlong) {
300
301                     ApplicationErrorInfoTypeImpl error_code =
302                         new ApplicationErrorInfoTypeImpl();
303
304                     error_code.error = new UIDType(
305                         intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
306                         intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
307
308                     error_code.details = new String JavaDoc ("Could not retrieve event time " +
309                         " for trap. Object with Snmp Object Identifier " + SnmpIdentifiers.TIME_OID +
310                         " is not of type long, as expected.");
311
312                     throw new ApplicationError(error_code);
313
314                 }
315
316                 trapTime = value.extract_longlong();
317                 trapTimeFound = true;
318                 break;
319             }
320
321         }
322
323         if (trapTimeFound == false) {
324             ApplicationErrorInfoTypeImpl error_code =
325                 new ApplicationErrorInfoTypeImpl();
326
327             error_code.error = new UIDType(
328                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
329                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
330
331             error_code.details = new String JavaDoc ("Could not retrieve event time " +
332                 " for trap.");
333
334             throw new ApplicationError(error_code);
335         }
336
337         //org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(trapTime, 0,(short) 0,(short) 0);
338
org.omg.TimeBase.UtcT eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(),
339                         0,(short) 0,(short) 0);
340
341 // int notificationId = data.getUniqueNotificationIdentifier();
342
int notificationId = IpNodeProviderImpl.getUniqueNotificationIdentifier();
343
344         String JavaDoc sourceClass = data.objectclass;
345
346         SourceIndicatorType sourceIndicator = SourceIndicatorType.unknown;
347
348         org.omg.CORBA.Any JavaDoc oldValue_any = orb.create_any();
349         OperationalStateTypeHelper.insert(oldValue_any, oldValue);
350
351         org.omg.CORBA.Any JavaDoc newValue_any = orb.create_any();
352         OperationalStateTypeHelper.insert(newValue_any, newValue);
353
354         AttributeValueChangeType [] changedValues = new AttributeValueChangeType[1];
355         changedValues[0] = new AttributeValueChangeType(
356                 "operationalState",
357                 oldValue_any,
358                 newValue_any);
359
360         StateChangedEventImpl stateChangedEvent = new StateChangedEventImpl(
361                 eventTime,
362                 name,
363                 sourceClass,
364                 notificationId,
365                 sourceIndicator,
366                 //new AttributeValueChangeType[0]);
367
changedValues);
368
369         System.err.println("IpNodeProvider>Before pushing StateChange event with identifier " +
370             stateChangedEvent.notificationIdentifier + " for " +
371             Utils.name2string(stateChangedEvent.source) + " of objectclass " +
372             stateChangedEvent.sourceClass + " generated after SNMP agent " +
373             "has been up for " + stateChangedEvent.eventTime.time +
374             " caused by an action of type " + sourceIndicator + "." );
375
376         get_context().push_stateChange(stateChangedEvent);
377
378     }
379
380
381     /**
382      * Implementation of the ::coachEmfServices::SnmpAdapter::TrapCallback::facade_name operation.
383      */

384     public String JavaDoc
385     facade_name()
386     {
387         //
388
// DONE : Implement
389
//
390
return get_main_segment().facade_name();
391     }
392
393 }
394
Popular Tags