mirror of https://github.com/apache/cloudstack.git
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 da0545ff86)
Conflicts:
api/src/org/apache/cloudstack/api/BaseCmd.java
This commit is contained in:
parent
920f39baaf
commit
fec3b1f865
|
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.Displayable;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
|
|
@ -34,7 +35,7 @@ import com.cloud.utils.fsm.StateObject;
|
|||
/**
|
||||
* owned by an account.
|
||||
*/
|
||||
public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity, Serializable {
|
||||
public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity, Serializable, Displayable {
|
||||
|
||||
public enum GuestType {
|
||||
Shared, Isolated
|
||||
|
|
@ -327,8 +328,11 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
|
|||
|
||||
boolean getSpecifyIpRanges();
|
||||
|
||||
@Deprecated
|
||||
boolean getDisplayNetwork();
|
||||
|
||||
boolean isDisplay();
|
||||
|
||||
String getGuruName();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -248,6 +248,11 @@ public class NetworkProfile implements Network {
|
|||
return displayNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay(){
|
||||
return displayNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getVpcId() {
|
||||
return vpcId;
|
||||
|
|
|
|||
|
|
@ -19,10 +19,11 @@ package com.cloud.network.rules;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.Displayable;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
public interface FirewallRule extends ControlledEntity, Identity, InternalIdentity {
|
||||
public interface FirewallRule extends ControlledEntity, Identity, InternalIdentity, Displayable {
|
||||
enum Purpose {
|
||||
Firewall, PortForwarding, LoadBalancing, Vpn, StaticNat, NetworkACL,
|
||||
}
|
||||
|
|
@ -87,6 +88,7 @@ public interface FirewallRule extends ControlledEntity, Identity, InternalIdenti
|
|||
*/
|
||||
TrafficType getTrafficType();
|
||||
|
||||
@Override
|
||||
boolean isDisplay();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.storage;
|
|||
import java.util.Date;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.Displayable;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
|
|
@ -26,7 +27,7 @@ import com.cloud.template.BasedOn;
|
|||
import com.cloud.utils.fsm.StateMachine2;
|
||||
import com.cloud.utils.fsm.StateObject;
|
||||
|
||||
public interface Volume extends ControlledEntity, Identity, InternalIdentity, BasedOn, StateObject<Volume.State> {
|
||||
public interface Volume extends ControlledEntity, Identity, InternalIdentity, BasedOn, StateObject<Volume.State>, Displayable {
|
||||
enum Type {
|
||||
UNKNOWN, ROOT, SWAP, DATADISK, ISO
|
||||
};
|
||||
|
|
@ -191,5 +192,8 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba
|
|||
|
||||
Integer getHypervisorSnapshotReserve();
|
||||
|
||||
@Deprecated
|
||||
boolean isDisplayVolume();
|
||||
|
||||
boolean isDisplay();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@
|
|||
package org.apache.cloudstack.api;
|
||||
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -95,26 +93,4 @@ public abstract class BaseAsyncCmd extends BaseCmd {
|
|||
return job;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay(){
|
||||
|
||||
// Get entity Class from the event name. Eg. - Volume.class
|
||||
final CallContext ctx = CallContext.current();
|
||||
Class entityClass = EventTypes.getEntityClassForEvent(getEventType());
|
||||
boolean isDisplay = true;
|
||||
|
||||
try{
|
||||
// If the entity Class implements Displayable interface then see the flag from VO
|
||||
if (entityClass != null && Displayable.class.isAssignableFrom(entityClass)){
|
||||
Object objVO =_entityMgr.findById(entityClass, (Long)ctx.getContextParameter(entityClass.getName()));
|
||||
isDisplay = ((Displayable)objVO).isDisplay();
|
||||
ctx.setEventDisplayEnabled(isDisplay);
|
||||
}
|
||||
}catch (Exception e){
|
||||
s_logger.trace("Caught exception while finding the display property, defaulting to true and moving on " +e);
|
||||
}
|
||||
|
||||
return isDisplay;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ public abstract class BaseCmd {
|
|||
Object key = entry.getKey();
|
||||
Class clz = Class.forName((String)key);
|
||||
if(Displayable.class.isAssignableFrom(clz)){
|
||||
final Object objVO = getEntityVO(clz, entry.getValue());
|
||||
final Object objVO = _entityMgr.findById(clz, getInternalId(entry.getValue()));
|
||||
isDisplay = ((Displayable) objVO).isDisplay();
|
||||
}
|
||||
|
||||
|
|
@ -388,25 +388,17 @@ public abstract class BaseCmd {
|
|||
|
||||
}
|
||||
|
||||
private Object getEntityVO(Class entityType, Object entityId){
|
||||
private static Long getInternalId(Object internalIdObj){
|
||||
Long internalId = null;
|
||||
|
||||
// entityId can be internal db id or UUID so accordingly call findbyId or findByUUID
|
||||
|
||||
if (entityId instanceof Long){
|
||||
// Its internal db id - use findById
|
||||
return _entityMgr.findById(entityType, (Long)entityId);
|
||||
} else if(entityId instanceof String){
|
||||
try{
|
||||
// In case its an async job the internal db id would be a string because of json deserialization
|
||||
Long internalId = Long.valueOf((String) entityId);
|
||||
return _entityMgr.findById(entityType, internalId);
|
||||
} catch (NumberFormatException e){
|
||||
// It is uuid - use findByUuid`
|
||||
return _entityMgr.findByUuid(entityType, (String)entityId);
|
||||
}
|
||||
// In case its an async job the value would be a string because of json deserialization
|
||||
if(internalIdObj instanceof String){
|
||||
internalId = Long.valueOf((String) internalIdObj);
|
||||
}else if (internalIdObj instanceof Long){
|
||||
internalId = (Long) internalIdObj;
|
||||
}
|
||||
|
||||
return null;
|
||||
return internalId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,6 +213,14 @@ public class CreateNetworkCmd extends BaseCmd {
|
|||
return displayNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay() {
|
||||
if(displayNetwork == null)
|
||||
return true;
|
||||
else
|
||||
return displayNetwork;
|
||||
}
|
||||
|
||||
public Long getZoneId() {
|
||||
Long physicalNetworkId = getPhysicalNetworkId();
|
||||
|
||||
|
|
|
|||
|
|
@ -150,16 +150,6 @@ public class UpdateVMCmd extends BaseCustomIdCmd {
|
|||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay(){
|
||||
UserVm userVm = _entityMgr.findById(UserVm.class, getId());
|
||||
if (userVm != null) {
|
||||
return userVm.isDisplayVm();
|
||||
}
|
||||
|
||||
return true; // no info means true
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
|
||||
CallContext.current().setEventDetails("Vm Id: " + getId());
|
||||
|
|
|
|||
|
|
@ -117,11 +117,6 @@ public class UpgradeVMCmd extends BaseCmd {
|
|||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay(){
|
||||
return _userVmService.isDisplayResourceEnabled(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceAllocationException {
|
||||
CallContext.current().setEventDetails("Vm Id: " + getId());
|
||||
|
|
|
|||
|
|
@ -157,6 +157,14 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd {
|
|||
return displayVolume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay() {
|
||||
if(displayVolume == null)
|
||||
return true;
|
||||
else
|
||||
return displayVolume;
|
||||
}
|
||||
|
||||
public Long getVirtualMachineId() {
|
||||
return virtualMachineId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,11 +79,6 @@ public class DeleteVolumeCmd extends BaseCmd {
|
|||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay(){
|
||||
return _volumeService.isDisplayResourceEnabled(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ConcurrentOperationException {
|
||||
CallContext.current().setEventDetails("Volume Id: " + getId());
|
||||
|
|
|
|||
|
|
@ -577,6 +577,11 @@ public class NetworkVO implements Network {
|
|||
this.displayNetwork = displayNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay(){
|
||||
return displayNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetworkACLId(Long networkACLId) {
|
||||
this.networkACLId = networkACLId;
|
||||
|
|
|
|||
|
|
@ -552,6 +552,15 @@ public class VolumeVO implements Volume {
|
|||
return displayVolume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay(){
|
||||
return displayVolume;
|
||||
}
|
||||
|
||||
public void setDisplay(boolean display){
|
||||
this.displayVolume = display;
|
||||
}
|
||||
|
||||
public void setDisplayVolume(boolean displayVolume) {
|
||||
this.displayVolume = displayVolume;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,11 @@ public class VolumeObject implements VolumeInfo {
|
|||
return volumeVO.isDisplayVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay() {
|
||||
return volumeVO.isDisplay();
|
||||
}
|
||||
|
||||
public long getVolumeId() {
|
||||
return volumeVO.getId();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue