~ccheney/ubuntu/lucid/eucalyptus/lucid-sru

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/edu/ucsb/eucalyptus/msgs/Messages.groovy

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2009-02-11 02:45:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090211024539-0jhzbpg3hk6nu1yg
Tags: upstream-1.5~bzr139
ImportĀ upstreamĀ versionĀ 1.5~bzr139

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package edu.ucsb.eucalyptus.msgs
 
2
 
 
3
import org.jibx.runtime.BindingDirectory
 
4
import org.jibx.runtime.IBindingFactory
 
5
import org.jibx.runtime.IMarshallingContext
 
6
 
 
7
public class INTERNAL extends EucalyptusMessage {
 
8
 
 
9
  def INTERNAL() {
 
10
    super();
 
11
    this.userId = "eucalyptus";
 
12
    this.effectiveUserId = "eucalyptus";
 
13
  }
 
14
}
 
15
 
 
16
public class EucalyptusMessage implements Cloneable, Serializable {
 
17
 
 
18
  String correlationId;
 
19
  String userId;
 
20
  String effectiveUserId;
 
21
  boolean _return;
 
22
  String statusMessage;
 
23
 
 
24
  public EucalyptusMessage()
 
25
  {
 
26
    this.correlationId = UUID.randomUUID();
 
27
  }
 
28
 
 
29
  public EucalyptusMessage( EucalyptusMessage msg )
 
30
  {
 
31
    this();
 
32
    this.userId = msg.userId;
 
33
    this.effectiveUserId = msg.effectiveUserId;
 
34
    this.correlationId = msg.correlationId;
 
35
  }
 
36
 
 
37
  def EucalyptusMessage(final String userId) {
 
38
    this();
 
39
    this.userId = userId;
 
40
    this.effectiveUserId = userId;
 
41
  }
 
42
 
 
43
 
 
44
 
 
45
 
 
46
  public MetaClass getMetaClass()
 
47
  {
 
48
    return metaClass;
 
49
  }
 
50
 
 
51
  public String getEffectiveUserId()
 
52
  {
 
53
    if ( isAdministrator() ) return "eucalyptus";
 
54
    return effectiveUserId;
 
55
  }
 
56
 
 
57
  public boolean isAdministrator()
 
58
  {
 
59
    return "eucalyptus".equals(this.effectiveUserId);
 
60
  }
 
61
 
 
62
  public String toString()
 
63
  {
 
64
    ByteArrayOutputStream temp = new ByteArrayOutputStream();
 
65
    Class targetClass = this.getClass();
 
66
    while ( !targetClass.getSimpleName().endsWith("Type") ) targetClass = targetClass.getSuperclass();
 
67
    IBindingFactory bindingFactory = BindingDirectory.getFactory("msgs_eucalyptus_ucsb_edu", targetClass);
 
68
    IMarshallingContext mctx = bindingFactory.createMarshallingContext();
 
69
    mctx.setIndent(2);
 
70
    mctx.marshalDocument(this, "UTF-8", null, temp);
 
71
    return temp.toString();
 
72
  }
 
73
 
 
74
  public String toString(String namespace)
 
75
  {
 
76
    ByteArrayOutputStream temp = new ByteArrayOutputStream();
 
77
    Class targetClass = this.getClass();
 
78
    while ( !targetClass.getSimpleName().endsWith("Type") ) targetClass = targetClass.getSuperclass();
 
79
    IBindingFactory bindingFactory = BindingDirectory.getFactory(namespace, targetClass);
 
80
    IMarshallingContext mctx = bindingFactory.createMarshallingContext();
 
81
    mctx.setIndent(2);
 
82
    mctx.marshalDocument(this, "UTF-8", null, temp);
 
83
    return temp;
 
84
  }
 
85
 
 
86
  public Object clone()
 
87
  {
 
88
    return super.clone();
 
89
  }
 
90
 
 
91
  public EucalyptusMessage getReply()
 
92
  {
 
93
    Class msgClass = this.getClass();
 
94
    if ( !this.getClass().getSimpleName().endsWith("Type") )
 
95
    msgClass = msgClass.getSuperclass();
 
96
    Class responseClass = Class.forName(msgClass.getName().replaceAll("Type", "") + "ResponseType");
 
97
    EucalyptusMessage reply = (EucalyptusMessage) responseClass.newInstance();
 
98
    reply.setCorrelationId(this.getCorrelationId());
 
99
    reply.setUserId(this.getUserId());
 
100
    reply.setEffectiveUserId(this.getEffectiveUserId());
 
101
    return reply;
 
102
  }
 
103
 
 
104
}
 
105
public class EucalyptusErrorMessageType extends EucalyptusMessage {
 
106
 
 
107
  String source;
 
108
  String message;
 
109
  String requestType = "not available";
 
110
 
 
111
  public EucalyptusErrorMessageType() {}
 
112
 
 
113
  public EucalyptusErrorMessageType(String source, String message)
 
114
  {
 
115
    this.source = source;
 
116
    this.message = message;
 
117
  }
 
118
 
 
119
  public EucalyptusErrorMessageType(String source, EucalyptusMessage msg, String message)
 
120
  {
 
121
    this(source, message);
 
122
    this.correlationId = msg.getCorrelationId();
 
123
    this.userId = msg.getUserId();
 
124
    this.requestType = msg != null ? msg.getClass().getSimpleName() : this.requestType;
 
125
  }
 
126
 
 
127
  public String toString()
 
128
  {
 
129
    return String.format("SERVICE: %s PROBLEM: %s MSG-TYPE: %s", this.source, this.message, this.requestType);
 
130
  }
 
131
 
 
132
}
 
133
 
 
134
public class EucalyptusData implements Cloneable, Serializable {
 
135
  public MetaClass getMetaClass() {
 
136
    return metaClass;
 
137
  }
 
138
 
 
139
  public String toString() {
 
140
    return this.getProperties().toMapString();
 
141
  }
 
142
 
 
143
  public Object clone(){
 
144
    return super.clone();
 
145
  }
 
146
}
 
147
/** *******************************************************************************/
 
148
public class DescribeResourcesType extends EucalyptusMessage {
 
149
 
 
150
  ArrayList<VmTypeInfo> instanceTypes = new ArrayList<VmTypeInfo>();
 
151
}
 
152
public class DescribeResourcesResponseType extends EucalyptusMessage {
 
153
 
 
154
  ArrayList<ResourceType> resources = new ArrayList<ResourceType>();
 
155
  ArrayList<String> serviceTags = new ArrayList<String>();
 
156
}
 
157
 
 
158
public class VmTypeInfo extends EucalyptusData {
 
159
 
 
160
  String name;
 
161
  Integer memory;
 
162
  Integer disk;
 
163
  Integer cores;
 
164
 
 
165
  def VmTypeInfo(){}
 
166
 
 
167
  def VmTypeInfo(final name, final memory, final disk, final cores)
 
168
  {
 
169
    this.name = name;
 
170
    this.memory = memory;
 
171
    this.disk = disk;
 
172
    this.cores = cores;
 
173
  }
 
174
 
 
175
  @Override
 
176
  public String toString() {
 
177
    return "VmTypeInfo{" +
 
178
            "name='" + name + '\'' +
 
179
            ", memory=" + memory +
 
180
            ", disk=" + disk +
 
181
            ", cores=" + cores +
 
182
            '}';
 
183
  }
 
184
 
 
185
}
 
186
public class ResourceType extends EucalyptusData {
 
187
 
 
188
  VmTypeInfo instanceType;
 
189
  int maxInstances;
 
190
  int availableInstances;
 
191
}
 
192
public class NetworkConfigType extends EucalyptusData {
 
193
  String macAddress;
 
194
  String ignoredMacAddress;
 
195
  String ipAddress;
 
196
  String ignoredPublicIp;
 
197
  int vlan;
 
198
 
 
199
  def NetworkConfigType()
 
200
  {
 
201
  }
 
202
 
 
203
  @Override
 
204
  public String toString() {
 
205
    return "NetworkConfigType{" +
 
206
            "macAddress='" + macAddress + '\'' +
 
207
            ", ipAddress='" + ipAddress + '\'' +
 
208
            ", publicIp='" + ignoredPublicIp + '\'' +
 
209
            ", vlan=" + vlan +
 
210
            '}';
 
211
  }
 
212
 
 
213
 
 
214
}
 
215
 
 
216
public class NetworkParameters extends EucalyptusData {
 
217
 
 
218
  String privateMacAddress;
 
219
  String publicMacAddress;
 
220
  int macLimit;
 
221
  int vlan;
 
222
}
 
223
 
 
224
public class PacketFilterRule {
 
225
  public static String ACCEPT = "firewall-open";
 
226
  public static String DENY = "firewall-close";
 
227
 
 
228
  public static PacketFilterRule revoke( PacketFilterRule  existingRule ) {
 
229
    PacketFilterRule pf = new PacketFilterRule();
 
230
    pf.destName = existingRule.getDestName();
 
231
    pf.policy = DENY;
 
232
    pf.portMin = existingRule.getPortMin();
 
233
    pf.portMax = existingRule.getPortMax();
 
234
    pf.protocol = existingRule.getProtocol();
 
235
    pf.setPeers( existingRule.getPeers() );
 
236
    pf.setSourceCidrs( existingRule.getSourceCidrs() );
 
237
    pf.setSourceNetworkNames( existingRule.getSourceNetworkNames() );
 
238
    pf.setSourceUserNames( existingRule.getSourceUserNames() );
 
239
    return pf;
 
240
  }
 
241
 
 
242
  String destName;
 
243
  String policy = "firewall-open";
 
244
  String protocol;
 
245
  int portMin;
 
246
  int portMax;
 
247
  ArrayList<String> sourceCidrs = new ArrayList<String>();
 
248
  ArrayList<VmNetworkPeer> peers = new ArrayList<VmNetworkPeer>();
 
249
  ArrayList<String> sourceNetworkNames = new ArrayList<String>();
 
250
  ArrayList<String> sourceUserNames = new ArrayList<String>();
 
251
 
 
252
  def PacketFilterRule(final destName, final protocol, final portMin, final portMax)
 
253
  {
 
254
    this.destName = destName;
 
255
    this.protocol = protocol;
 
256
    this.portMin = portMin;
 
257
    this.portMax = portMax;
 
258
  }
 
259
 
 
260
  def PacketFilterRule(){}
 
261
 
 
262
  @Override
 
263
  public String toString() {
 
264
    return "PacketFilterRule{" +
 
265
            "destName='" + destName + '\'' +
 
266
            ", policy='" + policy + '\'' +
 
267
            ", protocol='" + protocol + '\'' +
 
268
            ", portMin=" + portMin +
 
269
            ", portMax=" + portMax +
 
270
            ", sourceCidrs=" + sourceCidrs +
 
271
            ", peers=" + peers +
 
272
            ", sourceNetworkNames=" + sourceNetworkNames +
 
273
            ", sourceUserNames=" + sourceUserNames +
 
274
            '}';
 
275
  }
 
276
 
 
277
 
 
278
  public void addPeer( String queryKey, String groupName )
 
279
  {
 
280
    VmNetworkPeer peer = new VmNetworkPeer( queryKey, groupName );
 
281
    this.peers.add(peer);
 
282
    this.sourceNetworkNames.add( peer.getSourceNetworkName() );
 
283
    this.sourceUserNames.add(peer.userName);
 
284
  }
 
285
 
 
286
}
 
287
 
 
288
public class VmNetworkPeer {
 
289
 
 
290
  String userName;
 
291
  String sourceNetworkName;
 
292
 
 
293
  def VmNetworkPeer()
 
294
  {
 
295
  }
 
296
 
 
297
  def VmNetworkPeer(final userName, final sourceNetworkName)
 
298
  {
 
299
    this.userName = userName;
 
300
    this.sourceNetworkName = sourceNetworkName;
 
301
  }
 
302
 
 
303
}
 
304
 
 
305
 
 
306
 
 
307
public class EventRecord extends EucalyptusMessage {
 
308
 
 
309
  String host = "cloud";
 
310
  String service;
 
311
  long timestamp = System.currentTimeMillis();
 
312
  String eventUserId;
 
313
  String eventCorrelationId;
 
314
  String eventId;
 
315
  String other;
 
316
 
 
317
  def EventRecord(final service, final eventUserId, final eventCorrelationId, final eventId, final other)
 
318
  {
 
319
    this.service = service;
 
320
    this.eventUserId = eventUserId;
 
321
    this.eventCorrelationId = eventCorrelationId;
 
322
    this.eventId = eventId;
 
323
    this.other = other;
 
324
  }
 
325
 
 
326
  public EventRecord() {}
 
327
 
 
328
  public String toString()
 
329
  {
 
330
    return String.format("%s/%s:%s:%s:%s:%7.4f:%s", this.host, this.service, this.eventUserId, this.eventCorrelationId, this.eventId, this.timestamp / 1000.0f, this.other != null ? this.other : "");
 
331
  }
 
332
 
 
333
  public static EventRecord create(final service, final eventUserId, final eventCorrelationId, final eventId, final other)
 
334
  {
 
335
    return new EventRecord(service, eventUserId, eventCorrelationId, eventId, other);
 
336
  }
 
337
 
 
338
}
 
339
 
 
340
public class GetLogsType extends EucalyptusMessage implements Comparable {
 
341
  String serviceTag;
 
342
  def GetLogsType(){}
 
343
  def GetLogsType(final serviceTag)
 
344
  {
 
345
    this.serviceTag = serviceTag;
 
346
  }
 
347
  public int compareTo(Object o)
 
348
  {
 
349
    return this.serviceTag.compareTo(((GetLogsType)o).serviceTag);
 
350
  }
 
351
}
 
352
public class GetLogsResponseType extends EucalyptusMessage {
 
353
  NodeLogInfo logs = new NodeLogInfo();
 
354
}
 
355
public class GetKeysType extends EucalyptusMessage implements Comparable {
 
356
  String serviceTag;
 
357
  def GetKeysType(){}
 
358
  def GetKeysType(final serviceTag)
 
359
  {
 
360
    this.serviceTag = serviceTag;
 
361
  }
 
362
 
 
363
  public int compareTo(Object o)
 
364
  {
 
365
    return this.serviceTag.compareTo(((GetKeysType)o).serviceTag);
 
366
  }
 
367
 
 
368
}
 
369
public class GetKeysResponseType extends EucalyptusMessage {
 
370
  NodeCertInfo certs = new NodeCertInfo();
 
371
}
 
372
 
 
373
public class NodeCertInfo extends EucalyptusData implements Comparable {
 
374
  String serviceTag;
 
375
  String ccCert = "";
 
376
  String ncCert = "";
 
377
 
 
378
  public int compareTo(Object o)
 
379
  {
 
380
    return this.serviceTag.compareTo(((NodeCertInfo)o).serviceTag);
 
381
  }
 
382
 
 
383
  @Override
 
384
  public String toString() {
 
385
    return "NodeCertInfo{" +
 
386
            "serviceTag='" + serviceTag.replaceAll("services/EucalyptusNC","") + '\'' +
 
387
            ", ccCert='" + ccCert + '\'' +
 
388
            ", ncCert='" + ncCert + '\'' +
 
389
            '}';
 
390
  }
 
391
 
 
392
}
 
393
 
 
394
public class NodeLogInfo extends EucalyptusData implements Comparable {
 
395
  String serviceTag;
 
396
  String ccLog = "";
 
397
  String ncLog = "";
 
398
  String httpdLog = "";
 
399
  String axis2Log = "";
 
400
 
 
401
  public int compareTo(Object o)
 
402
  {
 
403
    return this.serviceTag.compareTo(((NodeLogInfo)o).serviceTag);
 
404
  }
 
405
 
 
406
}
 
407
 
 
408
public class HeartbeatMessage implements Cloneable, Serializable {
 
409
  String heartbeatId;
 
410
 
 
411
  def HeartbeatMessage(final String heartbeatId) {
 
412
    this.heartbeatId = heartbeatId;
 
413
  }
 
414
 
 
415
  def HeartbeatMessage() {}
 
416
 
 
417
 
 
418
}
 
419