~james-page/ubuntu/oneiric/eucalyptus/google-fix

« back to all changes in this revision

Viewing changes to clc/modules/cluster-manager/src/main/java/com/eucalyptus/address/Address.java

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey), Dave Walker (Daviey), Scott Moser
  • Date: 2010-08-11 13:46:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20100811134650-m7ltdeev7ne7glt8
Tags: 2.0~bzr1224-0ubuntu1
[ Dave Walker (Daviey) ]
* New upstream merge, r1224, should fix LP: #610259, #609112, #613033
* debian/patches/10-disable-iscsi.patch: Removed, we should now be 
  supporting iscsi.
* debian/control: Promoted tgt from Recommends to Depends for 
  eucalyptus-sc. (LP: #614503)

[ Scott Moser ]
* work around kvm virtio bug with -kernel by using boot floppy LP: #615529
* remove the listing of dependency on grub-pc for workaround. LP: #613463

Show diffs side-by-side

added added

removed removed

Lines of Context:
159
159
  @Transient
160
160
  public static String                    PENDING_ASSIGNMENT      = "pending";
161
161
  @Transient
162
 
  private AtomicMarkableReference<State>  state;
 
162
  private final AtomicMarkableReference<State> state = new AtomicMarkableReference<State>( State.unallocated, false ) { 
 
163
    public String toString() {
 
164
      return state.getReference( )+":pending="+state.isMarked( );
 
165
    }
 
166
  };
163
167
  @Transient
164
168
  private transient final SplitTransition QUIESCENT               = new SplitTransition( Transition.quiescent ) {
165
169
                                                                    public void bottom( ) {}
187
191
    this.instanceAddress = UNASSIGNED_INSTANCEADDR;
188
192
    this.cluster = cluster;
189
193
    this.transition = QUIESCENT;
190
 
    this.state = new AtomicMarkableReference<State>( State.unallocated, false );
191
194
    this.init( );
192
195
  }
193
196
  
198
201
    this.instanceId = instanceId;
199
202
    this.instanceAddress = instanceAddress;
200
203
    this.transition = QUIESCENT;
201
 
    this.state = new AtomicMarkableReference<State>( State.unallocated, false );
202
204
    this.init( );
203
205
  }
204
206
  
205
207
  public void init( ) {//Should only EVER be called externally after loading from the db
206
 
    this.state = new AtomicMarkableReference<State>( State.unallocated, false );
207
208
    this.transition = QUIESCENT;
208
209
    if ( this.userId == null ) {
209
210
      this.userId = UNALLOCATED_USERID;
258
259
        Address.this.instanceId = UNASSIGNED_INSTANCEID;
259
260
        Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR;
260
261
        Address.this.userId = userId;
261
 
        Address.addAddress( Address.this );
262
262
        try {
263
 
          Addresses.getInstance( ).register( Address.this );
 
263
          Addresses.getInstance( ).enable( Address.this.name );
264
264
        } catch ( NoSuchElementException e ) {
265
 
          LOG.debug( e );
 
265
          try {
 
266
            Addresses.getInstance( ).register( Address.this );
 
267
          } catch ( NoSuchElementException e1 ) {
 
268
            LOG.debug( e );
 
269
          }
 
270
        }
 
271
        if( !Address.this.isSystemOwned( ) ) {
 
272
          Address.addAddress( Address.this );
266
273
        }
267
274
        EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_ALLOCATE, "user=" + Address.this.userId, "address=" + Address.this.name,
268
275
                          Address.this.isSystemOwned( ) ? "SYSTEM" : "USER" ).info( );
269
276
        Address.this.state.attemptMark( State.allocated, false );
 
277
        super.bottom( );
270
278
      }
271
279
      
272
280
      public void bottom( ) {}
275
283
  }
276
284
  
277
285
  public Address release( ) {
278
 
    this.transition( State.allocated, State.unallocated, false, true, new SplitTransition( Transition.unallocating ) {
 
286
    SplitTransition release = new SplitTransition( Transition.unallocating ) {
279
287
      public void top( ) {
280
288
        EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_RELEASE, "user=" + Address.this.userId, "address=" + Address.this.name,
281
289
                          Address.this.isSystemOwned( ) ? "SYSTEM" : "USER" ).info( );
283
291
        Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR;
284
292
        Address.this.userId = UNALLOCATED_USERID;
285
293
        Address.removeAddress( Address.this.name );
286
 
        Address.this.state.attemptMark( State.unallocated, false );
 
294
        super.bottom( );
287
295
      }
288
 
      
289
 
      public void bottom( ) {}
290
 
    } );
 
296
    };
 
297
    if( State.impending.equals( this.state.getReference( ) ) ) {
 
298
      this.transition( State.impending, State.unallocated, true, true, release );
 
299
    } else {
 
300
      this.transition( State.allocated, State.unallocated, false, true, release );
 
301
    }
291
302
    return this;
292
303
  }
293
304
  
308
319
  }
309
320
  
310
321
  public Address unassign( ) {
311
 
    this.transition( State.assigned, State.allocated, false, true, //
312
 
                     new SplitTransition( Transition.unassigning ) {
313
 
                       public void top( ) {
314
 
                         if ( !Address.this.isSystemOwned( ) ) {
 
322
    if( this.isSystemOwned( ) ) {
 
323
      this.transition( State.assigned, State.unallocated, false, true, //
 
324
                       new SplitTransition( Transition.unassigning ) {
 
325
                         @Override
 
326
                         public void top( ) {}
 
327
                         
 
328
                         @Override
 
329
                         public void bottom( ) {
315
330
                           EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_UNASSIGN, "user=" + Address.this.userId )
316
 
                                      .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
317
 
                                      .append( Address.this.instanceAddress, "SYSTEM" ).info( );
318
 
                         } else {
319
 
                           try {
320
 
                             VmInstance vm = VmInstances.getInstance( ).lookup( Address.this.getInstanceId( ) );
321
 
                             EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_UNASSIGN, "user=" + vm.getOwnerId( ) )
322
 
                                        .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
323
 
                                        .append( Address.this.instanceAddress, "SYSTEM" ).info( );
324
 
                           } catch ( NoSuchElementException e ) {
325
 
                             EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_UNASSIGN, "user=<unknown>" )
326
 
                                        .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
327
 
                                        .append( Address.this.instanceAddress, "SYSTEM" ).info( );
328
 
                           }
 
331
                           .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
 
332
                           .append( Address.this.instanceAddress, "SYSTEM" ).info( );
 
333
                           Address.this.instanceId = UNASSIGNED_INSTANCEID;
 
334
                           Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR;
 
335
                           Address.this.userId = UNALLOCATED_USERID;
 
336
                           Address.removeAddress( Address.this.name );
 
337
                           super.bottom( );
329
338
                         }
330
 
                       }
331
 
                       
332
 
                       public void bottom( ) {
333
 
                         Address.this.instanceId = UNASSIGNED_INSTANCEID;
334
 
                         Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR;
335
 
                       }
336
 
                     } );
 
339
                       } );
 
340
    } else {
 
341
      this.transition( State.assigned, State.allocated, false, true, new SplitTransition( Transition.unassigning ) {
 
342
        public void top( ) {}
 
343
        public void bottom( ) {
 
344
          try {
 
345
            VmInstance vm = VmInstances.getInstance( ).lookup( Address.this.getInstanceId( ) );
 
346
            EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_UNASSIGN, "user=" + vm.getOwnerId( ) )
 
347
                       .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
 
348
                       .append( Address.this.instanceAddress, "SYSTEM" ).info( );
 
349
          } catch ( NoSuchElementException e ) {
 
350
            EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_UNASSIGN, "user=<unknown>" )
 
351
                       .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
 
352
                       .append( Address.this.instanceAddress, "SYSTEM" ).info( );
 
353
          }
 
354
          Address.this.instanceId = UNASSIGNED_INSTANCEID;
 
355
          Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR;
 
356
          super.bottom( );
 
357
        }
 
358
      } );
 
359
    }
337
360
    return this;
338
361
  }
339
362
  
340
363
  public Address pendingAssignment( ) {
341
 
    this.transition( State.allocated, State.impending, false, true, //
342
 
                     new SplitTransition( Transition.system ) {
343
 
                       public void bottom( ) {
344
 
                         Address.this.state.set( State.allocated, false );
345
 
                       }
346
 
                       
347
 
                       public void top( ) {}
348
 
                     } );
 
364
    this.transition( State.unallocated, State.impending, false, true, new SplitTransition( Transition.allocating ) {
 
365
      public void top( ) {
 
366
        Address.this.instanceId = PENDING_ASSIGNMENT;
 
367
        Address.this.instanceAddress = UNASSIGNED_INSTANCEADDR;
 
368
        Address.this.userId = "eucalyptus";
 
369
        try {
 
370
          Addresses.getInstance( ).enable( Address.this.name );
 
371
        } catch ( NoSuchElementException e ) {
 
372
          try {
 
373
            Addresses.getInstance( ).register( Address.this );
 
374
          } catch ( NoSuchElementException e1 ) {
 
375
            LOG.debug( e );
 
376
          }
 
377
        }
 
378
      }
 
379
    } );
349
380
    return this;
350
381
  }
351
 
  
 
382
 
352
383
  public Address assign( final String instanceId, final String instanceAddr ) {
353
 
    this.state.compareAndSet( State.impending, State.allocated, true, false );
354
 
    this.transition( State.allocated, State.assigned, false, true, //
355
 
                     new SplitTransition( Transition.assigning ) {
356
 
                       public void top( ) {
357
 
                         Address.this.setInstanceId( instanceId );
358
 
                         Address.this.setInstanceAddress( instanceAddr );
359
 
                       }
360
 
                       
361
 
                       public void bottom( ) {
362
 
                         if ( !Address.this.isSystemOwned( ) ) {
363
 
                           EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_ASSIGN, "user="+Address.this.userId ) 
364
 
                             .append( "address="+Address.this.name, "instance="+Address.this.instanceId, "instance-address=" )
365
 
                             .append( Address.this.instanceAddress, "SYSTEM" ).info( );
366
 
                         } else {
367
 
                           try {
368
 
                             VmInstance vm = VmInstances.getInstance( ).lookup( Address.this.getInstanceId( ) );
369
 
                             EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_ASSIGN, "user=" + vm.getOwnerId( ) )
370
 
                                        .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
371
 
                                        .append( Address.this.instanceAddress, "SYSTEM" ).info( );
372
 
                           } catch ( NoSuchElementException e ) {
373
 
                             EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_ASSIGN, "user=<unknown>" )
374
 
                                        .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
375
 
                                        .append( Address.this.instanceAddress, "SYSTEM" ).info( );
376
 
                           }
377
 
                         }
378
 
                       }
379
 
                     } );
 
384
    if( this.state.compareAndSet( State.impending, State.impending, true, true ) ) {
 
385
      this.transition( State.impending, State.assigned, true, true, //
 
386
                       new SplitTransition( Transition.assigning ) {
 
387
                         public void top( ) {
 
388
                           Address.this.setInstanceId( instanceId );
 
389
                           Address.this.setInstanceAddress( instanceAddr );
 
390
                         }
 
391
 
 
392
                        @Override
 
393
                        public void bottom( ) {
 
394
                          EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_ASSIGN, "user="+Address.this.userId ) 
 
395
                          .append( "address="+Address.this.name, "instance="+Address.this.instanceId, "instance-address=" )
 
396
                          .append( Address.this.instanceAddress, "SYSTEM" ).info( );
 
397
                          super.bottom( );
 
398
                        }
 
399
                       } );
 
400
    } else {
 
401
      this.transition( State.allocated, State.assigned, false, true, //
 
402
                       new SplitTransition( Transition.assigning ) {
 
403
                         public void top( ) {
 
404
                           Address.this.setInstanceId( instanceId );
 
405
                           Address.this.setInstanceAddress( instanceAddr );
 
406
                         }
 
407
 
 
408
                        @Override
 
409
                        public void bottom( ) {
 
410
                          try {
 
411
                            VmInstance vm = VmInstances.getInstance( ).lookup( Address.this.getInstanceId( ) );
 
412
                            EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_ASSIGN, "user=" + vm.getOwnerId( ) )
 
413
                                       .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
 
414
                                       .append( Address.this.instanceAddress, "USER" ).info( );
 
415
                          } catch ( NoSuchElementException e ) {
 
416
                            EventRecord.here( Address.class, EventClass.ADDRESS, EventType.ADDRESS_ASSIGN, "user=<unknown>" )
 
417
                                       .append( "address=" + Address.this.name, "instance=" + Address.this.instanceId, "instance-address=" )
 
418
                                       .append( Address.this.instanceAddress, "USER" ).info( );
 
419
                          }
 
420
                          super.bottom( );
 
421
                        }
 
422
                         
 
423
                       } );
 
424
    }
380
425
    return this;
381
426
  }
382
427
  
399
444
    if ( !this.state.isMarked( ) ) {
400
445
      throw new IllegalStateException( "Trying to clear an address which is not currently pending." );
401
446
    } else {
402
 
      EventRecord
403
 
                 .caller( this.getClass( ), EventType.ADDRESS_STATE, this.state.getReference( ), "BOTTOM", this.transition.getName( ).name( ), this.toString( ) )
 
447
      EventRecord.caller( this.getClass( ), EventType.ADDRESS_STATE, this.state.getReference( ), "BOTTOM", this.transition.getName( ).name( ), this.toString( ) )
404
448
                 .debug( );
405
449
      try {
406
450
        this.transition.bottom( );
407
451
      } finally {
408
452
        this.transition = QUIESCENT;
409
 
        this.state.set( this.state.getReference( ), false );
410
453
      }
411
454
    }
412
455
    return this;
429
472
  }
430
473
  
431
474
  private static void addAddress( Address address ) {
432
 
    Address addr = new Address( address.getName( ), address.getCluster( ) );
433
475
    EntityWrapper<Address> db = new EntityWrapper<Address>( );
434
476
    try {
435
 
      addr = db.getUnique( new Address( address.getName( ) ) );
 
477
      Address addr = db.getUnique( new Address( address.getName( ) ) );
436
478
      addr.setUserId( address.getUserId( ) );
437
479
      db.commit( );
438
480
    } catch ( Throwable e ) {
491
533
  
492
534
  @Override
493
535
  public String toString( ) {
494
 
    return LogUtil.dumpObject( this );
 
536
    return LogUtil.dumpObject( this ).replaceAll( "\\w*=\\s", "" );
495
537
  }
496
538
  
497
539
  public int compareTo( final Object o ) {
517
559
    String name = this.getName( );
518
560
    String desc = null;
519
561
    if ( isAdmin ) {
520
 
      desc = String.format( "%s (%s)", this.getInstanceId( ), this.getUserId( ) );
 
562
      desc = String.format( "%s (%s)", PENDING_ASSIGNMENT.equals( this.getInstanceId( ) ) ? UNASSIGNED_INSTANCEID : this.getInstanceId( ), this.getUserId( ) );
521
563
    } else {
522
 
      desc = UNASSIGNED_INSTANCEID.equals( this.getInstanceId( ) ) ? null : this.getInstanceId( );
 
564
      desc = UNASSIGNED_INSTANCEID.equals( this.getInstanceId( ) ) || PENDING_ASSIGNMENT.equals( this.getInstanceId( ) ) ? null : this.getInstanceId( );
523
565
    }
524
566
    return new DescribeAddressesResponseItemType( name, desc );
525
567
  }
538
580
    }
539
581
    
540
582
    public abstract void top( );
541
 
    
542
 
    public abstract void bottom( );
543
 
    
 
583
    public void bottom( ) {
 
584
      Address.this.state.set( Address.this.state.getReference( ), false );        
 
585
    }
544
586
    @Override
545
587
    public String toString( ) {
546
588
      return String.format( "[SplitTransition previous=%s, transition=%s, next=%s, pending=%s]", this.previous, this.t, Address.this.state.getReference( ),