Skip to content

Commit e7a554f

Browse files
author
Murali Reddy
committed
Merging events framework branch into master. This commit will bring
following changes - introduced notion of event bus with publish, subscribe, unsubscribe semantics - a plug-in can implement the EventBus abstraction to provide event bug to CloudStack - A rabbitMQ based plug-in that can interact with AMQP servers to provide message broker based event-bug - stream lines, action events, usage events, alerts publishing in to convineance classed which are also used to publish corresponding event on to event bus - introduced notion of state change event. On a state change, in the state machine corrsponding to the resource, a state change event is published on the event bug - associated a state machined with Snapshot and Network objects - Virtual Machine, Volume, Snaphost, Network object state changes wil result in a state change event
1 parent 6a6d93c commit e7a554f

63 files changed

Lines changed: 3400 additions & 1555 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.cloud.event;
21+
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
public class EventCategory {
26+
private static List<EventCategory> eventCategories = new ArrayList<EventCategory>();
27+
private String eventCategoryName;
28+
29+
public EventCategory(String categoryName) {
30+
this.eventCategoryName = categoryName;
31+
eventCategories.add(this);
32+
}
33+
34+
public String getName() {
35+
return eventCategoryName;
36+
}
37+
38+
public static List<EventCategory> listAllEventCategories() {
39+
return eventCategories;
40+
}
41+
42+
public static EventCategory getEventCategory(String categoryName) {
43+
for (EventCategory category : eventCategories) {
44+
if (category.getName().equalsIgnoreCase(categoryName)) {
45+
return category;
46+
}
47+
}
48+
return null;
49+
}
50+
51+
public static final EventCategory ACTION_EVENT = new EventCategory("ActionEvent");
52+
public static final EventCategory ALERT_EVENT = new EventCategory("AlertEvent");
53+
public static final EventCategory USAGE_EVENT = new EventCategory("UsageEvent");
54+
public static final EventCategory RESOURCE_STATE_CHANGE_EVENT = new EventCategory("ResourceStateEvent");
55+
}

api/src/com/cloud/event/EventTypes.java

Lines changed: 349 additions & 2 deletions
Large diffs are not rendered by default.

api/src/com/cloud/network/Network.java

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,25 @@
1616
// under the License.
1717
package com.cloud.network;
1818

19-
import org.apache.cloudstack.acl.ControlledEntity;
2019
import com.cloud.network.Networks.BroadcastDomainType;
2120
import com.cloud.network.Networks.Mode;
2221
import com.cloud.network.Networks.TrafficType;
23-
import com.cloud.utils.fsm.FiniteState;
24-
import com.cloud.utils.fsm.StateMachine;
22+
import com.cloud.utils.fsm.StateMachine2;
23+
import com.cloud.utils.fsm.StateObject;
24+
import org.apache.cloudstack.acl.ControlledEntity;
2525
import org.apache.cloudstack.api.Identity;
2626
import org.apache.cloudstack.api.InternalIdentity;
2727

2828
import java.net.URI;
2929
import java.util.ArrayList;
3030
import java.util.List;
31-
import java.util.Set;
3231

3332
/**
3433
* owned by an account.
3534
*/
36-
public interface Network extends ControlledEntity, InternalIdentity, Identity {
35+
public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity {
3736

38-
public enum GuestType {
37+
public enum GuestType {
3938
Shared,
4039
Isolated
4140
}
@@ -204,47 +203,17 @@ enum Event {
204203
OperationFailed;
205204
}
206205

207-
enum State implements FiniteState<State, Event> {
206+
public enum State {
207+
208208
Allocated("Indicates the network configuration is in allocated but not setup"),
209209
Setup("Indicates the network configuration is setup"),
210210
Implementing("Indicates the network configuration is being implemented"),
211211
Implemented("Indicates the network configuration is in use"),
212212
Shutdown("Indicates the network configuration is being destroyed"),
213213
Destroy("Indicates that the network is destroyed");
214214

215+
protected static final StateMachine2<State, Network.Event, Network> s_fsm = new StateMachine2<State, Network.Event, Network>();
215216

216-
@Override
217-
public StateMachine<State, Event> getStateMachine() {
218-
return s_fsm;
219-
}
220-
221-
@Override
222-
public State getNextState(Event event) {
223-
return s_fsm.getNextState(this, event);
224-
}
225-
226-
@Override
227-
public List<State> getFromStates(Event event) {
228-
return s_fsm.getFromStates(this, event);
229-
}
230-
231-
@Override
232-
public Set<Event> getPossibleEvents() {
233-
return s_fsm.getPossibleEvents(this);
234-
}
235-
236-
String _description;
237-
238-
@Override
239-
public String getDescription() {
240-
return _description;
241-
}
242-
243-
private State(String description) {
244-
_description = description;
245-
}
246-
247-
private static StateMachine<State, Event> s_fsm = new StateMachine<State, Event>();
248217
static {
249218
s_fsm.addTransition(State.Allocated, Event.ImplementNetwork, State.Implementing);
250219
s_fsm.addTransition(State.Implementing, Event.OperationSucceeded, State.Implemented);
@@ -253,6 +222,15 @@ private State(String description) {
253222
s_fsm.addTransition(State.Shutdown, Event.OperationSucceeded, State.Allocated);
254223
s_fsm.addTransition(State.Shutdown, Event.OperationFailed, State.Implemented);
255224
}
225+
226+
public static StateMachine2<State, Network.Event, Network> getStateMachine() {
227+
return s_fsm;
228+
}
229+
230+
String _description;
231+
private State(String description) {
232+
_description = description;
233+
}
256234
}
257235

258236
String getName();

api/src/com/cloud/storage/Snapshot.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19-
import java.util.Date;
20-
21-
import org.apache.cloudstack.acl.ControlledEntity;
2219
import com.cloud.hypervisor.Hypervisor.HypervisorType;
20+
import com.cloud.utils.fsm.StateMachine2;
21+
import com.cloud.utils.fsm.StateObject;
22+
import org.apache.cloudstack.acl.ControlledEntity;
2323
import org.apache.cloudstack.api.Identity;
2424
import org.apache.cloudstack.api.InternalIdentity;
2525

26-
public interface Snapshot extends ControlledEntity, Identity, InternalIdentity {
26+
import java.util.Date;
27+
28+
public interface Snapshot extends ControlledEntity, Identity, InternalIdentity, StateObject<Snapshot.State> {
2729
public enum Type {
2830
MANUAL,
2931
RECURRING,
@@ -51,13 +53,29 @@ public boolean equals(String snapshotType) {
5153
}
5254
}
5355

54-
public enum Status {
56+
public enum State {
5557
Creating,
5658
CreatedOnPrimary,
5759
BackingUp,
5860
BackedUp,
5961
Error;
6062

63+
private final static StateMachine2<State, Event, Snapshot> s_fsm = new StateMachine2<State, Event, Snapshot>();
64+
65+
public static StateMachine2<State, Event, Snapshot> getStateMachine() {
66+
return s_fsm;
67+
}
68+
69+
static {
70+
s_fsm.addTransition(null, Event.CreateRequested, Creating);
71+
s_fsm.addTransition(Creating, Event.OperationSucceeded, CreatedOnPrimary);
72+
s_fsm.addTransition(Creating, Event.OperationNotPerformed, BackedUp);
73+
s_fsm.addTransition(Creating, Event.OperationFailed, Error);
74+
s_fsm.addTransition(CreatedOnPrimary, Event.BackupToSecondary, BackingUp);
75+
s_fsm.addTransition(BackingUp, Event.OperationSucceeded, BackedUp);
76+
s_fsm.addTransition(BackingUp, Event.OperationFailed, Error);
77+
}
78+
6179
public String toString() {
6280
return this.name();
6381
}
@@ -67,6 +85,15 @@ public boolean equals(String status) {
6785
}
6886
}
6987

88+
enum Event {
89+
CreateRequested,
90+
OperationNotPerformed,
91+
BackupToSecondary,
92+
BackedupToSecondary,
93+
OperationSucceeded,
94+
OperationFailed
95+
}
96+
7097
public static final long MANUAL_POLICY_ID = 0L;
7198

7299
long getAccountId();
@@ -81,7 +108,7 @@ public boolean equals(String status) {
81108

82109
Type getType();
83110

84-
Status getStatus();
111+
State getState();
85112

86113
HypervisorType getHypervisorType();
87114

api/src/org/apache/cloudstack/api/response/SnapshotResponse.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19-
import java.util.Date;
20-
import java.util.List;
21-
22-
import org.apache.cloudstack.api.ApiConstants;
2319
import com.cloud.serializer.Param;
2420
import com.cloud.storage.Snapshot;
2521
import com.google.gson.annotations.SerializedName;
22+
import org.apache.cloudstack.api.ApiConstants;
2623
import org.apache.cloudstack.api.BaseResponse;
2724
import org.apache.cloudstack.api.EntityReference;
2825

26+
import java.util.Date;
27+
import java.util.List;
28+
2929
@EntityReference(value=Snapshot.class)
3030
@SuppressWarnings("unused")
3131
public class SnapshotResponse extends BaseResponse implements ControlledEntityResponse {
@@ -81,7 +81,7 @@ public class SnapshotResponse extends BaseResponse implements ControlledEntityRe
8181

8282
@SerializedName(ApiConstants.STATE)
8383
@Param(description = "the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage")
84-
private Snapshot.Status state;
84+
private Snapshot.State state;
8585

8686
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with snapshot", responseObject = ResourceTagResponse.class)
8787
private List<ResourceTagResponse> tags;
@@ -149,7 +149,7 @@ public void setIntervalType(String intervalType) {
149149
this.intervalType = intervalType;
150150
}
151151

152-
public void setState(Snapshot.Status state) {
152+
public void setState(Snapshot.State state) {
153153
this.state = state;
154154
}
155155

client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
<artifactId>cloud-plugin-host-allocator-random</artifactId>
117117
<version>${project.version}</version>
118118
</dependency>
119+
<dependency>
120+
<groupId>org.apache.cloudstack</groupId>
121+
<artifactId>cloud-mom-rabbitmq</artifactId>
122+
<version>${project.version}</version>
123+
</dependency>
119124
<dependency>
120125
<groupId>mysql</groupId>
121126
<artifactId>mysql-connector-java</artifactId>

core/src/com/cloud/storage/SnapshotVO.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,13 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19-
import java.util.Date;
20-
import java.util.UUID;
21-
22-
import javax.persistence.Column;
23-
import javax.persistence.Entity;
24-
import javax.persistence.EnumType;
25-
import javax.persistence.Enumerated;
26-
import javax.persistence.GeneratedValue;
27-
import javax.persistence.GenerationType;
28-
import javax.persistence.Id;
29-
import javax.persistence.Table;
30-
31-
import org.apache.cloudstack.api.Identity;
3219
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3320
import com.cloud.utils.db.GenericDao;
3421
import com.google.gson.annotations.Expose;
35-
import org.apache.cloudstack.api.InternalIdentity;
22+
23+
import javax.persistence.*;
24+
import java.util.Date;
25+
import java.util.UUID;
3626

3727
@Entity
3828
@Table(name="snapshots")
@@ -69,7 +59,7 @@ public class SnapshotVO implements Snapshot {
6959
@Expose
7060
@Column(name="status", updatable = true, nullable=false)
7161
@Enumerated(value=EnumType.STRING)
72-
private Status status;
62+
private State status;
7363

7464
@Column(name="snapshot_type")
7565
short snapshotType;
@@ -127,7 +117,7 @@ public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, Long
127117
this.snapshotType = snapshotType;
128118
this.typeDescription = typeDescription;
129119
this.size = size;
130-
this.status = Status.Creating;
120+
this.status = State.Creating;
131121
this.prevSnapshotId = 0;
132122
this.hypervisorType = hypervisorType;
133123
this.version = "2.2";
@@ -252,11 +242,11 @@ public Date getRemoved() {
252242
}
253243

254244
@Override
255-
public Status getStatus() {
245+
public State getState() {
256246
return status;
257247
}
258248

259-
public void setStatus(Status status) {
249+
public void setStatus(State status) {
260250
this.status = status;
261251
}
262252

framework/events/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<artifactId>cloud-framework-events</artifactId>
23+
<name>Apache CloudStack Event Notification Framework</name>
24+
<parent>
25+
<groupId>org.apache.cloudstack</groupId>
26+
<artifactId>cloudstack-framework</artifactId>
27+
<version>4.1.0-SNAPSHOT</version>
28+
<relativePath>../pom.xml</relativePath>
29+
</parent>
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.apache.cloudstack</groupId>
33+
<artifactId>cloud-utils</artifactId>
34+
<version>${project.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.google.code.gson</groupId>
38+
<artifactId>gson</artifactId>
39+
<version>${cs.gson.version}</version>
40+
</dependency>
41+
</dependencies>
42+
<build>
43+
<defaultGoal>install</defaultGoal>
44+
<sourceDirectory>src</sourceDirectory>
45+
<testSourceDirectory>test</testSourceDirectory>
46+
</build>
47+
</project>

0 commit comments

Comments
 (0)