Skip to content

Commit 0af923e

Browse files
committed
Merge branch '4.19'
2 parents a6f3560 + 0514cae commit 0af923e

File tree

25 files changed

+588
-22
lines changed

25 files changed

+588
-22
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,10 @@ public class EventTypes {
11931193
entityEventDetails.put(EVENT_QUOTA_TARIFF_UPDATE, QuotaTariff.class);
11941194
}
11951195

1196+
public static boolean isNetworkEvent(String eventType) {
1197+
return EVENT_NETWORK_CREATE.equals(eventType) || EVENT_NETWORK_DELETE.equals(eventType) ||
1198+
EVENT_NETWORK_UPDATE.equals(eventType);
1199+
}
11961200
public static String getEntityForEvent(String eventName) {
11971201
Object entityClass = entityEventDetails.get(eventName);
11981202
if (entityClass == null) {

api/src/main/java/org/apache/cloudstack/usage/UsageTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class UsageTypes {
4646
public static final int VM_SNAPSHOT_ON_PRIMARY = 27;
4747
public static final int BACKUP = 28;
4848
public static final int BUCKET = 29;
49+
public static final int NETWORK = 30;
4950
public static final int VPC = 31;
5051

5152
public static List<UsageTypeResponse> listUsageTypes() {
@@ -73,6 +74,7 @@ public static List<UsageTypeResponse> listUsageTypes() {
7374
responseList.add(new UsageTypeResponse(VM_SNAPSHOT_ON_PRIMARY, "VM Snapshot on primary storage usage"));
7475
responseList.add(new UsageTypeResponse(BACKUP, "Backup storage usage"));
7576
responseList.add(new UsageTypeResponse(BUCKET, "Bucket storage usage"));
77+
responseList.add(new UsageTypeResponse(NETWORK, "Network usage"));
7678
responseList.add(new UsageTypeResponse(VPC, "VPC usage"));
7779
return responseList;
7880
}

client/pom.xml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
<version>4.20.0.0-SNAPSHOT</version>
2929
</parent>
3030
<repositories>
31-
<repository>
32-
<id>juniper-contrail</id>
33-
<url>https://juniper.github.io/contrail-maven/snapshots</url>
34-
</repository>
3531
<repository>
3632
<id>juniper-tungsten-api</id>
3733
<url>https://github.com/radu-todirica/tungsten-api/raw/master</url>
@@ -271,11 +267,6 @@
271267
<artifactId>cloud-plugin-network-nvp</artifactId>
272268
<version>${project.version}</version>
273269
</dependency>
274-
<dependency>
275-
<groupId>org.apache.cloudstack</groupId>
276-
<artifactId>cloud-plugin-network-contrail</artifactId>
277-
<version>${project.version}</version>
278-
</dependency>
279270
<dependency>
280271
<groupId>org.apache.cloudstack</groupId>
281272
<artifactId>cloud-plugin-network-palo-alto</artifactId>
@@ -1107,6 +1098,11 @@
11071098
<artifactId>cloud-plugin-api-vmware-sioc</artifactId>
11081099
<version>${project.version}</version>
11091100
</dependency>
1101+
<dependency>
1102+
<groupId>org.apache.cloudstack</groupId>
1103+
<artifactId>cloud-plugin-network-contrail</artifactId>
1104+
<version>${project.version}</version>
1105+
</dependency>
11101106
<dependency>
11111107
<groupId>org.apache.cloudstack</groupId>
11121108
<artifactId>cloud-plugin-backup-veeam</artifactId>

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,8 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
14661466
if (isNetworkImplemented(network)) {
14671467
logger.debug("Network id={} is already implemented", networkId);
14681468
implemented.set(guru, network);
1469+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, network.getAccountId(), network.getDataCenterId(), network.getId(),
1470+
network.getName(), network.getNetworkOfferingId(), null, network.getState().name(), Network.class.getName(), network.getUuid(), true);
14691471
return implemented;
14701472
}
14711473

@@ -1522,6 +1524,8 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
15221524
network.setRestartRequired(false);
15231525
_networksDao.update(network.getId(), network);
15241526
implemented.set(guru, network);
1527+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(), network.getId(),
1528+
network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(), network.getUuid());
15251529
return implemented;
15261530
} catch (final NoTransitionException e) {
15271531
logger.error(e.getMessage());
@@ -3370,6 +3374,8 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
33703374
final Pair<Class<?>, Long> networkMsg = new Pair<Class<?>, Long>(Network.class, networkFinal.getId());
33713375
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
33723376
}
3377+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(), network.getId(),
3378+
network.getName(), network.getNetworkOfferingId(), null, null, null, Network.class.getName(), network.getUuid());
33733379
return true;
33743380
} catch (final CloudRuntimeException e) {
33753381
logger.error("Failed to delete network", e);
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.usage;
18+
19+
import javax.persistence.Column;
20+
import javax.persistence.Entity;
21+
import javax.persistence.GeneratedValue;
22+
import javax.persistence.GenerationType;
23+
import javax.persistence.Id;
24+
import javax.persistence.Table;
25+
import javax.persistence.Temporal;
26+
import javax.persistence.TemporalType;
27+
import org.apache.cloudstack.api.InternalIdentity;
28+
29+
import java.util.Date;
30+
31+
@Entity
32+
@Table(name = "usage_networks")
33+
public class UsageNetworksVO implements InternalIdentity {
34+
@Id
35+
@GeneratedValue(strategy = GenerationType.IDENTITY)
36+
@Column(name = "id")
37+
private long id;
38+
39+
@Column(name = "network_id")
40+
private long networkId;
41+
42+
@Column(name = "network_offering_id")
43+
private long networkOfferingId;
44+
45+
@Column(name = "zone_id")
46+
private long zoneId;
47+
48+
@Column(name = "account_id")
49+
private long accountId;
50+
51+
@Column(name = "domain_id")
52+
private long domainId;
53+
54+
@Column(name = "state")
55+
private String state;
56+
57+
@Column(name = "created")
58+
@Temporal(value = TemporalType.TIMESTAMP)
59+
private Date created = null;
60+
61+
@Column(name = "removed")
62+
@Temporal(value = TemporalType.TIMESTAMP)
63+
private Date removed = null;
64+
65+
protected UsageNetworksVO() {
66+
}
67+
68+
public UsageNetworksVO(long id, long networkId, long networkOfferingId, long zoneId, long accountId, long domainId, String state, Date created, Date removed) {
69+
this.id = id;
70+
this.networkId = networkId;
71+
this.networkOfferingId = networkOfferingId;
72+
this.zoneId = zoneId;
73+
this.domainId = domainId;
74+
this.accountId = accountId;
75+
this.state = state;
76+
this.created = created;
77+
this.removed = removed;
78+
}
79+
80+
public UsageNetworksVO(long networkId, long networkOfferingId, long zoneId, long accountId, long domainId, String state, Date created, Date removed) {
81+
this.networkId = networkId;
82+
this.networkOfferingId = networkOfferingId;
83+
this.zoneId = zoneId;
84+
this.domainId = domainId;
85+
this.accountId = accountId;
86+
this.state = state;
87+
this.created = created;
88+
this.removed = removed;
89+
}
90+
91+
@Override
92+
public long getId() {
93+
return id;
94+
}
95+
96+
public long getZoneId() {
97+
return zoneId;
98+
}
99+
100+
public long getAccountId() {
101+
return accountId;
102+
}
103+
104+
public long getDomainId() {
105+
return domainId;
106+
}
107+
108+
public long getNetworkId() {
109+
return networkId;
110+
}
111+
112+
public void setNetworkId(long networkId) {
113+
this.networkId = networkId;
114+
}
115+
116+
public long getNetworkOfferingId() {
117+
return networkOfferingId;
118+
}
119+
120+
public void setNetworkOfferingId(long networkOfferingId) {
121+
this.networkOfferingId = networkOfferingId;
122+
}
123+
124+
public String getState() {
125+
return state;
126+
}
127+
128+
public void setState(String state) {
129+
this.state = state;
130+
}
131+
132+
public Date getCreated() {
133+
return created;
134+
}
135+
136+
public Date getRemoved() {
137+
return removed;
138+
}
139+
140+
public void setRemoved(Date removed) {
141+
this.removed = removed;
142+
}
143+
}

engine/schema/src/main/java/com/cloud/usage/UsageVO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public class UsageVO implements Usage, InternalIdentity {
113113
@Column(name = "is_hidden")
114114
private boolean isHidden = false;
115115

116+
@Column(name = "state")
117+
private String state;
118+
116119
public Integer getQuotaCalculated() {
117120
return quotaCalculated;
118121
}
@@ -401,6 +404,14 @@ public void setHidden(boolean hidden) {
401404
this.isHidden = hidden;
402405
}
403406

407+
public String getState() {
408+
return state;
409+
}
410+
411+
public void setState(String state) {
412+
this.state = state;
413+
}
414+
404415
@Override
405416
public String toString() {
406417
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "usageId", "usageType");
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.usage.dao;
18+
19+
import com.cloud.usage.UsageNetworksVO;
20+
import com.cloud.utils.db.GenericDao;
21+
22+
import java.util.Date;
23+
import java.util.List;
24+
25+
public interface UsageNetworksDao extends GenericDao<UsageNetworksVO, Long> {
26+
void update(long networkId, long newNetworkOffering, String state);
27+
28+
void remove(long networkId, Date removed);
29+
30+
List<UsageNetworksVO> getUsageRecords(Long accountId, Date startDate, Date endDate);
31+
}

0 commit comments

Comments
 (0)