Skip to content

Commit 8a9092c

Browse files
committed
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
1 parent 81857d0 commit 8a9092c

11 files changed

Lines changed: 58 additions & 43 deletions

File tree

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import java.util.Map;
2121

2222
import com.cloud.network.IpAddress;
23+
import com.cloud.network.Site2SiteCustomerGateway;
2324
import com.cloud.network.Site2SiteVpnGateway;
2425
import com.cloud.network.rules.FirewallRule;
2526
import com.cloud.network.rules.HealthCheckPolicy;
2627
import com.cloud.network.rules.StickinessPolicy;
2728
import com.cloud.network.vpc.NetworkACL;
2829
import com.cloud.network.vpc.NetworkACLItem;
30+
import com.cloud.network.Site2SiteVpnConnection;
2931
import com.cloud.server.ResourceTag;
3032
import com.cloud.vm.ConsoleProxy;
3133
import com.cloud.vm.SecondaryStorageVm;
@@ -556,10 +558,10 @@ public class EventTypes {
556558
entityEventDetails.put(EVENT_FIREWALL_CLOSE, FirewallRule.class);
557559

558560
// Load Balancers
559-
entityEventDetails.put(EVENT_ASSIGN_TO_LOAD_BALANCER_RULE, LoadBalancer.class);
560-
entityEventDetails.put(EVENT_REMOVE_FROM_LOAD_BALANCER_RULE, LoadBalancer.class);
561+
entityEventDetails.put(EVENT_ASSIGN_TO_LOAD_BALANCER_RULE, FirewallRule.class);
562+
entityEventDetails.put(EVENT_REMOVE_FROM_LOAD_BALANCER_RULE, FirewallRule.class);
561563
entityEventDetails.put(EVENT_LOAD_BALANCER_CREATE, LoadBalancer.class);
562-
entityEventDetails.put(EVENT_LOAD_BALANCER_DELETE, LoadBalancer.class);
564+
entityEventDetails.put(EVENT_LOAD_BALANCER_DELETE, FirewallRule.class);
563565
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_CREATE, StickinessPolicy.class);
564566
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_UPDATE, StickinessPolicy.class);
565567
entityEventDetails.put(EVENT_LB_STICKINESSPOLICY_DELETE, StickinessPolicy.class);
@@ -707,12 +709,12 @@ public class EventTypes {
707709
entityEventDetails.put(EVENT_VPN_USER_REMOVE, RemoteAccessVpn.class);
708710
entityEventDetails.put(EVENT_S2S_VPN_GATEWAY_CREATE, Site2SiteVpnGateway.class);
709711
entityEventDetails.put(EVENT_S2S_VPN_GATEWAY_DELETE, Site2SiteVpnGateway.class);
710-
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE, RemoteAccessVpn.class);
711-
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE, RemoteAccessVpn.class);
712-
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE, RemoteAccessVpn.class);
713-
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_CREATE, RemoteAccessVpn.class);
714-
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_DELETE, RemoteAccessVpn.class);
715-
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_RESET, RemoteAccessVpn.class);
712+
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE, Site2SiteCustomerGateway.class);
713+
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE, Site2SiteCustomerGateway.class);
714+
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE, Site2SiteCustomerGateway.class);
715+
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_CREATE, Site2SiteVpnConnection.class);
716+
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_DELETE, Site2SiteVpnConnection.class);
717+
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_RESET, Site2SiteVpnConnection.class);
716718

717719
// Custom certificates
718720
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: 17 additions & 9 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 = _entityMgr.findById(clz, getInternalId(entry.getValue()));
374+
final Object objVO = getEntityVO(clz, entry.getValue());
375375
isDisplay = ((Displayable) objVO).isDisplay();
376376
}
377377

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

389389
}
390390

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

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;
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+
}
399407
}
400408

401-
return internalId;
409+
return null;
402410
}
403411

404412
}

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: 20 additions & 12 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;
252+
private static String getEntityUuid(Class entityType, Object entityId){
255253

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;
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
} catch (Exception e){

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
@@ -207,6 +207,7 @@ public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(ListNetworkACLL
207207
}
208208

209209
@Override
210+
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_DELETE, eventDescription = "Deleting Network ACL List", async = true)
210211
public boolean deleteNetworkACL(long id) {
211212
Account caller = CallContext.current().getCallingAccount();
212213
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)