|
18 | 18 | package com.cloud.vm; |
19 | 19 |
|
20 | 20 | import java.net.URI; |
| 21 | +import java.util.Date; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Set; |
21 | 24 |
|
22 | 25 | import com.cloud.network.Networks.Mode; |
23 | | -import com.cloud.resource.Resource; |
| 26 | +import com.cloud.utils.fsm.FiniteState; |
| 27 | +import com.cloud.utils.fsm.StateMachine; |
24 | 28 |
|
25 | 29 |
|
26 | 30 | /** |
27 | 31 | * Nic represents one nic on the VM. |
28 | 32 | */ |
29 | | -public interface Nic extends Resource { |
| 33 | +public interface Nic { |
| 34 | + enum Event { |
| 35 | + ReservationRequested, |
| 36 | + ReleaseRequested, |
| 37 | + CancelRequested, |
| 38 | + OperationCompleted, |
| 39 | + OperationFailed, |
| 40 | + } |
| 41 | + |
| 42 | + public enum State implements FiniteState<State, Event> { |
| 43 | + Allocated("Resource is allocated but not reserved"), |
| 44 | + Reserving("Resource is being reserved right now"), |
| 45 | + Reserved("Resource has been reserved."), |
| 46 | + Releasing("Resource is being released"), |
| 47 | + Deallocating("Resource is being deallocated"); |
| 48 | + |
| 49 | + String _description; |
| 50 | + |
| 51 | + @Override |
| 52 | + public StateMachine<State, Event> getStateMachine() { |
| 53 | + return s_fsm; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public State getNextState(Event event) { |
| 58 | + return s_fsm.getNextState(this, event); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public List<State> getFromStates(Event event) { |
| 63 | + return s_fsm.getFromStates(this, event); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public Set<Event> getPossibleEvents() { |
| 68 | + return s_fsm.getPossibleEvents(this); |
| 69 | + } |
| 70 | + |
| 71 | + private State(String description) { |
| 72 | + _description = description; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public String getDescription() { |
| 77 | + return _description; |
| 78 | + } |
| 79 | + |
| 80 | + final static private StateMachine<State, Event> s_fsm = new StateMachine<State, Event>(); |
| 81 | + static { |
| 82 | + s_fsm.addTransition(State.Allocated, Event.ReservationRequested, State.Reserving); |
| 83 | + s_fsm.addTransition(State.Reserving, Event.CancelRequested, State.Allocated); |
| 84 | + s_fsm.addTransition(State.Reserving, Event.OperationCompleted, State.Reserved); |
| 85 | + s_fsm.addTransition(State.Reserving, Event.OperationFailed, State.Allocated); |
| 86 | + s_fsm.addTransition(State.Reserved, Event.ReleaseRequested, State.Releasing); |
| 87 | + s_fsm.addTransition(State.Releasing, Event.OperationCompleted, State.Allocated); |
| 88 | + s_fsm.addTransition(State.Releasing, Event.OperationFailed, State.Reserved); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + public enum ReservationStrategy { |
| 93 | + PlaceHolder, |
| 94 | + Create, |
| 95 | + Start; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * @return id in the CloudStack database |
| 100 | + */ |
| 101 | + long getId(); |
| 102 | + |
| 103 | + /** |
| 104 | + * @return reservation id returned by the allocation source. This can be the |
| 105 | + * String version of the database id if the allocation source does not need it's |
| 106 | + * own implementation of the reservation id. This is passed back to the |
| 107 | + * allocation source to release the resource. |
| 108 | + */ |
| 109 | + String getReservationId(); |
| 110 | + |
| 111 | + /** |
| 112 | + * @return unique name for the allocation source. |
| 113 | + */ |
| 114 | + String getReserver(); |
| 115 | + |
| 116 | + /** |
| 117 | + * @return the time a reservation request was made to the allocation source. |
| 118 | + */ |
| 119 | + Date getUpdateTime(); |
| 120 | + |
| 121 | + /** |
| 122 | + * @return the reservation state of the resource. |
| 123 | + */ |
| 124 | + State getState(); |
| 125 | + |
| 126 | + ReservationStrategy getReservationStrategy(); |
30 | 127 | boolean isDefaultNic(); |
31 | 128 |
|
32 | 129 | String getIp4Address(); |
@@ -54,5 +151,4 @@ public interface Nic extends Resource { |
54 | 151 | URI getIsolationUri(); |
55 | 152 |
|
56 | 153 | URI getBroadcastUri(); |
57 | | - |
58 | 154 | } |
0 commit comments