Skip to content

Commit a1ab336

Browse files
nitinmehDaanHoogland
authored andcommitted
CLOUDSTACK-6895: 1. Populate firstclass entities as uuids in the context instead of dbids for performance.
2. Add ctxDetails in the ParamGenericValidationWorker to avoid warning for api validation 3. Add some missing events. 4. Correcting mapping for ResourceObjectType.NetworkACL and ResourceObjectType.NetworkACLItem (cherry picked from commit 8a9092c) Conflicts: api/src/com/cloud/event/EventTypes.java api/src/org/apache/cloudstack/api/BaseCmd.java
1 parent d6a92b4 commit a1ab336

11 files changed

Lines changed: 104 additions & 43 deletions

File tree

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22-
import com.cloud.server.ResourceTag;
23-
import com.cloud.vm.ConsoleProxy;
24-
import com.cloud.vm.SecondaryStorageVm;
2522
import org.apache.cloudstack.config.Configuration;
2623

2724
import com.cloud.dc.DataCenter;
@@ -37,14 +34,20 @@
3734
import com.cloud.network.PhysicalNetworkTrafficType;
3835
import com.cloud.network.PublicIpAddress;
3936
import com.cloud.network.RemoteAccessVpn;
37+
import com.cloud.network.Site2SiteCustomerGateway;
38+
import com.cloud.network.Site2SiteVpnConnection;
39+
import com.cloud.network.Site2SiteVpnGateway;
4040
import com.cloud.network.as.AutoScaleCounter;
4141
import com.cloud.network.as.AutoScalePolicy;
4242
import com.cloud.network.as.AutoScaleVmGroup;
4343
import com.cloud.network.as.AutoScaleVmProfile;
4444
import com.cloud.network.as.Condition;
4545
import com.cloud.network.router.VirtualRouter;
46+
import com.cloud.network.rules.FirewallRule;
47+
import com.cloud.network.rules.HealthCheckPolicy;
4648
import com.cloud.network.rules.LoadBalancer;
4749
import com.cloud.network.rules.StaticNat;
50+
import com.cloud.network.rules.StickinessPolicy;
4851
import com.cloud.network.security.SecurityGroup;
4952
import com.cloud.network.vpc.PrivateGateway;
5053
import com.cloud.network.vpc.StaticRoute;
@@ -53,13 +56,16 @@
5356
import com.cloud.offering.NetworkOffering;
5457
import com.cloud.offering.ServiceOffering;
5558
import com.cloud.projects.Project;
59+
import com.cloud.server.ResourceTag;
5660
import com.cloud.storage.GuestOS;
5761
import com.cloud.storage.GuestOSHypervisor;
5862
import com.cloud.storage.Snapshot;
5963
import com.cloud.storage.Volume;
6064
import com.cloud.template.VirtualMachineTemplate;
6165
import com.cloud.user.Account;
6266
import com.cloud.user.User;
67+
import com.cloud.vm.ConsoleProxy;
68+
import com.cloud.vm.SecondaryStorageVm;
6369
import com.cloud.vm.VirtualMachine;
6470

6571
public class EventTypes {
@@ -548,12 +554,16 @@ public class EventTypes {
548554
entityEventDetails.put(EVENT_FIREWALL_CLOSE, Network.class);
549555

550556
// Load Balancers
551-
entityEventDetails.put(EVENT_ASSIGN_TO_LOAD_BALANCER_RULE, LoadBalancer.class);
552-
entityEventDetails.put(EVENT_REMOVE_FROM_LOAD_BALANCER_RULE, LoadBalancer.class);
557+
entityEventDetails.put(EVENT_ASSIGN_TO_LOAD_BALANCER_RULE, FirewallRule.class);
558+
entityEventDetails.put(EVENT_REMOVE_FROM_LOAD_BALANCER_RULE, FirewallRule.class);
553559
entityEventDetails.put(EVENT_LOAD_BALANCER_CREATE, LoadBalancer.class);
554-
entityEventDetails.put(EVENT_LOAD_BALANCER_DELETE, LoadBalancer.class);
555-
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_CREATE, LoadBalancer.class);
556-
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_DELETE, LoadBalancer.class);
560+
entityEventDetails.put(EVENT_LOAD_BALANCER_DELETE, FirewallRule.class);
561+
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_CREATE, StickinessPolicy.class);
562+
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_UPDATE, StickinessPolicy.class);
563+
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_DELETE, StickinessPolicy.class);
564+
entityEventDetails.put(EVENT_LB_HEALTHCHECKPOLICY_CREATE, HealthCheckPolicy.class);
565+
entityEventDetails.put(EVENT_LB_HEALTHCHECKPOLICY_UPDATE, HealthCheckPolicy.class);
566+
entityEventDetails.put(EVENT_LB_HEALTHCHECKPOLICY_DELETE, HealthCheckPolicy.class);
557567
entityEventDetails.put(EVENT_LOAD_BALANCER_UPDATE, LoadBalancer.class);
558568
entityEventDetails.put(EVENT_LB_CERT_UPLOAD, LoadBalancer.class);
559569
entityEventDetails.put(EVENT_LB_CERT_DELETE, LoadBalancer.class);
@@ -693,14 +703,14 @@ public class EventTypes {
693703
entityEventDetails.put(EVENT_REMOTE_ACCESS_VPN_DESTROY, RemoteAccessVpn.class);
694704
entityEventDetails.put(EVENT_VPN_USER_ADD, RemoteAccessVpn.class);
695705
entityEventDetails.put(EVENT_VPN_USER_REMOVE, RemoteAccessVpn.class);
696-
entityEventDetails.put(EVENT_S2S_VPN_GATEWAY_CREATE, RemoteAccessVpn.class);
697-
entityEventDetails.put(EVENT_S2S_VPN_GATEWAY_DELETE, RemoteAccessVpn.class);
698-
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE, RemoteAccessVpn.class);
699-
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE, RemoteAccessVpn.class);
700-
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE, RemoteAccessVpn.class);
701-
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_CREATE, RemoteAccessVpn.class);
702-
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_DELETE, RemoteAccessVpn.class);
703-
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_RESET, RemoteAccessVpn.class);
706+
entityEventDetails.put(EVENT_S2S_VPN_GATEWAY_CREATE, Site2SiteVpnGateway.class);
707+
entityEventDetails.put(EVENT_S2S_VPN_GATEWAY_DELETE, Site2SiteVpnGateway.class);
708+
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE, Site2SiteCustomerGateway.class);
709+
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE, Site2SiteCustomerGateway.class);
710+
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE, Site2SiteCustomerGateway.class);
711+
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_CREATE, Site2SiteVpnConnection.class);
712+
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_DELETE, Site2SiteVpnConnection.class);
713+
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_RESET, Site2SiteVpnConnection.class);
704714

705715
// Custom certificates
706716
entityEventDetails.put(EVENT_UPLOAD_CUSTOM_CERTIFICATE, "Certificate");

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class ApiConstants {
5858
public static final String CPU_SPEED = "cpuspeed";
5959
public static final String CREATED = "created";
6060
public static final String CTX_ACCOUNT_ID = "ctxaccountid";
61+
public static final String CTX_DETAILS = "ctxDetails";
6162
public static final String CTX_USER_ID = "ctxuserid";
6263
public static final String CTXSTARTEVENTID = "ctxstarteventid";
6364
public static final String CTX_START_EVENT_ID = "ctxStartEventId";

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,52 @@ 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 = getEntityVO(clz, 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 Object getEntityVO(Class entityType, Object entityId){
392+
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+
}
407+
}
408+
409+
return null;
410+
}
411+
366412
}

server/src/com/cloud/api/ApiServer.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
617617
params.put("id", objectId.toString());
618618
Class entityClass = EventTypes.getEntityClassForEvent(createCmd.getEventType());
619619
if (entityClass != null)
620-
ctx.putContextParameter(entityClass.getName(), objectId);
620+
ctx.putContextParameter(entityClass.getName(), objectUuid);
621621
} else {
622622
// Extract the uuid before params are processed and id reflects internal db id
623623
objectUuid = params.get(ApiConstants.ID);
@@ -639,12 +639,6 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
639639
long startEventId = ctx.getStartEventId();
640640
asyncCmd.setStartEventId(startEventId);
641641

642-
// Add the resource id in the call context, also add some other first class object ids (for now vm) if available.
643-
// TODO - this should be done for all the uuids passed in the cmd - so should be moved where uuid to id conversion happens.
644-
if (EventTypes.getEntityForEvent(asyncCmd.getEventType()) != null) {
645-
ctx.putContextParameter(EventTypes.getEntityForEvent(asyncCmd.getEventType()), objectUuid);
646-
}
647-
648642
// save the scheduled event
649643
final Long eventId =
650644
ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(),

server/src/com/cloud/api/dispatch/ParamGenericValidationWorker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class ParamGenericValidationWorker implements DispatchWorker {
6363
defaultParamNames.add(ApiConstants.CTX_ACCOUNT_ID);
6464
defaultParamNames.add(ApiConstants.CTX_START_EVENT_ID);
6565
defaultParamNames.add(ApiConstants.CTX_USER_ID);
66+
defaultParamNames.add(ApiConstants.CTX_DETAILS);
6667
defaultParamNames.add(ApiConstants.UUID);
6768
defaultParamNames.add(ApiConstants.ID);
6869
defaultParamNames.add("_");

server/src/com/cloud/api/dispatch/ParamProcessWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ private Long translateUuidToInternalId(final String uuid, final Parameter annota
427427
}
428428
// Return on first non-null Id for the uuid entity
429429
if (internalId != null){
430-
CallContext.current().putContextParameter(entity.getName(), internalId);
430+
CallContext.current().putContextParameter(entity.getName(), uuid);
431431
break;
432432
}
433433
}

server/src/com/cloud/event/ActionEventUtils.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ private static void publishOnEventBus(long userId, long accountId, String eventC
206206
//Get uuid from id
207207
if(context.getContextParameter(entityClass.getName()) != null){
208208
try {
209-
final Object objVO = s_entityMgr.findByIdIncludingRemoved(entityClass, getInternalId(context.getContextParameter(entityClass.getName())));
210-
entityUuid = ((Identity)objVO).getUuid();
209+
entityUuid = getEntityUuid(entityClass, context.getContextParameter(entityClass.getName()));
211210
} catch (Exception e){
212211
s_logger.debug("Caught exception while finding entityUUID, moving on");
213212
}
@@ -250,17 +249,27 @@ private static void publishOnEventBus(long userId, long accountId, String eventC
250249
}
251250
}
252251

253-
private static Long getInternalId(Object internalIdObj){
254-
Long internalId = null;
255-
256-
// In case its an async job the value would be a string because of json deserialization
257-
if(internalIdObj instanceof String){
258-
internalId = Long.valueOf((String) internalIdObj);
259-
}else if (internalIdObj instanceof Long){
260-
internalId = (Long) internalIdObj;
252+
private static String getEntityUuid(Class entityType, Object entityId){
253+
254+
// entityId can be internal db id or UUID so accordingly call findbyId or return uuid directly
255+
256+
if (entityId instanceof Long){
257+
// Its internal db id - use findById
258+
final Object objVO = s_entityMgr.findById(entityType, (Long)entityId);
259+
return ((Identity)objVO).getUuid();
260+
} else if(entityId instanceof String){
261+
try{
262+
// In case its an async job the internal db id would be a string because of json deserialization
263+
Long internalId = Long.valueOf((String) entityId);
264+
final Object objVO = s_entityMgr.findById(entityType, internalId);
265+
return ((Identity)objVO).getUuid();
266+
} catch (NumberFormatException e){
267+
// It is uuid - so return it
268+
return (String)entityId;
269+
}
261270
}
262271

263-
return internalId;
272+
return null;
264273
}
265274

266275
private static long getDomainId(long accountId) {
@@ -282,8 +291,7 @@ private static void populateFirstClassEntities(Map<String, String> eventDescript
282291
Object key = entry.getKey();
283292
Class clz = Class.forName((String)key);
284293
if(clz instanceof Class && Identity.class.isAssignableFrom(clz)){
285-
final Object objVO = s_entityMgr.findById(clz, getInternalId(entry.getValue()));
286-
String uuid = ((Identity) objVO).getUuid();
294+
String uuid = getEntityUuid(clz, entry.getValue());
287295
eventDescription.put(ReflectUtil.getEntityName(clz), uuid);
288296
}
289297
}

server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ public NetworkACLItem getNetworkACLItem(long ruleId) {
271271
}
272272

273273
@Override
274-
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_DELETE, eventDescription = "revoking network acl", async = true)
275274
public boolean revokeNetworkACLItem(long ruleId) {
276275

277276
NetworkACLItemVO rule = _networkACLItemDao.findById(ruleId);

server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(ListNetworkACLL
206206
}
207207

208208
@Override
209+
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_DELETE, eventDescription = "Deleting Network ACL List", async = true)
209210
public boolean deleteNetworkACL(long id) {
210211
Account caller = CallContext.current().getCallingAccount();
211212
NetworkACL acl = _networkACLDao.findById(id);

server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
119119
}
120120

121121
@Override
122-
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE, eventDescription = "creating s2s vpn gateway", create = true)
122+
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE, eventDescription = "creating s2s vpn gateway", async = true)
123123
public Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd) {
124124
Account caller = CallContext.current().getCallingAccount();
125125
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
@@ -311,6 +311,7 @@ public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) th
311311

312312
@Override
313313
@DB
314+
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "starting s2s vpn connection", async = true)
314315
public Site2SiteVpnConnection startVpnConnection(long id) throws ResourceUnavailableException {
315316
Site2SiteVpnConnectionVO conn = _vpnConnectionDao.acquireInLockTable(id);
316317
if (conn == null) {
@@ -387,7 +388,7 @@ protected void doDeleteVpnGateway(Site2SiteVpnGateway gw) {
387388
}
388389

389390
@Override
390-
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_DELETE, eventDescription = "deleting s2s vpn gateway", create = true)
391+
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_DELETE, eventDescription = "deleting s2s vpn gateway", async = true)
391392
public boolean deleteVpnGateway(DeleteVpnGatewayCmd cmd) {
392393
CallContext.current().setEventDetails(" Id: " + cmd.getId());
393394
Account caller = CallContext.current().getCallingAccount();

0 commit comments

Comments
 (0)