Skip to content

Commit da0545f

Browse files
committed
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.
1 parent b9bdaf9 commit da0545f

14 files changed

Lines changed: 92 additions & 48 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: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,44 @@ public void validateSpecificParameters(final Map<String, String> params){
361361
* @return display flag
362362
*/
363363
public boolean isDisplay(){
364-
return true;
364+
CallContext context = CallContext.current();
365+
Map<Object, Object> contextMap = context.getContextParameters();
366+
boolean isDisplay = true;
367+
368+
// Iterate over all the first class entities in context and check their display property.
369+
for(Map.Entry<Object, Object> entry : contextMap.entrySet()){
370+
try{
371+
Object key = entry.getKey();
372+
Class clz = Class.forName((String)key);
373+
if(Displayable.class.isAssignableFrom(clz)){
374+
final Object objVO = _entityMgr.findById(clz, getInternalId(entry.getValue()));
375+
isDisplay = ((Displayable) objVO).isDisplay();
376+
}
377+
378+
// If the flag is false break immediately
379+
if(!isDisplay)
380+
break;
381+
} catch (Exception e){
382+
s_logger.trace("Caught exception while checking first class entities for display property, continuing on", e);
383+
}
384+
}
385+
386+
context.setEventDisplayEnabled(isDisplay);
387+
return isDisplay;
388+
365389
}
390+
391+
private static Long getInternalId(Object internalIdObj){
392+
Long internalId = null;
393+
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;
399+
}
400+
401+
return internalId;
402+
}
403+
366404
}

‎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
@@ -212,6 +212,14 @@ public Boolean getDisplayNetwork() {
212212
return displayNetwork;
213213
}
214214

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

‎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
@@ -161,6 +161,14 @@ public Boolean getDisplayVolume() {
161161
return displayVolume;
162162
}
163163

164+
@Override
165+
public boolean isDisplay() {
166+
if(displayVolume == null)
167+
return true;
168+
else
169+
return displayVolume;
170+
}
171+
164172
public Long getVirtualMachineId() {
165173
return virtualMachineId;
166174
}

0 commit comments

Comments
 (0)