Skip to content

Commit fec3b1f

Browse files
nitinmehDaanHoogland
authored andcommitted
CLOUDSTACK-6530: Make Network and Volume implement Displayable interface. Iterate over all first class entities in the context to decide the display property for event display.
(cherry picked from commit da0545f) Conflicts: api/src/org/apache/cloudstack/api/BaseCmd.java
1 parent 920f39b commit fec3b1f

14 files changed

Lines changed: 62 additions & 64 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323

2424
import org.apache.cloudstack.acl.ControlledEntity;
25+
import org.apache.cloudstack.api.Displayable;
2526
import org.apache.cloudstack.api.Identity;
2627
import org.apache.cloudstack.api.InternalIdentity;
2728

@@ -34,7 +35,7 @@
3435
/**
3536
* owned by an account.
3637
*/
37-
public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity, Serializable {
38+
public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity, Serializable, Displayable {
3839

3940
public enum GuestType {
4041
Shared, Isolated
@@ -327,8 +328,11 @@ public void setIp6Address(String ip6Address) {
327328

328329
boolean getSpecifyIpRanges();
329330

331+
@Deprecated
330332
boolean getDisplayNetwork();
331333

334+
boolean isDisplay();
335+
332336
String getGuruName();
333337

334338
/**

‎api/src/com/cloud/network/NetworkProfile.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ public boolean getDisplayNetwork() {
248248
return displayNetwork;
249249
}
250250

251+
@Override
252+
public boolean isDisplay(){
253+
return displayNetwork;
254+
}
255+
251256
@Override
252257
public Long getVpcId() {
253258
return vpcId;

‎api/src/com/cloud/network/rules/FirewallRule.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import java.util.List;
2020

2121
import org.apache.cloudstack.acl.ControlledEntity;
22+
import org.apache.cloudstack.api.Displayable;
2223
import org.apache.cloudstack.api.Identity;
2324
import org.apache.cloudstack.api.InternalIdentity;
2425

25-
public interface FirewallRule extends ControlledEntity, Identity, InternalIdentity {
26+
public interface FirewallRule extends ControlledEntity, Identity, InternalIdentity, Displayable {
2627
enum Purpose {
2728
Firewall, PortForwarding, LoadBalancing, Vpn, StaticNat, NetworkACL,
2829
}
@@ -87,6 +88,7 @@ enum TrafficType {
8788
*/
8889
TrafficType getTrafficType();
8990

91+
@Override
9092
boolean isDisplay();
9193

9294
}

‎api/src/com/cloud/storage/Volume.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
import java.util.Date;
2020

2121
import org.apache.cloudstack.acl.ControlledEntity;
22+
import org.apache.cloudstack.api.Displayable;
2223
import org.apache.cloudstack.api.Identity;
2324
import org.apache.cloudstack.api.InternalIdentity;
2425

2526
import com.cloud.template.BasedOn;
2627
import com.cloud.utils.fsm.StateMachine2;
2728
import com.cloud.utils.fsm.StateObject;
2829

29-
public interface Volume extends ControlledEntity, Identity, InternalIdentity, BasedOn, StateObject<Volume.State> {
30+
public interface Volume extends ControlledEntity, Identity, InternalIdentity, BasedOn, StateObject<Volume.State>, Displayable {
3031
enum Type {
3132
UNKNOWN, ROOT, SWAP, DATADISK, ISO
3233
};
@@ -191,5 +192,8 @@ enum Event {
191192

192193
Integer getHypervisorSnapshotReserve();
193194

195+
@Deprecated
194196
boolean isDisplayVolume();
197+
198+
boolean isDisplay();
195199
}

‎api/src/org/apache/cloudstack/api/BaseAsyncCmd.java‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package org.apache.cloudstack.api;
1818

1919

20-
import com.cloud.event.EventTypes;
21-
import org.apache.cloudstack.context.CallContext;
2220
import org.apache.log4j.Logger;
2321

2422
/**
@@ -95,26 +93,4 @@ public Object getJob() {
9593
return job;
9694
}
9795

98-
@Override
99-
public boolean isDisplay(){
100-
101-
// Get entity Class from the event name. Eg. - Volume.class
102-
final CallContext ctx = CallContext.current();
103-
Class entityClass = EventTypes.getEntityClassForEvent(getEventType());
104-
boolean isDisplay = true;
105-
106-
try{
107-
// If the entity Class implements Displayable interface then see the flag from VO
108-
if (entityClass != null && Displayable.class.isAssignableFrom(entityClass)){
109-
Object objVO =_entityMgr.findById(entityClass, (Long)ctx.getContextParameter(entityClass.getName()));
110-
isDisplay = ((Displayable)objVO).isDisplay();
111-
ctx.setEventDisplayEnabled(isDisplay);
112-
}
113-
}catch (Exception e){
114-
s_logger.trace("Caught exception while finding the display property, defaulting to true and moving on " +e);
115-
}
116-
117-
return isDisplay;
118-
}
119-
12096
}

‎api/src/org/apache/cloudstack/api/BaseCmd.java‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public boolean isDisplay(){
371371
Object key = entry.getKey();
372372
Class clz = Class.forName((String)key);
373373
if(Displayable.class.isAssignableFrom(clz)){
374-
final Object objVO = getEntityVO(clz, entry.getValue());
374+
final Object objVO = _entityMgr.findById(clz, getInternalId(entry.getValue()));
375375
isDisplay = ((Displayable) objVO).isDisplay();
376376
}
377377

@@ -388,25 +388,17 @@ public boolean isDisplay(){
388388

389389
}
390390

391-
private Object getEntityVO(Class entityType, Object entityId){
391+
private static Long getInternalId(Object internalIdObj){
392+
Long internalId = null;
392393

393-
// entityId can be internal db id or UUID so accordingly call findbyId or findByUUID
394-
395-
if (entityId instanceof Long){
396-
// Its internal db id - use findById
397-
return _entityMgr.findById(entityType, (Long)entityId);
398-
} else if(entityId instanceof String){
399-
try{
400-
// In case its an async job the internal db id would be a string because of json deserialization
401-
Long internalId = Long.valueOf((String) entityId);
402-
return _entityMgr.findById(entityType, internalId);
403-
} catch (NumberFormatException e){
404-
// It is uuid - use findByUuid`
405-
return _entityMgr.findByUuid(entityType, (String)entityId);
406-
}
394+
// In case its an async job the value would be a string because of json deserialization
395+
if(internalIdObj instanceof String){
396+
internalId = Long.valueOf((String) internalIdObj);
397+
}else if (internalIdObj instanceof Long){
398+
internalId = (Long) internalIdObj;
407399
}
408400

409-
return null;
401+
return internalId;
410402
}
411403

412404
}

‎api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ public Boolean getDisplayNetwork() {
213213
return displayNetwork;
214214
}
215215

216+
@Override
217+
public boolean isDisplay() {
218+
if(displayNetwork == null)
219+
return true;
220+
else
221+
return displayNetwork;
222+
}
223+
216224
public Long getZoneId() {
217225
Long physicalNetworkId = getPhysicalNetworkId();
218226

‎api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,6 @@ public long getEntityOwnerId() {
150150
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
151151
}
152152

153-
@Override
154-
public boolean isDisplay(){
155-
UserVm userVm = _entityMgr.findById(UserVm.class, getId());
156-
if (userVm != null) {
157-
return userVm.isDisplayVm();
158-
}
159-
160-
return true; // no info means true
161-
}
162-
163153
@Override
164154
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
165155
CallContext.current().setEventDetails("Vm Id: " + getId());

‎api/src/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ public long getEntityOwnerId() {
117117
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
118118
}
119119

120-
@Override
121-
public boolean isDisplay(){
122-
return _userVmService.isDisplayResourceEnabled(getId());
123-
}
124-
125120
@Override
126121
public void execute() throws ResourceAllocationException {
127122
CallContext.current().setEventDetails("Vm Id: " + getId());

‎api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ public Boolean getDisplayVolume() {
157157
return displayVolume;
158158
}
159159

160+
@Override
161+
public boolean isDisplay() {
162+
if(displayVolume == null)
163+
return true;
164+
else
165+
return displayVolume;
166+
}
167+
160168
public Long getVirtualMachineId() {
161169
return virtualMachineId;
162170
}

0 commit comments

Comments
 (0)