Skip to content

Commit 3e7ea4e

Browse files
committed
CLOUDSTACK-6530: Populate the first class entities in the context to be available for publishing more information for the event bus, checking the displayable property etc.
1 parent 69add34 commit 3e7ea4e

21 files changed

Lines changed: 419 additions & 305 deletions

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

Lines changed: 243 additions & 226 deletions
Large diffs are not rendered by default.

‎api/src/com/cloud/vm/VirtualMachine.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Map;
2121

2222
import org.apache.cloudstack.acl.ControlledEntity;
23+
import org.apache.cloudstack.api.Displayable;
2324
import org.apache.cloudstack.api.Identity;
2425
import org.apache.cloudstack.api.InternalIdentity;
2526

@@ -31,7 +32,7 @@
3132
* VirtualMachine describes the properties held by a virtual machine
3233
*
3334
*/
34-
public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, InternalIdentity, StateObject<VirtualMachine.State> {
35+
public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, InternalIdentity, Displayable, StateObject<VirtualMachine.State> {
3536

3637
public enum PowerState {
3738
PowerUnknown,
@@ -321,6 +322,7 @@ public boolean isUsedBySystem() {
321322

322323
long getUpdated();
323324

325+
@Override
324326
boolean isDisplay();
325327

326328
}

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

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

1919

20+
import com.cloud.event.EventTypes;
21+
import org.apache.cloudstack.context.CallContext;
22+
import org.apache.log4j.Logger;
23+
2024
/**
2125
* queryAsyncJobResult API command.
2226
*/
@@ -27,6 +31,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
2731
public static final String vpcSyncObject = "vpc";
2832
public static final String snapshotHostSyncObject = "snapshothost";
2933
public static final String gslbSyncObject = "globalserverloadbalacner";
34+
private static final Logger s_logger = Logger.getLogger(BaseAsyncCmd.class.getName());
3035

3136
private Object job;
3237

@@ -89,4 +94,27 @@ public Long getSyncObjId() {
8994
public Object getJob() {
9095
return job;
9196
}
97+
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+
92120
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public void validateSpecificParameters(final Map<String, String> params){
360360
* display flag is used to control the display of the resource only to the end user. It doesnt affect Root Admin.
361361
* @return display flag
362362
*/
363-
public boolean isDisplayResourceEnabled(){
363+
public boolean isDisplay(){
364364
return true;
365365
}
366366
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 org.apache.cloudstack.api;
18+
19+
public interface Displayable {
20+
boolean isDisplay();
21+
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ public Boolean getDisplayVm() {
250250
return displayVm;
251251
}
252252

253+
@Override
254+
public boolean isDisplay() {
255+
if(displayVm == null)
256+
return true;
257+
else
258+
return displayVm;
259+
}
260+
253261
public List<Long> getSecurityGroupIdList() {
254262
if (securityGroupNameList != null && securityGroupIdList != null) {
255263
throw new InvalidParameterValueException("securitygroupids parameter is mutually exclusive with securitygroupnames parameter");
@@ -408,16 +416,6 @@ public long getEntityOwnerId() {
408416
return accountId;
409417
}
410418

411-
@Override
412-
public boolean isDisplayResourceEnabled(){
413-
Boolean display = getDisplayVm();
414-
if(display == null){
415-
return true;
416-
} else {
417-
return display;
418-
}
419-
}
420-
421419
@Override
422420
public String getEventType() {
423421
return EventTypes.EVENT_VM_CREATE;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public long getEntityOwnerId() {
151151
}
152152

153153
@Override
154-
public boolean isDisplayResourceEnabled(){
154+
public boolean isDisplay(){
155155
UserVm userVm = _entityMgr.findById(UserVm.class, getId());
156156
if (userVm != null) {
157157
return userVm.isDisplayVm();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public long getEntityOwnerId() {
118118
}
119119

120120
@Override
121-
public boolean isDisplayResourceEnabled(){
121+
public boolean isDisplay(){
122122
return _userVmService.isDisplayResourceEnabled(getId());
123123
}
124124

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,6 @@ public String getEventType() {
194194
return EventTypes.EVENT_VOLUME_CREATE;
195195
}
196196

197-
@Override
198-
public boolean isDisplayResourceEnabled(){
199-
Boolean display = getDisplayVolume();
200-
if(display == null){
201-
return true;
202-
} else {
203-
return display;
204-
}
205-
}
206-
207197
@Override
208198
public String getEventDescription() {
209199
return "creating volume: " + getVolumeName() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public long getEntityOwnerId() {
8080
}
8181

8282
@Override
83-
public boolean isDisplayResourceEnabled(){
83+
public boolean isDisplay(){
8484
return _volumeService.isDisplayResourceEnabled(getId());
8585
}
8686

0 commit comments

Comments
 (0)