You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/04/09 15:21:03 UTC
[26/50] [abbrv] git commit: updated refs/heads/marvin_refactor to
2a99064
CLOUDSTACK-1795: implement custom AOP to fully support legacy CloudStack AOP semantcis
Signed-off-by: Chip Childers <ch...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/07a63a89
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/07a63a89
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/07a63a89
Branch: refs/heads/marvin_refactor
Commit: 07a63a89b671efb50a05d39d951a0a20cbdafdac
Parents: 646c4fb
Author: Kelven Yang <ke...@gmail.com>
Authored: Wed Mar 27 13:06:49 2013 +0000
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Sun Mar 31 22:07:09 2013 +0530
----------------------------------------------------------------------
client/tomcatconf/applicationContext.xml.in | 27 +-
server/src/com/cloud/api/ApiDispatcher.java | 280 +++++++--------
.../src/com/cloud/network/NetworkManagerImpl.java | 16 +-
server/src/com/cloud/network/NetworkModelImpl.java | 6 +-
.../src/com/cloud/utils/component/AdapterBase.java | 2 +-
.../cloud/utils/component/ComponentContext.java | 40 +-
.../ComponentInstantiationPostProcessor.java | 24 +-
.../component/ComponentMethodInterceptor.java | 2 +-
.../utils/component/ComponentNamingPolicy.java | 6 +-
utils/src/com/cloud/utils/db/GenericDaoBase.java | 2 +-
.../cloud/utils/db/TransactionContextBuilder.java | 24 +-
utils/test/resources/testContext.xml | 16 +-
12 files changed, 213 insertions(+), 232 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in
index da7a380..250d5ef 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -35,27 +35,18 @@
<!--
@DB support
-->
- <aop:config>
- <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
- <aop:pointcut id="captureAnyMethod"
- expression="execution(* *(..))"
- />
-
- <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/>
- </aop:aspect>
-
- <aop:aspect id="actionEventInterceptorAspect" ref="actionEventInterceptor">
- <aop:pointcut id="captureEventMethod"
- expression="execution(* *(..)) and @annotation(com.cloud.event.ActionEvent)"
- />
-
- <aop:around pointcut-ref="captureEventMethod" method="AroundAnyMethod"/>
- </aop:aspect>
- </aop:config>
-
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
<bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
+ <bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
+ <property name="Interceptors">
+ <list>
+ <ref bean="transactionContextBuilder" />
+ <ref bean="actionEventInterceptor" />
+ </list>
+ </property>
+ </bean>
+
<!--
RPC/Async/EventBus
-->
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/server/src/com/cloud/api/ApiDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java
index f7d881d..925d90a 100755
--- a/server/src/com/cloud/api/ApiDispatcher.java
+++ b/server/src/com/cloud/api/ApiDispatcher.java
@@ -31,91 +31,86 @@ import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
-import com.cloud.dao.EntityManager;
-import com.cloud.utils.ReflectUtil;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.InfrastructureEntity;
-import org.apache.cloudstack.acl.Role;
-import org.apache.cloudstack.api.*;
-import org.apache.log4j.Logger;
-
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseCmd.CommandType;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.EntityReference;
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.Validate;
+import org.apache.cloudstack.api.command.user.event.ArchiveEventsCmd;
+import org.apache.cloudstack.api.command.user.event.DeleteEventsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
import com.cloud.async.AsyncCommandQueued;
import com.cloud.async.AsyncJobManager;
-import com.cloud.configuration.Config;
-import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.dao.EntityManager;
import com.cloud.exception.AccountLimitException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.server.ManagementServer;
-import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.UserContext;
import com.cloud.utils.DateUtil;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.Inject;
-import com.cloud.utils.component.PluggableService;
-import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.ReflectUtil;
+import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.exception.CSExceptionErrorCode;
import com.cloud.utils.exception.CloudRuntimeException;
-// ApiDispatcher: A class that dispatches API commands to the appropriate manager for execution.
+@Component
public class ApiDispatcher {
private static final Logger s_logger = Logger.getLogger(ApiDispatcher.class.getName());
- ComponentLocator _locator;
Long _createSnapshotQueueSizeLimit;
- @Inject private AsyncJobManager _asyncMgr = null;
- @Inject private AccountManager _accountMgr = null;
+ @Inject AsyncJobManager _asyncMgr = null;
+ @Inject AccountManager _accountMgr = null;
@Inject EntityManager _entityMgr = null;
- Map<String, Class<? extends GenericDao>> _daoNameMap = new HashMap<String, Class<? extends GenericDao>>();
- // singleton class
- private static ApiDispatcher s_instance = ApiDispatcher.getInstance();
+ private static ApiDispatcher s_instance;
public static ApiDispatcher getInstance() {
- if (s_instance == null) {
- s_instance = ComponentLocator.inject(ApiDispatcher.class);
- }
return s_instance;
}
- protected ApiDispatcher() {
- super();
- _locator = ComponentLocator.getLocator(ManagementServer.Name);
- ConfigurationDao configDao = _locator.getDao(ConfigurationDao.class);
- Map<String, String> configs = configDao.getConfiguration();
- String strSnapshotLimit = configs.get(Config.ConcurrentSnapshotsThresholdPerHost.key());
- if (strSnapshotLimit != null) {
- Long snapshotLimit = NumbersUtil.parseLong(strSnapshotLimit, 1L);
- if (snapshotLimit <= 0) {
- s_logger.debug("Global config parameter " + Config.ConcurrentSnapshotsThresholdPerHost.toString()
- + " is less or equal 0; defaulting to unlimited");
- } else {
- _createSnapshotQueueSizeLimit = snapshotLimit;
- }
- }
- _daoNameMap.put("com.cloud.network.Network", NetworkDao.class);
- _daoNameMap.put("com.cloud.template.VirtualMachineTemplate", VMTemplateDao.class);
+ public ApiDispatcher() {
+ }
+
+ @PostConstruct
+ void init() {
+ s_instance = this;
+ }
+
+ public void setCreateSnapshotQueueSizeLimit(Long snapshotLimit) {
+ _createSnapshotQueueSizeLimit = snapshotLimit;
}
public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map<String, String> params) throws Exception {
processParameters(cmd, params);
- UserContext ctx = UserContext.current();
- ctx.setAccountId(cmd.getEntityOwnerId());
- cmd.create();
+ UserContext ctx = UserContext.current();
+ ctx.setAccountId(cmd.getEntityOwnerId());
+ cmd.create();
}
- private void doAccessChecks(BaseCmd cmd, List<Object> entitiesToAccess) {
+ private void doAccessChecks(BaseCmd cmd, Map<Object, AccessType> entitiesToAccess) {
Account caller = UserContext.current().getCaller();
Account owner = _accountMgr.getActiveAccountById(cmd.getEntityOwnerId());
@@ -127,9 +122,9 @@ public class ApiDispatcher {
if(!entitiesToAccess.isEmpty()){
//check that caller can access the owner account.
_accountMgr.checkAccess(caller, null, true, owner);
- for(Object entity : entitiesToAccess) {
+ for (Object entity : entitiesToAccess.keySet()) {
if (entity instanceof ControlledEntity) {
- _accountMgr.checkAccess(caller, null, true, (ControlledEntity) entity);
+ _accountMgr.checkAccess(caller, entitiesToAccess.get(entity), true, (ControlledEntity) entity);
}
else if (entity instanceof InfrastructureEntity) {
//FIXME: Move this code in adapter, remove code from Account manager
@@ -139,39 +134,40 @@ public class ApiDispatcher {
}
public void dispatch(BaseCmd cmd, Map<String, String> params) throws Exception {
- processParameters(cmd, params);
- UserContext ctx = UserContext.current();
- ctx.setAccountId(cmd.getEntityOwnerId());
- if (cmd instanceof BaseAsyncCmd) {
-
- BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmd;
- String startEventId = params.get("ctxStartEventId");
- ctx.setStartEventId(Long.valueOf(startEventId));
-
- // Synchronise job on the object if needed
- if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) {
- Long queueSizeLimit = null;
- if (asyncCmd.getSyncObjType() != null && asyncCmd.getSyncObjType().equalsIgnoreCase(BaseAsyncCmd.snapshotHostSyncObject)) {
- queueSizeLimit = _createSnapshotQueueSizeLimit;
- } else {
- queueSizeLimit = 1L;
- }
+ processParameters(cmd, params);
+ UserContext ctx = UserContext.current();
+ ctx.setAccountId(cmd.getEntityOwnerId());
+
+ if (cmd instanceof BaseAsyncCmd) {
+
+ BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmd;
+ String startEventId = params.get("ctxStartEventId");
+ ctx.setStartEventId(Long.valueOf(startEventId));
+
+ // Synchronise job on the object if needed
+ if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) {
+ Long queueSizeLimit = null;
+ if (asyncCmd.getSyncObjType() != null && asyncCmd.getSyncObjType().equalsIgnoreCase(BaseAsyncCmd.snapshotHostSyncObject)) {
+ queueSizeLimit = _createSnapshotQueueSizeLimit;
+ } else {
+ queueSizeLimit = 1L;
+ }
- if (queueSizeLimit != null) {
+ if (queueSizeLimit != null) {
_asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit);
- } else {
- s_logger.trace("The queue size is unlimited, skipping the synchronizing");
+ } else {
+ s_logger.trace("The queue size is unlimited, skipping the synchronizing");
+ }
}
}
- }
- cmd.execute();
+ cmd.execute();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- public static void processParameters(BaseCmd cmd, Map<String, String> params) {
- List<Object> entitiesToAccess = new ArrayList<Object>();
+ public static void processParameters(BaseCmd cmd, Map<String, String> params) {
+ Map<Object, AccessType> entitiesToAccess = new HashMap<Object, AccessType>();
Map<String, Object> unpackedParams = cmd.unpackParams(params);
if (cmd instanceof BaseListCmd) {
@@ -184,7 +180,7 @@ public class ApiDispatcher {
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
ServerApiException ex = new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
- throw ex;
+ throw ex;
} else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
}
@@ -193,11 +189,6 @@ public class ApiDispatcher {
List<Field> fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(), BaseCmd.class);
for (Field field : fields) {
- PlugService plugServiceAnnotation = field.getAnnotation(PlugService.class);
- if(plugServiceAnnotation != null){
- plugService(field, cmd);
- }
-
Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
if ((parameterAnnotation == null) || !parameterAnnotation.expose()) {
continue;
@@ -233,15 +224,16 @@ public class ApiDispatcher {
} catch (InvalidParameterValueException invEx) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
} catch (CloudRuntimeException cloudEx) {
+ s_logger.error("CloudRuntimeException", cloudEx);
// FIXME: Better error message? This only happens if the API command is not executable, which typically
- //means
+ //means
// there was
// and IllegalAccessException setting one of the parameters.
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
}
//check access on the resource this field points to
- try {
+ try {
ACL checkAccess = field.getAnnotation(ACL.class);
CommandType fieldType = parameterAnnotation.type();
@@ -261,17 +253,17 @@ public class ApiDispatcher {
// Check if the parameter type is a single
// Id or list of id's/name's
switch (fieldType) {
- case LIST:
- CommandType listType = parameterAnnotation.collectionType();
- switch (listType) {
- case LONG:
- case UUID:
- List<Long> listParam = (List<Long>) field.get(cmd);
- for (Long entityId : listParam) {
- Object entityObj = s_instance._entityMgr.findById(entity, entityId);
- entitiesToAccess.add(entityObj);
- }
- break;
+ case LIST:
+ CommandType listType = parameterAnnotation.collectionType();
+ switch (listType) {
+ case LONG:
+ case UUID:
+ List<Long> listParam = (List<Long>) field.get(cmd);
+ for (Long entityId : listParam) {
+ Object entityObj = s_instance._entityMgr.findById(entity, entityId);
+ entitiesToAccess.put(entityObj, checkAccess.accessType());
+ }
+ break;
/*
* case STRING: List<String> listParam =
* new ArrayList<String>(); listParam =
@@ -283,17 +275,17 @@ public class ApiDispatcher {
* entitiesToAccess.add(entityObj); }
* break;
*/
- default:
- break;
- }
- break;
- case LONG:
- case UUID:
- Object entityObj = s_instance._entityMgr.findById(entity, (Long) field.get(cmd));
- entitiesToAccess.add(entityObj);
- break;
default:
break;
+ }
+ break;
+ case LONG:
+ case UUID:
+ Object entityObj = s_instance._entityMgr.findById(entity, (Long) field.get(cmd));
+ entitiesToAccess.put(entityObj, checkAccess.accessType());
+ break;
+ default:
+ break;
}
if (ControlledEntity.class.isAssignableFrom(entity)) {
@@ -309,22 +301,22 @@ public class ApiDispatcher {
}
}
- }
+ }
- }
+ }
- } catch (IllegalArgumentException e) {
- s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
- throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]");
- } catch (IllegalAccessException e) {
- s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
- throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]");
- }
+ } catch (IllegalArgumentException e) {
+ s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
+ throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]");
+ } catch (IllegalAccessException e) {
+ s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
+ throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]");
+ }
}
//check access on the entities.
- s_instance.doAccessChecks(cmd, entitiesToAccess);
+ getInstance().doAccessChecks(cmd, entitiesToAccess);
}
@@ -368,7 +360,7 @@ public class ApiDispatcher {
// Invoke the getId method, get the internal long ID
// If that fails hide exceptions as the uuid may not exist
try {
- internalId = (Long) ((InternalIdentity)objVO).getId();
+ internalId = ((InternalIdentity)objVO).getId();
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
}
@@ -379,8 +371,8 @@ public class ApiDispatcher {
if (internalId == null) {
if (s_logger.isDebugEnabled())
s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
- throw new InvalidParameterValueException("Invalid parameter value=" + uuid
- + " due to incorrect long value format, or entity was not found as it may have been deleted, or due to incorrect parameter annotation for the field in api cmd.");
+ throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid
+ + " due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
}
return internalId;
}
@@ -398,7 +390,7 @@ public class ApiDispatcher {
// This piece of code is for maintaining backward compatibility
// and support both the date formats(Bug 9724)
// Do the date messaging for ListEventsCmd only
- if (cmdObj instanceof ListEventsCmd) {
+ if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd) {
boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
if (isObjInNewDateFormat) {
DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
@@ -413,6 +405,8 @@ public class ApiDispatcher {
date = messageDate(date, 0, 0, 0);
} else if (field.getName().equals("endDate")) {
date = messageDate(date, 23, 59, 59);
+ } else if (field.getName().equals("olderThan")) {
+ date = messageDate(date, 0, 0, 0);
}
field.set(cmdObj, date);
}
@@ -441,35 +435,35 @@ public class ApiDispatcher {
field.set(cmdObj, Integer.valueOf(paramObj.toString()));
}
break;
- case LIST:
- List listParam = new ArrayList();
- StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- CommandType listType = annotation.collectionType();
- switch (listType) {
- case INTEGER:
- listParam.add(Integer.valueOf(token));
- break;
- case UUID:
- if (token.isEmpty())
- break;
- Long internalId = translateUuidToInternalId(token, annotation);
- listParam.add(internalId);
- break;
- case LONG: {
- listParam.add(Long.valueOf(token));
- }
+ case LIST:
+ List listParam = new ArrayList();
+ StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ CommandType listType = annotation.collectionType();
+ switch (listType) {
+ case INTEGER:
+ listParam.add(Integer.valueOf(token));
+ break;
+ case UUID:
+ if (token.isEmpty())
break;
- case SHORT:
- listParam.add(Short.valueOf(token));
- case STRING:
- listParam.add(token);
- break;
- }
+ Long internalId = translateUuidToInternalId(token, annotation);
+ listParam.add(internalId);
+ break;
+ case LONG: {
+ listParam.add(Long.valueOf(token));
}
- field.set(cmdObj, listParam);
break;
+ case SHORT:
+ listParam.add(Short.valueOf(token));
+ case STRING:
+ listParam.add(token);
+ break;
+ }
+ }
+ field.set(cmdObj, listParam);
+ break;
case UUID:
if (paramObj.toString().isEmpty())
break;
@@ -518,13 +512,9 @@ public class ApiDispatcher {
}
public static void plugService(Field field, BaseCmd cmd) {
- ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
Class<?> fc = field.getType();
Object instance = null;
- if (PluggableService.class.isAssignableFrom(fc)) {
- instance = locator.getPluggableService(fc);
- }
if (instance == null) {
throw new CloudRuntimeException("Unable to plug service " + fc.getSimpleName() + " in command " + cmd.getClass().getSimpleName());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index d77aa1f..e980b0f 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -611,10 +611,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
IpDeployer deployer = null;
NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
- if (!(ComponentContext.getTargetObject(element) instanceof IpDeployingRequester)) {
+ if (!(element instanceof IpDeployingRequester)) {
throw new CloudRuntimeException("Element " + element + " is not a IpDeployingRequester!");
}
- deployer = ((IpDeployingRequester)ComponentContext.getTargetObject(element)).getIpDeployer(network);
+ deployer = ((IpDeployingRequester)element).getIpDeployer(network);
if (deployer == null) {
throw new CloudRuntimeException("Fail to get ip deployer for element: " + element);
}
@@ -1594,13 +1594,13 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
if (vmProfile.getType() == Type.User && element.getProvider() != null) {
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) &&
_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) &&
- (ComponentContext.getTargetObject(element) instanceof DhcpServiceProvider)) {
+ element instanceof DhcpServiceProvider) {
DhcpServiceProvider sp = (DhcpServiceProvider) element;
sp.addDhcpEntry(network, profile, vmProfile, dest, context);
}
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) &&
_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) &&
- (ComponentContext.getTargetObject(element) instanceof UserDataServiceProvider)) {
+ element instanceof UserDataServiceProvider) {
UserDataServiceProvider sp = (UserDataServiceProvider) element;
sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context);
}
@@ -3678,15 +3678,15 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
@Override
public StaticNatServiceProvider getStaticNatProviderForNetwork(Network network) {
NetworkElement element = getElementForServiceInNetwork(network, Service.StaticNat);
- assert ComponentContext.getTargetObject(element) instanceof StaticNatServiceProvider;
- return (StaticNatServiceProvider)ComponentContext.getTargetObject(element);
+ assert element instanceof StaticNatServiceProvider;
+ return (StaticNatServiceProvider)element;
}
@Override
public LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network) {
NetworkElement element = getElementForServiceInNetwork(network, Service.Lb);
- assert ComponentContext.getTargetObject(element) instanceof LoadBalancingServiceProvider;
- return ( LoadBalancingServiceProvider)ComponentContext.getTargetObject(element);
+ assert element instanceof LoadBalancingServiceProvider;
+ return (LoadBalancingServiceProvider)element;
}
@Override
public boolean isNetworkInlineMode(Network network) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index e6361b0..e45818f 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -404,9 +404,9 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
Network network = _networksDao.findById(networkId);
NetworkElement oldElement = getElementImplementingProvider(oldProvider.getName());
NetworkElement newElement = getElementImplementingProvider(newProvider.getName());
- if (ComponentContext.getTargetObject(oldElement) instanceof IpDeployingRequester && ComponentContext.getTargetObject(newElement) instanceof IpDeployingRequester) {
- IpDeployer oldIpDeployer = ((IpDeployingRequester)ComponentContext.getTargetObject(oldElement)).getIpDeployer(network);
- IpDeployer newIpDeployer = ((IpDeployingRequester)ComponentContext.getTargetObject(newElement)).getIpDeployer(network);
+ if (oldElement instanceof IpDeployingRequester && newElement instanceof IpDeployingRequester) {
+ IpDeployer oldIpDeployer = ((IpDeployingRequester)oldElement).getIpDeployer(network);
+ IpDeployer newIpDeployer = ((IpDeployingRequester)newElement).getIpDeployer(network);
if (!oldIpDeployer.getProvider().getName().equals(newIpDeployer.getProvider().getName())) {
throw new InvalidParameterException("There would be multiple providers for IP " + publicIp.getAddress() + "!");
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/src/com/cloud/utils/component/AdapterBase.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/AdapterBase.java b/utils/src/com/cloud/utils/component/AdapterBase.java
index 8353cee..d161787 100644
--- a/utils/src/com/cloud/utils/component/AdapterBase.java
+++ b/utils/src/com/cloud/utils/component/AdapterBase.java
@@ -29,7 +29,7 @@ public class AdapterBase extends ComponentLifecycleBase implements Adapter, Comp
public static <T extends Adapter> T getAdapterByName(List<T> adapters, String name) {
for(T adapter : adapters) {
if(adapter.getName() != null && adapter.getName().equalsIgnoreCase(name))
- return adapter;
+ return adapter;
}
return null;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/src/com/cloud/utils/component/ComponentContext.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/ComponentContext.java b/utils/src/com/cloud/utils/component/ComponentContext.java
index 796d4ec..32e4464 100644
--- a/utils/src/com/cloud/utils/component/ComponentContext.java
+++ b/utils/src/com/cloud/utils/component/ComponentContext.java
@@ -60,17 +60,17 @@ public class ComponentContext implements ApplicationContextAware {
public static ApplicationContext getApplicationContext() {
return s_appContext;
}
-
+
public static void initComponentsLifeCycle() {
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
- Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(
- ComponentMethodInterceptable.class);
- for(Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
- Object bean = getTargetObject(entry.getValue());
- beanFactory.configureBean(bean, entry.getKey());
- }
-
+ Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(
+ ComponentMethodInterceptable.class);
+ for(Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
+ Object bean = getTargetObject(entry.getValue());
+ beanFactory.configureBean(bean, entry.getKey());
+ }
+
Map<String, ComponentLifecycle> lifecyleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class);
Map[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS];
@@ -81,18 +81,6 @@ public class ComponentContext implements ApplicationContextAware {
for(Map.Entry<String, ComponentLifecycle> entry : lifecyleComponents.entrySet()) {
classifiedComponents[entry.getValue().getRunLevel()].put(entry.getKey(), entry.getValue());
}
-
- // Run the SystemIntegrityCheckers first
- Map<String, SystemIntegrityChecker> integrityCheckers = getApplicationContext().getBeansOfType(SystemIntegrityChecker.class);
- for (Entry<String,SystemIntegrityChecker> entry : integrityCheckers.entrySet() ){
- s_logger.info ("Running SystemIntegrityChecker " + entry.getKey());
- try {
- entry.getValue().check();
- } catch(Throwable e) {
- s_logger.error("System integrity check failed. Refuse to startup");
- System.exit(1);
- }
- }
// configuration phase
Map<String, String> avoidMap = new HashMap<String, String>();
@@ -117,6 +105,18 @@ public class ComponentContext implements ApplicationContextAware {
avoidMap.put(implClassName, implClassName);
}
}
+
+ // Run the SystemIntegrityCheckers first
+ Map<String, SystemIntegrityChecker> integrityCheckers = getApplicationContext().getBeansOfType(SystemIntegrityChecker.class);
+ for (Entry<String,SystemIntegrityChecker> entry : integrityCheckers.entrySet() ){
+ s_logger.info ("Running SystemIntegrityChecker " + entry.getKey());
+ try {
+ entry.getValue().check();
+ } catch(Throwable e) {
+ s_logger.error("System integrity check failed. Refuse to startup");
+ System.exit(1);
+ }
+ }
// starting phase
avoidMap.clear();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/src/com/cloud/utils/component/ComponentInstantiationPostProcessor.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/ComponentInstantiationPostProcessor.java b/utils/src/com/cloud/utils/component/ComponentInstantiationPostProcessor.java
index cb64975..256ff81 100644
--- a/utils/src/com/cloud/utils/component/ComponentInstantiationPostProcessor.java
+++ b/utils/src/com/cloud/utils/component/ComponentInstantiationPostProcessor.java
@@ -41,7 +41,7 @@ public class ComponentInstantiationPostProcessor implements InstantiationAwareBe
private List<ComponentMethodInterceptor> _interceptors = new ArrayList<ComponentMethodInterceptor>();
private Callback[] _callbacks;
private CallbackFilter _callbackFilter;
-
+
public ComponentInstantiationPostProcessor() {
_callbacks = new Callback[2];
_callbacks[0] = NoOp.INSTANCE;
@@ -49,23 +49,23 @@ public class ComponentInstantiationPostProcessor implements InstantiationAwareBe
_callbackFilter = new InterceptorFilter();
}
-
+
public List<ComponentMethodInterceptor> getInterceptors() {
return _interceptors;
}
-
+
public void setInterceptors(List<ComponentMethodInterceptor> interceptors) {
_interceptors = interceptors;
}
-
+
private Callback[] getCallbacks() {
return _callbacks;
}
-
+
private CallbackFilter getCallbackFilter() {
return _callbackFilter;
}
-
+
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
@@ -88,7 +88,7 @@ public class ComponentInstantiationPostProcessor implements InstantiationAwareBe
enhancer.setCallbacks(getCallbacks());
enhancer.setCallbackFilter(getCallbackFilter());
enhancer.setNamingPolicy(ComponentNamingPolicy.INSTANCE);
-
+
Object bean = enhancer.create();
return bean;
}
@@ -108,12 +108,12 @@ public class ComponentInstantiationPostProcessor implements InstantiationAwareBe
throws BeansException {
return pvs;
}
-
+
protected class InterceptorDispatcher implements MethodInterceptor {
@Override
public Object intercept(Object target, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
ArrayList<Pair<ComponentMethodInterceptor, Object>> interceptors = new ArrayList<Pair<ComponentMethodInterceptor, Object>>();
-
+
for (ComponentMethodInterceptor interceptor : getInterceptors()) {
if (interceptor.needToIntercept(method)) {
Object objReturnedInInterceptStart = interceptor.interceptStart(method, target);
@@ -136,14 +136,14 @@ public class ComponentInstantiationPostProcessor implements InstantiationAwareBe
}
}
}
-
+
protected class InterceptorFilter implements CallbackFilter {
@Override
public int accept(Method method) {
for(ComponentMethodInterceptor interceptor : getInterceptors()) {
-
+
if (interceptor.needToIntercept(method)) {
- return 1;
+ return 1;
}
}
return 0;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/src/com/cloud/utils/component/ComponentMethodInterceptor.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/ComponentMethodInterceptor.java b/utils/src/com/cloud/utils/component/ComponentMethodInterceptor.java
index 39a81d0..1925ddf 100644
--- a/utils/src/com/cloud/utils/component/ComponentMethodInterceptor.java
+++ b/utils/src/com/cloud/utils/component/ComponentMethodInterceptor.java
@@ -20,7 +20,7 @@ import java.lang.reflect.Method;
public interface ComponentMethodInterceptor {
boolean needToIntercept(Method method);
-
+
Object interceptStart(Method method, Object target);
void interceptComplete(Method method, Object target, Object objReturnedInInterceptStart);
void interceptException(Method method, Object target, Object objReturnedInInterceptStart);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/src/com/cloud/utils/component/ComponentNamingPolicy.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/ComponentNamingPolicy.java b/utils/src/com/cloud/utils/component/ComponentNamingPolicy.java
index 5659a48..03c1573 100644
--- a/utils/src/com/cloud/utils/component/ComponentNamingPolicy.java
+++ b/utils/src/com/cloud/utils/component/ComponentNamingPolicy.java
@@ -26,7 +26,7 @@ import net.sf.cglib.core.Predicate;
public class ComponentNamingPolicy implements NamingPolicy {
public static final ComponentNamingPolicy INSTANCE = new ComponentNamingPolicy();
-
+
public String getClassName(String prefix, String source, Object key, Predicate names) {
if (prefix == null) {
prefix = "net.sf.cglib.empty.Object";
@@ -34,7 +34,7 @@ public class ComponentNamingPolicy implements NamingPolicy {
prefix = "_" + prefix;
}
String base =
- prefix + "_" +
+ prefix + "_" +
source.substring(source.lastIndexOf('.') + 1) +
getTag() + "_" +
Integer.toHexString(key.hashCode());
@@ -56,7 +56,7 @@ public class ComponentNamingPolicy implements NamingPolicy {
public int hashCode() {
return getTag().hashCode();
}
-
+
public boolean equals(Object o) {
return (o instanceof ComponentNamingPolicy) && ((ComponentNamingPolicy) o).getTag().equals(getTag());
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/src/com/cloud/utils/db/GenericDaoBase.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java
index f0fc700..3c43666 100755
--- a/utils/src/com/cloud/utils/db/GenericDaoBase.java
+++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java
@@ -201,7 +201,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
s_daoMaps.put(interphace, this);
}
}
-
+
_table = DbUtil.getTableName(_entityBeanType);
final SqlGenerator generator = new SqlGenerator(_entityBeanType);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/TransactionContextBuilder.java b/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
index 40fcbbf..7bab62f 100644
--- a/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
+++ b/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
@@ -23,16 +23,16 @@ import com.cloud.utils.component.ComponentMethodInterceptor;
public class TransactionContextBuilder implements ComponentMethodInterceptor {
public TransactionContextBuilder() {
}
-
+
@Override
public boolean needToIntercept(Method method) {
DB db = method.getAnnotation(DB.class);
if (db != null) {
return true;
}
-
+
Class<?> clazz = method.getDeclaringClass();
-
+
do {
db = clazz.getAnnotation(DB.class);
if (db != null) {
@@ -46,20 +46,20 @@ public class TransactionContextBuilder implements ComponentMethodInterceptor {
@Override
public Object interceptStart(Method method, Object target) {
- return Transaction.open(method.getName());
+ return Transaction.open(method.getName());
}
-
+
@Override
public void interceptComplete(Method method, Object target, Object objReturnedInInterceptStart) {
- Transaction txn = (Transaction)objReturnedInInterceptStart;
- if(txn != null)
- txn.close();
+ Transaction txn = (Transaction)objReturnedInInterceptStart;
+ if(txn != null)
+ txn.close();
}
-
+
@Override
public void interceptException(Method method, Object target, Object objReturnedInInterceptStart) {
- Transaction txn = (Transaction)objReturnedInInterceptStart;
- if(txn != null)
- txn.close();
+ Transaction txn = (Transaction)objReturnedInInterceptStart;
+ if(txn != null)
+ txn.close();
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07a63a89/utils/test/resources/testContext.xml
----------------------------------------------------------------------
diff --git a/utils/test/resources/testContext.xml b/utils/test/resources/testContext.xml
index 5cccfcd..490288a 100644
--- a/utils/test/resources/testContext.xml
+++ b/utils/test/resources/testContext.xml
@@ -33,18 +33,18 @@
<context:annotation-config />
<context:component-scan base-package="org.apache.cloudstack, com.cloud" />
-
+
<!--
@DB support
-->
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
- <bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
- <property name="Interceptors">
- <list>
- <ref bean="transactionContextBuilder" />
- </list>
- </property>
- </bean>
+ <bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
+ <property name="Interceptors">
+ <list>
+ <ref bean="transactionContextBuilder" />
+ </list>
+ </property>
+ </bean>
</beans>