2
* Software License Agreement (BSD License)
4
* Copyright (c) 2008, Regents of the University of California
7
* Redistribution and use of this software in source and binary forms, with or
8
* without modification, are permitted provided that the following conditions
11
* * Redistributions of source code must retain the above
12
* copyright notice, this list of conditions and the
13
* following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the
17
* following disclaimer in the documentation and/or other
18
* materials provided with the distribution.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
32
* Author: Chris Grzegorczyk grze@cs.ucsb.edu
35
package edu.ucsb.eucalyptus.cloud.cluster;
37
import edu.ucsb.eucalyptus.constants.HasName;
38
import edu.ucsb.eucalyptus.msgs.ReservationInfoType;
39
import org.apache.log4j.Logger;
42
import java.util.zip.Adler32;
44
public class Reservation implements HasName {
45
private static Logger LOG = Logger.getLogger( Reservation.class );
47
private String ownerId;
48
private String reservationId;
52
private int launchIndexBase = 0;
53
private List<String> vmInstances;
55
public Reservation( String ownerId, String reservationId)
57
this(ownerId,0l,0,0,0);
58
this.reservationId = reservationId;
61
public Reservation( String ownerId, Long reservationId, int minCount, int maxCount, int baseMac )
63
this.ownerId = ownerId;
64
this.rsvId = reservationId;
66
//:: DOCUMENT: reservation ID creation:://
67
Adler32 hash = new Adler32();
69
hash.update( ( ownerId + Long.toHexString( reservationId ) ).getBytes() );
70
this.reservationId = String.format( "r-%08X", hash.getValue() );
72
this.minCount = minCount;
73
this.maxCount = maxCount;
74
this.vmInstances = new ArrayList<String>();
77
public String getName()
79
return this.getReservationId();
82
public boolean isEmpty()
84
return this.vmInstances.isEmpty();
87
public boolean contains( String instanceId )
89
return this.vmInstances.contains( instanceId );
92
public boolean removeInstance( String instanceId )
94
return this.vmInstances.remove( instanceId );
97
public int addInstance( String vmId )
99
this.vmInstances.add( vmId );
100
return this.launchIndexBase++;
103
public int getMaxCount()
108
public int getMinCount()
113
public String getOwnerId()
118
public String getReservationId()
120
return reservationId;
123
public Long getRsvId()
128
public ReservationInfoType getAsReservationInfoType()
130
ReservationInfoType rsvInfo = new ReservationInfoType();
131
for( String vmId : this.vmInstances )
133
VmInstance vm = VmInstances.getInstance().lookup( vmId );
134
rsvInfo.getInstancesSet().add( vm.getAsRunningInstanceItemType() );
136
rsvInfo.setOwnerId( this.getOwnerId() );
137
rsvInfo.setReservationId( this.getReservationId() );
141
public int compareTo( final Object o )
143
Reservation that = (Reservation) o;
144
return this.getRsvId().compareTo( that.getRsvId() );