diff --git a/api/resources/META-INF/cloudstack/api-planner/module.properties b/api/resources/META-INF/cloudstack/api-planner/module.properties new file mode 100644 index 00000000000..98f4ffe9427 --- /dev/null +++ b/api/resources/META-INF/cloudstack/api-planner/module.properties @@ -0,0 +1,2 @@ +name=api-planner +parent=planner \ No newline at end of file diff --git a/api/resources/META-INF/cloudstack/api-planner/spring-api-planner-context.xml b/api/resources/META-INF/cloudstack/api-planner/spring-api-planner-context.xml new file mode 100644 index 00000000000..2fd34a8ee0a --- /dev/null +++ b/api/resources/META-INF/cloudstack/api-planner/spring-api-planner-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java index a9867d3bb70..15fbad3f639 100644 --- a/api/src/org/apache/cloudstack/context/CallContext.java +++ b/api/src/org/apache/cloudstack/context/CallContext.java @@ -57,7 +57,7 @@ public class CallContext { private User user; private final Map context = new HashMap(); - private static EntityManager s_entityMgr; + static EntityManager s_entityMgr; public static void init(EntityManager entityMgr) { s_entityMgr = entityMgr; diff --git a/client/resources/META-INF/cloudstack/webApplicationContext.xml b/client/resources/META-INF/cloudstack/webApplicationContext.xml new file mode 100644 index 00000000000..fea2709747b --- /dev/null +++ b/client/resources/META-INF/cloudstack/webApplicationContext.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/client/tomcatconf/log4j-cloud.xml.in b/client/tomcatconf/log4j-cloud.xml.in index d439b771f4f..08021f2077b 100755 --- a/client/tomcatconf/log4j-cloud.xml.in +++ b/client/tomcatconf/log4j-cloud.xml.in @@ -152,6 +152,14 @@ under the License. + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/allocator/module.properties b/core/resources/META-INF/cloudstack/allocator/module.properties new file mode 100644 index 00000000000..9ae4d8e6b15 --- /dev/null +++ b/core/resources/META-INF/cloudstack/allocator/module.properties @@ -0,0 +1,2 @@ +name=allocator +parent=core diff --git a/core/resources/META-INF/cloudstack/allocator/spring-core-allocator-context.xml b/core/resources/META-INF/cloudstack/allocator/spring-core-allocator-context.xml new file mode 100644 index 00000000000..65ebc704400 --- /dev/null +++ b/core/resources/META-INF/cloudstack/allocator/spring-core-allocator-context.xml @@ -0,0 +1,32 @@ + + + + + + \ No newline at end of file diff --git a/core/resources/META-INF/cloudstack/allocator/spring-core-lifecycle-allocator-context-inheritable.xml b/core/resources/META-INF/cloudstack/allocator/spring-core-lifecycle-allocator-context-inheritable.xml new file mode 100644 index 00000000000..ad00de8be2c --- /dev/null +++ b/core/resources/META-INF/cloudstack/allocator/spring-core-lifecycle-allocator-context-inheritable.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/resources/META-INF/cloudstack/api/module.properties b/core/resources/META-INF/cloudstack/api/module.properties new file mode 100644 index 00000000000..0a08e16fa3e --- /dev/null +++ b/core/resources/META-INF/cloudstack/api/module.properties @@ -0,0 +1,2 @@ +name=api +parent=core diff --git a/core/resources/META-INF/cloudstack/api/spring-core-lifecycle-api-context-inheritable.xml b/core/resources/META-INF/cloudstack/api/spring-core-lifecycle-api-context-inheritable.xml new file mode 100644 index 00000000000..b0ed228c0da --- /dev/null +++ b/core/resources/META-INF/cloudstack/api/spring-core-lifecycle-api-context-inheritable.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/backend/module.properties b/core/resources/META-INF/cloudstack/backend/module.properties new file mode 100644 index 00000000000..58f0b3671ea --- /dev/null +++ b/core/resources/META-INF/cloudstack/backend/module.properties @@ -0,0 +1,2 @@ +name=backend +parent=core diff --git a/core/resources/META-INF/cloudstack/bootstrap/module.properties b/core/resources/META-INF/cloudstack/bootstrap/module.properties new file mode 100644 index 00000000000..fa28ca4cc4b --- /dev/null +++ b/core/resources/META-INF/cloudstack/bootstrap/module.properties @@ -0,0 +1 @@ +name=bootstrap diff --git a/core/resources/META-INF/cloudstack/bootstrap/spring-bootstrap-context-inheritable.xml b/core/resources/META-INF/cloudstack/bootstrap/spring-bootstrap-context-inheritable.xml new file mode 100644 index 00000000000..adee3ed28e0 --- /dev/null +++ b/core/resources/META-INF/cloudstack/bootstrap/spring-bootstrap-context-inheritable.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/bootstrap/spring-bootstrap-context.xml b/core/resources/META-INF/cloudstack/bootstrap/spring-bootstrap-context.xml new file mode 100644 index 00000000000..40fcc71c14e --- /dev/null +++ b/core/resources/META-INF/cloudstack/bootstrap/spring-bootstrap-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/core/resources/META-INF/cloudstack/compute/module.properties b/core/resources/META-INF/cloudstack/compute/module.properties new file mode 100644 index 00000000000..d997f7b2b5d --- /dev/null +++ b/core/resources/META-INF/cloudstack/compute/module.properties @@ -0,0 +1,2 @@ +name=compute +parent=backend diff --git a/core/resources/META-INF/cloudstack/compute/spring-core-lifecycle-compute-context-inheritable.xml b/core/resources/META-INF/cloudstack/compute/spring-core-lifecycle-compute-context-inheritable.xml new file mode 100644 index 00000000000..b57f52fc2ef --- /dev/null +++ b/core/resources/META-INF/cloudstack/compute/spring-core-lifecycle-compute-context-inheritable.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/core/module.properties b/core/resources/META-INF/cloudstack/core/module.properties new file mode 100644 index 00000000000..b88fe93e104 --- /dev/null +++ b/core/resources/META-INF/cloudstack/core/module.properties @@ -0,0 +1,2 @@ +name=core +parent=system diff --git a/core/resources/META-INF/cloudstack/core/spring-core-context.xml b/core/resources/META-INF/cloudstack/core/spring-core-context.xml new file mode 100644 index 00000000000..6cd00a40103 --- /dev/null +++ b/core/resources/META-INF/cloudstack/core/spring-core-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/core/spring-core-lifecycle-core-context-inheritable.xml b/core/resources/META-INF/cloudstack/core/spring-core-lifecycle-core-context-inheritable.xml new file mode 100644 index 00000000000..06b9f5e0748 --- /dev/null +++ b/core/resources/META-INF/cloudstack/core/spring-core-lifecycle-core-context-inheritable.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml b/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml new file mode 100644 index 00000000000..170d33d8588 --- /dev/null +++ b/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/resources/META-INF/cloudstack/discoverer/module.properties b/core/resources/META-INF/cloudstack/discoverer/module.properties new file mode 100644 index 00000000000..9fba24cec52 --- /dev/null +++ b/core/resources/META-INF/cloudstack/discoverer/module.properties @@ -0,0 +1,2 @@ +name=discoverer +parent=core diff --git a/core/resources/META-INF/cloudstack/discoverer/spring-core-lifecycle-discoverer-context-inheritable.xml b/core/resources/META-INF/cloudstack/discoverer/spring-core-lifecycle-discoverer-context-inheritable.xml new file mode 100644 index 00000000000..2c83a104b32 --- /dev/null +++ b/core/resources/META-INF/cloudstack/discoverer/spring-core-lifecycle-discoverer-context-inheritable.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/network/module.properties b/core/resources/META-INF/cloudstack/network/module.properties new file mode 100644 index 00000000000..6e5219aacca --- /dev/null +++ b/core/resources/META-INF/cloudstack/network/module.properties @@ -0,0 +1,2 @@ +name=network +parent=backend diff --git a/core/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml b/core/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml new file mode 100644 index 00000000000..b2660fc7caf --- /dev/null +++ b/core/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/resources/META-INF/cloudstack/planner/module.properties b/core/resources/META-INF/cloudstack/planner/module.properties new file mode 100644 index 00000000000..eea9158c87d --- /dev/null +++ b/core/resources/META-INF/cloudstack/planner/module.properties @@ -0,0 +1,2 @@ +name=planner +parent=allocator \ No newline at end of file diff --git a/core/resources/META-INF/cloudstack/planner/spring-core-lifecycle-planner-context-inheritable.xml b/core/resources/META-INF/cloudstack/planner/spring-core-lifecycle-planner-context-inheritable.xml new file mode 100644 index 00000000000..715f86d9c28 --- /dev/null +++ b/core/resources/META-INF/cloudstack/planner/spring-core-lifecycle-planner-context-inheritable.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/storage/module.properties b/core/resources/META-INF/cloudstack/storage/module.properties new file mode 100644 index 00000000000..fe32b10e03f --- /dev/null +++ b/core/resources/META-INF/cloudstack/storage/module.properties @@ -0,0 +1,2 @@ +name=storage +parent=backend diff --git a/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml b/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml new file mode 100644 index 00000000000..617dd214326 --- /dev/null +++ b/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/system/module.properties b/core/resources/META-INF/cloudstack/system/module.properties new file mode 100644 index 00000000000..b86468e5311 --- /dev/null +++ b/core/resources/META-INF/cloudstack/system/module.properties @@ -0,0 +1,2 @@ +name=system +parent=bootstrap diff --git a/core/resources/META-INF/cloudstack/system/spring-core-system-context-inheritable.xml b/core/resources/META-INF/cloudstack/system/spring-core-system-context-inheritable.xml new file mode 100644 index 00000000000..80c5da744bb --- /dev/null +++ b/core/resources/META-INF/cloudstack/system/spring-core-system-context-inheritable.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/core/resources/META-INF/cloudstack/system/spring-core-system-context.xml b/core/resources/META-INF/cloudstack/system/spring-core-system-context.xml new file mode 100644 index 00000000000..c2d540ca102 --- /dev/null +++ b/core/resources/META-INF/cloudstack/system/spring-core-system-context.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + diff --git a/engine/api/resources/META-INF/cloudstack/core/spring-engine-api-core-context.xml b/engine/api/resources/META-INF/cloudstack/core/spring-engine-api-core-context.xml new file mode 100644 index 00000000000..1cb8829839d --- /dev/null +++ b/engine/api/resources/META-INF/cloudstack/core/spring-engine-api-core-context.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + diff --git a/engine/components-api/resources/META-INF/cloudstack/core/spring-engine-components-api-core-context.xml b/engine/components-api/resources/META-INF/cloudstack/core/spring-engine-components-api-core-context.xml new file mode 100644 index 00000000000..fd7f96752f9 --- /dev/null +++ b/engine/components-api/resources/META-INF/cloudstack/core/spring-engine-components-api-core-context.xml @@ -0,0 +1,30 @@ + + + + diff --git a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml new file mode 100644 index 00000000000..b5c4254abaa --- /dev/null +++ b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml new file mode 100644 index 00000000000..cc5af3f669c --- /dev/null +++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -0,0 +1,321 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/engine/schema/resources/META-INF/cloudstack/system/spring-engine-schema-system-checkers-context.xml b/engine/schema/resources/META-INF/cloudstack/system/spring-engine-schema-system-checkers-context.xml new file mode 100644 index 00000000000..2a308873f6a --- /dev/null +++ b/engine/schema/resources/META-INF/cloudstack/system/spring-engine-schema-system-checkers-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java b/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java index c107fa021ff..1afd0560f80 100755 --- a/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java +++ b/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.TreeMap; import javax.ejb.Local; +import javax.inject.Inject; import org.apache.log4j.Logger; @@ -66,7 +67,6 @@ import com.cloud.upgrade.dao.Upgrade420to430; import com.cloud.upgrade.dao.UpgradeSnapshot217to224; import com.cloud.upgrade.dao.UpgradeSnapshot223to224; import com.cloud.upgrade.dao.VersionDao; -import com.cloud.upgrade.dao.VersionDaoImpl; import com.cloud.upgrade.dao.VersionVO; import com.cloud.upgrade.dao.VersionVO.Step; import com.cloud.utils.component.SystemIntegrityChecker; @@ -81,10 +81,10 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { protected HashMap _upgradeMap = new HashMap(); + @Inject VersionDao _dao; public DatabaseUpgradeChecker() { - _dao = new VersionDaoImpl(); _upgradeMap.put("2.1.7", new DbUpgrade[] {new Upgrade217to218(), new Upgrade218to22(), new Upgrade221to222(), new UpgradeSnapshot217to224(), new Upgrade222to224(), new Upgrade224to225(), new Upgrade225to226(), new Upgrade227to228(), new Upgrade228to229(), new Upgrade229to2210(), new Upgrade2210to2211(), diff --git a/engine/storage/cache/resources/META-INF/cloudstack/core/spring-engine-storage-cache-core-context.xml b/engine/storage/cache/resources/META-INF/cloudstack/core/spring-engine-storage-cache-core-context.xml new file mode 100644 index 00000000000..7b8e2a4ab2c --- /dev/null +++ b/engine/storage/cache/resources/META-INF/cloudstack/core/spring-engine-storage-cache-core-context.xml @@ -0,0 +1,38 @@ + + + + + + + + + diff --git a/engine/storage/datamotion/resources/META-INF/cloudstack/core/spring-engine-storage-datamotion-core-context.xml b/engine/storage/datamotion/resources/META-INF/cloudstack/core/spring-engine-storage-datamotion-core-context.xml new file mode 100644 index 00000000000..822644eb232 --- /dev/null +++ b/engine/storage/datamotion/resources/META-INF/cloudstack/core/spring-engine-storage-datamotion-core-context.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + diff --git a/engine/storage/image/resources/META-INF/cloudstack/core/spring-engine-storage-image-core-context.xml b/engine/storage/image/resources/META-INF/cloudstack/core/spring-engine-storage-image-core-context.xml new file mode 100644 index 00000000000..db517dbd863 --- /dev/null +++ b/engine/storage/image/resources/META-INF/cloudstack/core/spring-engine-storage-image-core-context.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + diff --git a/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml b/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml new file mode 100644 index 00000000000..29f4fcd48f7 --- /dev/null +++ b/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/engine/storage/resources/META-INF/cloudstack/storage-allocator/module.properties b/engine/storage/resources/META-INF/cloudstack/storage-allocator/module.properties new file mode 100644 index 00000000000..7a1cd0e8cce --- /dev/null +++ b/engine/storage/resources/META-INF/cloudstack/storage-allocator/module.properties @@ -0,0 +1,2 @@ +name=storage-allocator +parent=storage \ No newline at end of file diff --git a/engine/storage/resources/META-INF/cloudstack/storage-allocator/spring-engine-storage-storage-allocator-context.xml b/engine/storage/resources/META-INF/cloudstack/storage-allocator/spring-engine-storage-storage-allocator-context.xml new file mode 100644 index 00000000000..e4e02aa210e --- /dev/null +++ b/engine/storage/resources/META-INF/cloudstack/storage-allocator/spring-engine-storage-storage-allocator-context.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + diff --git a/engine/storage/snapshot/resources/META-INF/cloudstack/core/spring-engine-storage-snapshot-core-context.xml b/engine/storage/snapshot/resources/META-INF/cloudstack/core/spring-engine-storage-snapshot-core-context.xml new file mode 100644 index 00000000000..c9c89e3f3d1 --- /dev/null +++ b/engine/storage/snapshot/resources/META-INF/cloudstack/core/spring-engine-storage-snapshot-core-context.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java index 92b4e7a5479..c5d904be8b8 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java @@ -20,6 +20,8 @@ package org.apache.cloudstack.storage.datastore.provider; import com.cloud.exception.InvalidParameterValueException; import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.component.Registry; + import org.apache.cloudstack.api.response.StorageProviderResponse; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType; @@ -33,18 +35,22 @@ import org.springframework.stereotype.Component; import javax.inject.Inject; import javax.naming.ConfigurationException; + import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; @Component -public class DataStoreProviderManagerImpl extends ManagerBase implements DataStoreProviderManager { +public class DataStoreProviderManagerImpl extends ManagerBase implements DataStoreProviderManager, Registry { private static final Logger s_logger = Logger.getLogger(DataStoreProviderManagerImpl.class); - @Inject + List providers; - protected Map providerMap = new HashMap(); + protected Map providerMap = new ConcurrentHashMap(); @Inject PrimaryDataStoreProviderManager primaryDataStoreProviderMgr; @Inject @@ -96,43 +102,54 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto @Override public boolean configure(String name, Map params) throws ConfigurationException { - Map copyParams = new HashMap(params); - for (DataStoreProvider provider : providers) { - String providerName = provider.getName(); - if (providerMap.get(providerName) != null) { - s_logger.debug("Failed to register data store provider, provider name: " + providerName - + " is not unique"); - return false; - } - - s_logger.debug("registering data store provider:" + provider.getName()); - - providerMap.put(providerName, provider); - try { - boolean registrationResult = provider.configure(copyParams); - if (!registrationResult) { - providerMap.remove(providerName); - s_logger.debug("Failed to register data store provider: " + providerName); - return false; - } - - Set types = provider.getTypes(); - if (types.contains(DataStoreProviderType.PRIMARY)) { - primaryDataStoreProviderMgr.registerDriver(provider.getName(), - (PrimaryDataStoreDriver) provider.getDataStoreDriver()); - primaryDataStoreProviderMgr.registerHostListener(provider.getName(), provider.getHostListener()); - } else if (types.contains(DataStoreProviderType.IMAGE)) { - imageStoreProviderMgr.registerDriver(provider.getName(), - (ImageStoreDriver) provider.getDataStoreDriver()); - } - } catch (Exception e) { - s_logger.debug("configure provider failed", e); - providerMap.remove(providerName); - return false; + if ( providers != null ) { + for (DataStoreProvider provider : providers) { + registerProvider(provider); } } + providers = new CopyOnWriteArrayList(providers); + + return true; + } + + protected boolean registerProvider(DataStoreProvider provider) { + Map copyParams = new HashMap(); + + String providerName = provider.getName(); + if (providerMap.get(providerName) != null) { + s_logger.debug("Did not register data store provider, provider name: " + providerName + + " is not unique"); + return false; + } + + s_logger.debug("registering data store provider:" + provider.getName()); + + providerMap.put(providerName, provider); + try { + boolean registrationResult = provider.configure(copyParams); + if (!registrationResult) { + providerMap.remove(providerName); + s_logger.debug("Failed to register data store provider: " + providerName); + return false; + } + + Set types = provider.getTypes(); + if (types.contains(DataStoreProviderType.PRIMARY)) { + primaryDataStoreProviderMgr.registerDriver(provider.getName(), + (PrimaryDataStoreDriver) provider.getDataStoreDriver()); + primaryDataStoreProviderMgr.registerHostListener(provider.getName(), provider.getHostListener()); + } else if (types.contains(DataStoreProviderType.IMAGE)) { + imageStoreProviderMgr.registerDriver(provider.getName(), + (ImageStoreDriver) provider.getDataStoreDriver()); + } + } catch (Exception e) { + s_logger.debug("configure provider failed", e); + providerMap.remove(providerName); + return false; + } + return true; } @@ -167,6 +184,27 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto } } + @Override + public boolean register(DataStoreProvider type) { + if ( registerProvider(type) ) { + providers.add(type); + return true; + } + + return false; + } + + @Override + public void unregister(DataStoreProvider type) { + /* Sorry, no unregister supported... */ + } + + @Override + public List getRegistered() { + return Collections.unmodifiableList(providers); + } + + @Inject public void setProviders(List providers) { this.providers = providers; } @@ -178,4 +216,9 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto public void setImageStoreProviderMgr(ImageStoreProviderManager imageDataStoreProviderMgr) { this.imageStoreProviderMgr = imageDataStoreProviderMgr; } + + public List getProviders() { + return providers; + } + } diff --git a/engine/storage/volume/resources/META-INF/cloudstack/core/spring-engine-storage-volume-core-context.xml b/engine/storage/volume/resources/META-INF/cloudstack/core/spring-engine-storage-volume-core-context.xml new file mode 100644 index 00000000000..ba9afb538ec --- /dev/null +++ b/engine/storage/volume/resources/META-INF/cloudstack/core/spring-engine-storage-volume-core-context.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/cluster/resources/META-INF/cloudstack/core/spring-framework-cluster-core-context.xml b/framework/cluster/resources/META-INF/cloudstack/core/spring-framework-cluster-core-context.xml new file mode 100644 index 00000000000..13353b0ead1 --- /dev/null +++ b/framework/cluster/resources/META-INF/cloudstack/core/spring-framework-cluster-core-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/framework/config/resources/META-INF/cloudstack/bootstrap/spring-framework-config-bootstrap-context-inheritable.xml b/framework/config/resources/META-INF/cloudstack/bootstrap/spring-framework-config-bootstrap-context-inheritable.xml new file mode 100644 index 00000000000..c887531300c --- /dev/null +++ b/framework/config/resources/META-INF/cloudstack/bootstrap/spring-framework-config-bootstrap-context-inheritable.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + diff --git a/framework/config/resources/META-INF/cloudstack/bootstrap/spring-framework-config-bootstrap-context.xml b/framework/config/resources/META-INF/cloudstack/bootstrap/spring-framework-config-bootstrap-context.xml new file mode 100644 index 00000000000..8d75d27576e --- /dev/null +++ b/framework/config/resources/META-INF/cloudstack/bootstrap/spring-framework-config-bootstrap-context.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotAdmin.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotAdmin.java index b4d3773356d..b7fe1253854 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotAdmin.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotAdmin.java @@ -31,6 +31,8 @@ public interface ConfigDepotAdmin { * @see Configuration */ void populateConfigurations(); + + void populateConfiguration(Configurable configurable); List getComponentsInDepot(); } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java b/framework/config/src/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java index e4029888007..43e2cec26c6 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.PostConstruct; import javax.ejb.Local; import javax.naming.ConfigurationException; @@ -128,6 +129,14 @@ public class ConfigurationDaoImpl extends GenericDaoBase _configurables; - @Inject List _scopedStorages; + Set _configured = Collections.synchronizedSet(new HashSet()); HashMap>> _allKeys = new HashMap>>(1007); @@ -85,52 +86,60 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemInt return value != null ? value.second() : null; } + @PostConstruct @Override public void populateConfigurations() { Date date = new Date(); for (Configurable configurable : _configurables) { - for (ConfigKey key : configurable.getConfigKeys()) { - ConfigurationVO vo = _configDao.findById(key.key()); - if (vo == null) { - vo = new ConfigurationVO(configurable.getConfigComponentName(), key); - vo.setUpdated(date); - _configDao.persist(vo); - } else { - if (vo.isDynamic() != key.isDynamic() || - !ObjectUtils.equals(vo.getDescription(), key.description()) || - !ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue())) { - vo.setDynamic(key.isDynamic()); - vo.setDescription(key.description()); - vo.setDefaultValue(key.defaultValue()); - vo.setUpdated(date); - _configDao.persist(vo); - } - } - } + populateConfiguration(date, configurable); } } + protected void populateConfiguration(Date date, Configurable configurable) { + if ( _configured.contains(configurable) ) + return; + + s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); + + for (ConfigKey key : configurable.getConfigKeys()) { + Pair> previous = _allKeys.get(key.key()); + if (previous != null && !previous.first().equals(configurable.getConfigComponentName())) { + throw new CloudRuntimeException("Configurable " + configurable.getConfigComponentName() + " is adding a key that has been added before by " + previous.first() + + ": " + key.toString()); + } + _allKeys.put(key.key(), new Pair>(configurable.getConfigComponentName(), key)); + + ConfigurationVO vo = _configDao.findById(key.key()); + if (vo == null) { + vo = new ConfigurationVO(configurable.getConfigComponentName(), key); + vo.setUpdated(date); + _configDao.persist(vo); + } else { + if (vo.isDynamic() != key.isDynamic() || + !ObjectUtils.equals(vo.getDescription(), key.description()) || + !ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue())) { + vo.setDynamic(key.isDynamic()); + vo.setDescription(key.description()); + vo.setDefaultValue(key.defaultValue()); + vo.setUpdated(date); + _configDao.persist(vo); + } + } + } + + _configured.add(configurable); + } + + @Override + public void populateConfiguration(Configurable configurable) { + populateConfiguration(new Date(), configurable); + } + @Override public List getComponentsInDepot() { return new ArrayList(); } - @Override - @PostConstruct - public void check() { - for (Configurable configurable : _configurables) { - s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); - for (ConfigKey key : configurable.getConfigKeys()) { - Pair> previous = _allKeys.get(key.key()); - if (previous != null && !previous.first().equals(configurable.getConfigComponentName())) { - throw new CloudRuntimeException("Configurable " + configurable.getConfigComponentName() + " is adding a key that has been added before by " + previous.first() + - ": " + key.toString()); - } - _allKeys.put(key.key(), new Pair>(configurable.getConfigComponentName(), key)); - } - } - } - public ConfigurationDao global() { return _configDao; } @@ -144,4 +153,23 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemInt throw new CloudRuntimeException("Unable to find config storage for this scope: " + config.scope() + " for " + config.key()); } + + public List getScopedStorages() { + return _scopedStorages; + } + + @Inject + public void setScopedStorages(List scopedStorages) { + this._scopedStorages = scopedStorages; + } + + public List getConfigurables() { + return _configurables; + } + + @Inject + public void setConfigurables(List configurables) { + this._configurables = configurables; + } + } diff --git a/framework/config/test/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java b/framework/config/test/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java index 1c5fbe5c807..5a7f1768e14 100644 --- a/framework/config/test/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java +++ b/framework/config/test/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java @@ -95,6 +95,7 @@ public class ConfigDepotAdminTest extends TestCase { verify(_configDao, times(1)).persist(any(ConfigurationVO.class)); when(_configDao.findById(DynamicIntCK.key())).thenReturn(dynamicIntCV); + _depotAdmin._configured.clear(); _depotAdmin.populateConfigurations(); // This is two because DynamicIntCK also returns null. verify(_configDao, times(2)).persist(any(ConfigurationVO.class)); diff --git a/framework/db/resources/META-INF/cloudstack/system/spring-framework-db-system-context.xml b/framework/db/resources/META-INF/cloudstack/system/spring-framework-db-system-context.xml new file mode 100644 index 00000000000..651b8742a33 --- /dev/null +++ b/framework/db/resources/META-INF/cloudstack/system/spring-framework-db-system-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/framework/db/src/com/cloud/utils/db/Transaction.java b/framework/db/src/com/cloud/utils/db/Transaction.java index a5da4b3575c..60baf9e1de6 100755 --- a/framework/db/src/com/cloud/utils/db/Transaction.java +++ b/framework/db/src/com/cloud/utils/db/Transaction.java @@ -138,7 +138,9 @@ public class Transaction { // the existing DAO features // public void transitToUserManagedConnection(Connection conn) { - assert(_conn == null /*&& _stack.size() <= 1*/) : "Can't change to a user managed connection unless the stack is empty and the db connection is null, you may have forgotten to invoke transitToAutoManagedConnection to close out the DB connection: " + toString(); + if ( _conn != null ) + throw new IllegalStateException("Can't change to a user managed connection unless the db connection is null"); + _conn = conn; _dbId = CONNECTED_DB; } diff --git a/framework/db/src/com/cloud/utils/db/TransactionContextInterceptor.java b/framework/db/src/com/cloud/utils/db/TransactionContextInterceptor.java new file mode 100644 index 00000000000..9dbbbe1a4af --- /dev/null +++ b/framework/db/src/com/cloud/utils/db/TransactionContextInterceptor.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.cloud.utils.db; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + +public class TransactionContextInterceptor implements MethodInterceptor { + + public TransactionContextInterceptor() { + + } + @Override + public Object invoke(MethodInvocation m) throws Throwable { + Transaction txn = Transaction.open(m.getMethod().getName()); + try { + return m.proceed(); + } finally { + txn.close(); + } + } + +} diff --git a/framework/db/src/com/cloud/utils/db/TransactionContextListener.java b/framework/db/src/com/cloud/utils/db/TransactionContextListener.java new file mode 100644 index 00000000000..30e9e0289c9 --- /dev/null +++ b/framework/db/src/com/cloud/utils/db/TransactionContextListener.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.cloud.utils.db; + +import org.apache.cloudstack.managed.context.ManagedContextListener; + +public class TransactionContextListener implements ManagedContextListener { + + @Override + public Transaction onEnterContext(boolean reentry) { + if ( ! reentry ) { + return Transaction.open(Thread.currentThread().getName()); + } + + return null; + } + + @Override + public void onLeaveContext(Transaction data, boolean reentry) { + if ( ! reentry ) { + data.close(); + } + } + +} diff --git a/framework/ipc/resources/META-INF/cloudstack/core/spring-framework-ipc-core-context.xml b/framework/ipc/resources/META-INF/cloudstack/core/spring-framework-ipc-core-context.xml new file mode 100644 index 00000000000..effa23efded --- /dev/null +++ b/framework/ipc/resources/META-INF/cloudstack/core/spring-framework-ipc-core-context.xml @@ -0,0 +1,59 @@ + + + + + + + + org.apache.cloudstack.framework + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/jobs/resources/META-INF/cloudstack/core/spring-framework-jobs-core-context.xml b/framework/jobs/resources/META-INF/cloudstack/core/spring-framework-jobs-core-context.xml new file mode 100644 index 00000000000..85cad0216c0 --- /dev/null +++ b/framework/jobs/resources/META-INF/cloudstack/core/spring-framework-jobs-core-context.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + diff --git a/framework/pom.xml b/framework/pom.xml index 4ea2df14cf2..14e3368d4ba 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -38,5 +38,7 @@ db config managed-context + spring/lifecycle + spring/module diff --git a/framework/spring/lifecycle/pom.xml b/framework/spring/lifecycle/pom.xml new file mode 100644 index 00000000000..647101c69ca --- /dev/null +++ b/framework/spring/lifecycle/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + cloud-framework-spring-lifecycle + Apache CloudStack Framework - Spring Life Cycle + + org.apache.cloudstack + cloud-maven-standard + 4.3.0-SNAPSHOT + ../../../maven-standard/pom.xml + + + + org.apache.cloudstack + cloud-utils + ${project.version} + + + org.apache.cloudstack + cloud-framework-config + ${project.version} + + + diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractBeanCollector.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractBeanCollector.java new file mode 100644 index 00000000000..a3c0d600c71 --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractBeanCollector.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; + +/** + * This class provides a method to do basically the same as @Inject of a type, but + * it will only find the types in the current context and not the parent. This class + * should only be used for very specific Spring bootstrap logic. In general @Inject + * is infinitely better. Basically you need a very good reason to use this. + * + */ +public abstract class AbstractBeanCollector extends AbstractSmartLifeCycle implements BeanPostProcessor { + + Class[] typeClasses = new Class[] {}; + Map, Set> beans = new HashMap, Set>(); + + @Override + public int getPhase() { + return 2000; + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + for ( Class typeClass : typeClasses ) { + if ( typeClass.isAssignableFrom(bean.getClass()) ) { + doPostProcessBeforeInitialization(bean, beanName); + break; + } + } + + return bean; + } + + protected void doPostProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + } + + protected void doPostProcessAfterInitialization(Object bean, Class typeClass, String beanName) throws BeansException { + Set beansOfType = beans.get(typeClass); + + if ( beansOfType == null ) { + beansOfType = new HashSet(); + beans.put(typeClass, beansOfType); + } + + beansOfType.add(bean); + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + for ( Class typeClass : typeClasses ) { + if ( typeClass.isAssignableFrom(bean.getClass()) ) { + doPostProcessAfterInitialization(bean, typeClass, beanName); + } + } + + return bean; + } + + protected Set getBeans(Class typeClass) { + @SuppressWarnings("unchecked") + Set result = (Set) beans.get(typeClass); + + if ( result == null ) + return Collections.emptySet(); + + return result; + } + + public Class getTypeClass() { + if ( typeClasses == null || typeClasses.length == 0 ) + return null; + + return typeClasses[0]; + } + + public void setTypeClass(Class typeClass) { + this.typeClasses = new Class[] { typeClass }; + } + + public Class[] getTypeClasses() { + return typeClasses; + } + + public void setTypeClasses(Class[] typeClasses) { + this.typeClasses = typeClasses; + } + +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java new file mode 100644 index 00000000000..071817b0b66 --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle; + +import org.springframework.context.SmartLifecycle; + +public abstract class AbstractSmartLifeCycle implements SmartLifecycle { + + boolean running = false; + + @Override + public void start() { + running = true; + } + + @Override + public void stop() { + running = false; + } + + @Override + public boolean isRunning() { + return running; + } + + @Override + public boolean isAutoStartup() { + return true; + } + + @Override + public void stop(Runnable callback) { + stop(); + callback.run(); + } + +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java new file mode 100644 index 00000000000..1b7ea513061 --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.MBeanRegistrationException; +import javax.management.MalformedObjectNameException; +import javax.management.NotCompliantMBeanException; +import javax.naming.ConfigurationException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.cloud.utils.component.ComponentLifecycle; +import com.cloud.utils.component.SystemIntegrityChecker; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.mgmt.JmxUtil; +import com.cloud.utils.mgmt.ManagementBean; + +public class CloudStackExtendedLifeCycle extends AbstractBeanCollector { + + private static final Logger log = LoggerFactory.getLogger(CloudStackExtendedLifeCycle.class); + + Map> sorted = new TreeMap>(); + + public CloudStackExtendedLifeCycle() { + super(); + setTypeClasses(new Class[] { + ComponentLifecycle.class, + SystemIntegrityChecker.class + }); + } + + @Override + public void start() { + sortBeans(); + checkIntegrity(); + configure(); + + super.start(); + } + + protected void checkIntegrity() { + for ( SystemIntegrityChecker checker : getBeans(SystemIntegrityChecker.class) ) { + log.info("Running system integrity checker {}", checker); + + checker.check(); + } + } + + public void startBeans() { + log.info("Starting CloudStack Components"); + + with(new WithComponentLifeCycle() { + @Override + public void with(ComponentLifecycle lifecycle) { + lifecycle.start(); + + if ( lifecycle instanceof ManagementBean ) { + ManagementBean mbean = (ManagementBean)lifecycle; + try { + JmxUtil.registerMBean(mbean); + } catch (MalformedObjectNameException e) { + log.warn("Unable to register MBean: " + mbean.getName(), e); + } catch (InstanceAlreadyExistsException e) { + log.warn("Unable to register MBean: " + mbean.getName(), e); + } catch (MBeanRegistrationException e) { + log.warn("Unable to register MBean: " + mbean.getName(), e); + } catch (NotCompliantMBeanException e) { + log.warn("Unable to register MBean: " + mbean.getName(), e); + } + log.info("Registered MBean: " + mbean.getName()); + } + } + }); + + log.info("Done Starting CloudStack Components"); + } + + public void stopBeans() { + with(new WithComponentLifeCycle() { + @Override + public void with(ComponentLifecycle lifecycle) { + lifecycle.stop(); + } + }); + } + + private void configure() { + log.info("Configuring CloudStack Components"); + + with(new WithComponentLifeCycle() { + @Override + public void with(ComponentLifecycle lifecycle) { + try { + lifecycle.configure(lifecycle.getName(), lifecycle.getConfigParams()); + } catch (ConfigurationException e) { + log.error("Failed to configure {}", lifecycle.getName(), e); + throw new CloudRuntimeException(e); + } + } + }); + + log.info("Done Configuring CloudStack Components"); + } + + private void sortBeans() { + for ( ComponentLifecycle lifecycle : getBeans(ComponentLifecycle.class) ) { + Set set = sorted.get(lifecycle.getRunLevel()); + + if ( set == null ) { + set = new HashSet(); + sorted.put(lifecycle.getRunLevel(), set); + } + + set.add(lifecycle); + } + } + + @Override + public void stop() { + with(new WithComponentLifeCycle() { + @Override + public void with(ComponentLifecycle lifecycle) { + lifecycle.stop(); + } + }); + + super.stop(); + } + + protected void with(WithComponentLifeCycle with) { + for ( Set lifecycles : sorted.values() ) { + for ( ComponentLifecycle lifecycle : lifecycles ) { + with.with(lifecycle); + } + } + } + + @Override + public int getPhase() { + return 2000; + } + + private static interface WithComponentLifeCycle { + public void with(ComponentLifecycle lifecycle); + } +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java new file mode 100644 index 00000000000..33d4aea24e4 --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle; + +public class CloudStackExtendedLifeCycleStart extends AbstractSmartLifeCycle implements Runnable { + + CloudStackExtendedLifeCycle lifeCycle; + + @Override + public void stop() { + lifeCycle.stopBeans(); + super.stop(); + } + + @Override + public int getPhase() { + return 3000; + } + + public CloudStackExtendedLifeCycle getLifeCycle() { + return lifeCycle; + } + + public void setLifeCycle(CloudStackExtendedLifeCycle lifeCycle) { + this.lifeCycle = lifeCycle; + } + + @Override + public void run() { + lifeCycle.startBeans(); + } + +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackLog4jSetup.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackLog4jSetup.java new file mode 100644 index 00000000000..163703d0447 --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackLog4jSetup.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle; + +import org.springframework.context.SmartLifecycle; + +import com.cloud.utils.LogUtils; + +public class CloudStackLog4jSetup implements SmartLifecycle { + + @Override + public void start() { + LogUtils.initLog4j("log4j-cloud.xml"); + } + + @Override + public void stop() { + } + + @Override + public boolean isRunning() { + return false; + } + + @Override + public int getPhase() { + return 0; + } + + @Override + public boolean isAutoStartup() { + return true; + } + + @Override + public void stop(Runnable callback) { + callback.run(); + } + +} \ No newline at end of file diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/ConfigDepotLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/ConfigDepotLifeCycle.java new file mode 100644 index 00000000000..b380028964e --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/ConfigDepotLifeCycle.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle; + +import javax.inject.Inject; + +import org.apache.cloudstack.framework.config.ConfigDepotAdmin; +import org.apache.cloudstack.framework.config.Configurable; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; + +public class ConfigDepotLifeCycle implements BeanPostProcessor { + + @Inject + ConfigDepotAdmin configDepotAdmin; + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + if ( bean instanceof Configurable ) { + configDepotAdmin.populateConfiguration((Configurable)bean); + } + + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java new file mode 100644 index 00000000000..5614a32aee5 --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle.registry; + +import java.util.List; + +import com.cloud.utils.component.ComponentLifecycleBase; +import com.cloud.utils.component.Named; +import com.cloud.utils.component.Registry; + +import javax.inject.Inject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DumpRegistry extends ComponentLifecycleBase { + + private static final Logger log = LoggerFactory.getLogger(DumpRegistry.class); + + List> registries; + + public List> getRegistries() { + return registries; + } + + @Inject + public void setRegistries(List> registries) { + this.registries = registries; + } + + @Override + public boolean start() { + for ( Registry registry : registries ) { + StringBuilder buffer = new StringBuilder(); + + for ( Object o : registry.getRegistered() ) { + if ( buffer.length() > 0 ) + buffer.append(", "); + + buffer.append(getName(o)); + } + + log.info("Registry [{}] contains [{}]", registry.getName(), buffer); + } + + return super.start(); + } + + protected String getName(Object o) { + String name = null; + if (o instanceof Named) { + name = ((Named) o).getName(); + } + + if (name == null) { + name = o.getClass().getSimpleName(); + } + + return name; + } +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java new file mode 100644 index 00000000000..2bd362eb8e3 --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java @@ -0,0 +1,245 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle.registry; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import javax.annotation.PostConstruct; + +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.BeanNameAware; + +import com.cloud.utils.component.Named; +import com.cloud.utils.component.Registry; + +public class ExtensionRegistry implements Registry, Configurable, BeanNameAware { + + private static final Logger log = LoggerFactory.getLogger(ExtensionRegistry.class); + + String name; + String beanName; + + String orderConfigKey; + String orderConfigDefault; + ConfigKey orderConfigKeyObj; + + String excludeKey; + String excludeDefault; + ConfigKey excludeKeyObj; + + String configComponentName; + List preRegistered; + List registered = new CopyOnWriteArrayList(); + List readOnly = Collections.unmodifiableList(registered); + + @Override + public boolean register(Object item) { + if ( registered.contains(item) ) + return false; + + String[] order = new String[] {}; + Set exclude = new HashSet(); + + if ( orderConfigKeyObj != null ) { + Object value = orderConfigKeyObj.value(); + if ( value != null && value.toString().trim().length() > 0 ) { + order = value.toString().trim().split("\\s*,\\s*"); + } + } + + if ( excludeKeyObj != null ) { + Object value = excludeKeyObj.value(); + if ( value != null && value.toString().trim().length() > 0 ) { + for ( String e : value.toString().trim().split("\\s*,\\s*") ) { + exclude.add(e); + } + } + } + + String name = getName(item); + + if ( name != null && exclude.size() > 0 && exclude.contains(name) ) { + return false; + } + + if ( name == null && order.length > 0 ) { + throw new RuntimeException("getName() is null for [" + item + "]"); + } + + int i = 0; + for ( String orderTest : order ) { + if ( orderTest.equals(name) ) { + registered.add(i, item); + i = -1; + break; + } + + if ( registered.size() <= i ) { + break; + } + + if ( getName(registered.get(i)).equals(orderTest) ) { + i++; + } + } + + if ( i != -1 ) { + registered.add(item); + } + + log.debug("Registering extension [{}] in [{}]", name, this.name); + + return true; + } + + protected String getName(Object object) { + if ( object instanceof Named ) { + String name = ((Named)object).getName(); + if ( name != null ) + return name; + } + + return object == null ? null : object.getClass().getSimpleName(); + } + + @Override + public void unregister(Object type) { + registered.remove(type); + } + + @Override + public List getRegistered() { + return readOnly; + } + + @Override + public String getConfigComponentName() { + return configComponentName == null ? this.getClass().getSimpleName() : configComponentName; + } + + @Override + public ConfigKey[] getConfigKeys() { + List> result = new ArrayList>(); + + if ( orderConfigKey != null && orderConfigKeyObj == null ) { + orderConfigKeyObj = new ConfigKey("Advanced", String.class, orderConfigKey, orderConfigDefault, + "The order of precedence for the extensions", false); + } + + if ( orderConfigKeyObj != null ) + result.add(orderConfigKeyObj); + + if ( excludeKey != null && excludeKeyObj == null ) { + excludeKeyObj = new ConfigKey("Advanced", String.class, excludeKey, excludeDefault, + "Extensions to exclude from being registered", false); + } + + if ( excludeKeyObj != null ) { + result.add(excludeKeyObj); + } + + return result.toArray(new ConfigKey[result.size()]); + } + + @PostConstruct + public void init() { + if ( name == null ) { + for ( String part : beanName.replaceAll("([A-Z])", " $1").split("\\s+") ) { + part = StringUtils.capitalize(part.toLowerCase());; + + name = name == null ? part : name + " " + part; + } + } + + if ( preRegistered != null ) { + for ( Object o : preRegistered ) { + register(o); + } + } + } + + + public String getOrderConfigKey() { + return orderConfigKey; + } + + public void setOrderConfigKey(String orderConfigKey) { + this.orderConfigKey = orderConfigKey; + } + + public void setConfigComponentName(String configComponentName) { + this.configComponentName = configComponentName; + } + + public String getOrderConfigDefault() { + return orderConfigDefault; + } + + public void setOrderConfigDefault(String orderConfigDefault) { + this.orderConfigDefault = orderConfigDefault; + } + + public String getExcludeKey() { + return excludeKey; + } + + public void setExcludeKey(String excludeKey) { + this.excludeKey = excludeKey; + } + + public String getExcludeDefault() { + return excludeDefault; + } + + public void setExcludeDefault(String excludeDefault) { + this.excludeDefault = excludeDefault; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public void setBeanName(String name) { + this.beanName = name; + } + + public List getPreRegistered() { + return preRegistered; + } + + public void setPreRegistered(List preRegistered) { + this.preRegistered = preRegistered; + } + +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/PluggableServiceLifecycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/PluggableServiceLifecycle.java new file mode 100644 index 00000000000..3eeeed83c7b --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/PluggableServiceLifecycle.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle.registry; + +import com.cloud.utils.component.ComponentContext; +import com.cloud.utils.component.PluggableService; + +public class PluggableServiceLifecycle extends RegistryLifecycle { + + @Override + public void start() { + super.start(); + + for (Object obj : beans) { + if (obj instanceof PluggableService) { + for (Class cmd : ((PluggableService) obj).getCommands()) { + ComponentContext.addDelegateContext(cmd, applicationContext); + } + } + } + } + + @Override + public void stop() { + for (Object obj : beans) { + if (obj instanceof PluggableService) { + for (Class cmd : ((PluggableService) obj).getCommands()) { + ComponentContext.removeDelegateContext(cmd); + } + } + } + + super.stop(); + } + + +} diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java new file mode 100644 index 00000000000..bd7a0334a6f --- /dev/null +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.lifecycle.registry; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.SmartLifecycle; + +import com.cloud.utils.component.Registry; + +public class RegistryLifecycle implements BeanPostProcessor, SmartLifecycle, ApplicationContextAware { + + private static final Logger log = LoggerFactory.getLogger(RegistryLifecycle.class); + + Registry registry; + + /* The bean name works around circular dependency issues in Spring. This shouldn't be + * needed if your beans are already nicely organized. If they look like spaghetti, then you + * can use this. + */ + String registryBeanName; + Set beans = new HashSet(); + Class typeClass; + ApplicationContext applicationContext; + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + if ( typeClass.isAssignableFrom(bean.getClass()) ) + beans.add(bean); + + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + @Override + public void start() { + Iterator iter = beans.iterator(); + Registry registry = lookupRegistry(); + + while ( iter.hasNext() ) { + Object next = iter.next(); + if ( registry.register(next) ) { + log.debug("Registered {}", next); + } else { + iter.remove(); + } + } + } + + @Override + public void stop() { + Registry registry = lookupRegistry(); + + for ( Object bean : beans ) { + registry.unregister(bean); + } + + beans.clear(); + } + + @Override + public boolean isRunning() { + return false; + } + + @Override + public int getPhase() { + return 2000; + } + + @Override + public boolean isAutoStartup() { + return true; + } + + @Override + public void stop(Runnable callback) { + stop(); + callback.run(); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + @SuppressWarnings("unchecked") + protected Registry lookupRegistry() { + return registry == null ? applicationContext.getBean(registryBeanName, Registry.class) : registry; + } + + public Registry getRegistry() { + return registry; + } + + public void setRegistry(Registry registry) { + this.registry = registry; + } + + public Class getTypeClass() { + return typeClass; + } + + public void setTypeClass(Class typeClass) { + this.typeClass = typeClass; + } + + public String getRegistryBeanName() { + return registryBeanName; + } + + public void setRegistryBeanName(String registryBeanName) { + this.registryBeanName = registryBeanName; + } + +} diff --git a/framework/spring/module/pom.xml b/framework/spring/module/pom.xml new file mode 100644 index 00000000000..b9d95a8447f --- /dev/null +++ b/framework/spring/module/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + cloud-framework-spring-module + + org.apache.cloudstack + cloud-maven-standard + 4.3.0-SNAPSHOT + ../../../maven-standard/pom.xml + + + + org.apache.cloudstack + cloud-utils + ${project.version} + + + commons-io + commons-io + + + org.springframework + spring-web + + + javax.servlet + servlet-api + provided + true + + + diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/context/ResourceApplicationContext.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/context/ResourceApplicationContext.java new file mode 100644 index 00000000000..60d0262ab36 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/context/ResourceApplicationContext.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.context; + +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.core.io.Resource; + +public class ResourceApplicationContext extends AbstractXmlApplicationContext { + + Resource[] configResources; + String applicationName = ""; + + public ResourceApplicationContext() { + } + + public ResourceApplicationContext(Resource... configResources) { + super(); + this.configResources = configResources; + } + + @Override + protected Resource[] getConfigResources() { + return configResources; + } + + public void setConfigResources(Resource[] configResources) { + this.configResources = configResources; + } + + @Override + public String getApplicationName() { + return applicationName; + } + + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; + } + +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java new file mode 100644 index 00000000000..e624a5b04d4 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.factory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.cloudstack.spring.module.locator.ModuleDefinitionLocator; +import org.apache.cloudstack.spring.module.locator.impl.ClasspathModuleDefinitionLocator; +import org.apache.cloudstack.spring.module.model.ModuleDefinition; +import org.apache.cloudstack.spring.module.model.ModuleDefinitionSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.io.Resource; + +public class CloudStackSpringContext { + + private static final Logger log = LoggerFactory.getLogger(CloudStackSpringContext.class); + + public static final String CLOUDSTACK_CONTEXT = "META-INF/cloudstack"; + public static final String CLOUDSTACK_BASE = "bootstrap"; + + ModuleBasedContextFactory factory = new ModuleBasedContextFactory(); + ModuleDefinitionLocator loader = new ClasspathModuleDefinitionLocator(); + ModuleDefinitionSet moduleDefinitionSet; + String baseName; + String contextName; + + public CloudStackSpringContext(String context, String base) throws IOException { + this.baseName = base; + this.contextName = context; + + factory = new ModuleBasedContextFactory(); + loader = new ClasspathModuleDefinitionLocator(); + init(); + } + + public CloudStackSpringContext() throws IOException { + this(CLOUDSTACK_CONTEXT, CLOUDSTACK_BASE); + } + + public void init() throws IOException { + Collection defs = loader.locateModules(contextName); + + if ( defs.size() == 0 ) + throw new RuntimeException("No modules found to load for Spring"); + + moduleDefinitionSet = factory.loadModules(defs, baseName); + } + + public void registerShutdownHook() { + ApplicationContext base = moduleDefinitionSet.getApplicationContext(baseName); + + if ( base instanceof ConfigurableApplicationContext ) { + ((ConfigurableApplicationContext)base).registerShutdownHook(); + } + } + + public ModuleDefinition getModuleDefinitionForWeb(String name) { + ModuleDefinition def = moduleDefinitionSet.getModuleDefinition(name); + + if ( def != null ) { + return def; + } + + /* Grab farthest descendant that is deterministic */ + def = moduleDefinitionSet.getModuleDefinition(baseName); + + if ( def == null ) { + throw new RuntimeException("Failed to find base spring module to extend for web"); + } + + while ( def.getChildren().size() == 1 ) { + def = def.getChildren().iterator().next(); + } + + return def; + } + + public ApplicationContext getApplicationContextForWeb(String name) { + ModuleDefinition def = getModuleDefinitionForWeb(name); + + return moduleDefinitionSet.getApplicationContext(def.getName()); + } + + public String[] getConfigLocationsForWeb(String name, String[] configured) { + if ( configured == null ) + configured = new String[] {}; + + ModuleDefinition def = getModuleDefinitionForWeb(name); + + List inherited = new ArrayList(); + + while ( def != null ) { + inherited.addAll(def.getInheritableContextLocations()); + def = moduleDefinitionSet.getModuleDefinition(def.getParentName()); + } + + List urlList = new ArrayList(); + + for ( Resource r : inherited ) { + try { + String urlString = r.getURL().toExternalForm(); + urlList.add(urlString); + } catch (IOException e) { + log.error("Failed to create URL for {}", r.getDescription(), e); + } + } + + String[] result = new String[urlList.size() + configured.length]; + result = urlList.toArray(result); + + System.arraycopy(configured, 0, result, urlList.size(), configured.length); + + return result; + } +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/ModuleBasedContextFactory.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/ModuleBasedContextFactory.java new file mode 100644 index 00000000000..3f89d3ab935 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/ModuleBasedContextFactory.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.factory; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.cloudstack.spring.module.model.ModuleDefinition; +import org.apache.cloudstack.spring.module.model.ModuleDefinitionSet; +import org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet; + +public class ModuleBasedContextFactory { + + public ModuleDefinitionSet loadModules(Collection defs, String root) throws IOException { + + Map modules = wireUpModules(root, defs); + + DefaultModuleDefinitionSet moduleSet = new DefaultModuleDefinitionSet(modules, root); + moduleSet.load(); + + return moduleSet; + } + + protected Map wireUpModules(String root, Collection defs) throws IOException { + Map modules = new HashMap(); + + for ( ModuleDefinition def : defs ) { + modules.put(def.getName(), def); + } + + ModuleDefinition rootDef = null; + Map result = new HashMap(); + + for ( ModuleDefinition def : modules.values() ) { + if ( def.getName().equals(root) ) { + rootDef = def; + } + + if ( def.getParentName() != null ) { + ModuleDefinition parentDef = modules.get(def.getParentName()); + + if ( parentDef != null ) + parentDef.addChild(def); + } + } + + return traverse(rootDef, result); + } + + protected Map traverse(ModuleDefinition base, Map result) { + if ( base == null ) + return result; + + if ( result.containsKey(base.getName()) ) { + throw new RuntimeException("Circular dependency to [" + base.getName() + "] from current set " + + result.keySet()); + } + + result.put(base.getName(), base); + + for ( ModuleDefinition childDef : base.getChildren() ) + traverse(childDef, result); + + return result; + } +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/locator/ModuleDefinitionLocator.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/locator/ModuleDefinitionLocator.java new file mode 100644 index 00000000000..6b14e0abfd7 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/locator/ModuleDefinitionLocator.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.locator; + +import java.io.IOException; +import java.util.Collection; + +import org.apache.cloudstack.spring.module.model.ModuleDefinition; + +/** + * Responsible for locating the ModuleDefinition for a given context. The implementation + * of this class should take extra care to set the ClassLoader of the ModuleDefinition + * properly. + * + */ +public interface ModuleDefinitionLocator { + + Collection locateModules(String context) throws IOException; + +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/locator/impl/ClasspathModuleDefinitionLocator.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/locator/impl/ClasspathModuleDefinitionLocator.java new file mode 100644 index 00000000000..c9deacc23e8 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/locator/impl/ClasspathModuleDefinitionLocator.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.locator.impl; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.cloudstack.spring.module.locator.ModuleDefinitionLocator; +import org.apache.cloudstack.spring.module.model.ModuleDefinition; +import org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinition; +import org.apache.cloudstack.spring.module.util.ModuleLocationUtils; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; + +public class ClasspathModuleDefinitionLocator implements ModuleDefinitionLocator { + + protected ResourcePatternResolver getResolver() { + return new PathMatchingResourcePatternResolver(); + } + + public Collection locateModules(String context) throws IOException { + ResourcePatternResolver resolver = getResolver(); + + Map allModules = discoverModules(context, resolver); + + return allModules.values(); + } + + protected Map discoverModules(String baseDir, ResourcePatternResolver resolver) throws IOException { + Map result = new HashMap(); + + for ( Resource r : resolver.getResources(ModuleLocationUtils.getModulesLocation(baseDir)) ) { + DefaultModuleDefinition def = new DefaultModuleDefinition(baseDir, r, resolver); + def.init(); + + if ( def.isValid() ) + result.put(def.getName(), def); + } + + return result; + } + +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/ModuleDefinition.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/ModuleDefinition.java new file mode 100644 index 00000000000..b3c46474224 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/ModuleDefinition.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.model; + +import java.util.Collection; +import java.util.List; + +import org.springframework.core.io.Resource; + +public interface ModuleDefinition { + + ClassLoader getClassLoader(); + + String getName(); + + String getParentName(); + + List getConfigLocations(); + + List getContextLocations(); + + List getInheritableContextLocations(); + + List getOverrideContextLocations(); + + boolean isValid(); + + Collection getChildren(); + + void addChild(ModuleDefinition childDef); + +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/ModuleDefinitionSet.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/ModuleDefinitionSet.java new file mode 100644 index 00000000000..635a7a193df --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/ModuleDefinitionSet.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.model; + +import org.springframework.context.ApplicationContext; +import org.springframework.core.io.Resource; + +public interface ModuleDefinitionSet { + + ModuleDefinition getModuleDefinition(String name); + + ApplicationContext getApplicationContext(String name); + + Resource[] getConfigResources(String name); + +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinition.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinition.java new file mode 100644 index 00000000000..6c5180874b8 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinition.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.model.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +import org.apache.cloudstack.spring.module.model.ModuleDefinition; +import org.apache.cloudstack.spring.module.util.ModuleLocationUtils; +import org.apache.commons.io.IOUtils; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.util.StringUtils; + +public class DefaultModuleDefinition implements ModuleDefinition { + + public static final String NAME = "name"; + public static final String PARENT = "parent"; + + String name; + String baseDir; + String parent; + Resource moduleProperties; + ResourcePatternResolver resolver; + boolean valid; + + List configLocations; + List contextLocations; + List inheritableContextLocations; + List overrideContextLocations; + Map children = new TreeMap(); + + public DefaultModuleDefinition(String baseDir, Resource moduleProperties, ResourcePatternResolver resolver) { + this.baseDir = baseDir; + this.resolver = resolver; + this.moduleProperties = moduleProperties; + } + + public void init() throws IOException { + + if ( ! moduleProperties.exists() ) { + return; + } + + resolveNameAndParent(); + + contextLocations = Arrays.asList(resolver.getResources(ModuleLocationUtils.getContextLocation(baseDir, name))); + configLocations = Arrays.asList(resolver.getResources(ModuleLocationUtils.getDefaultsLocation(baseDir, name))); + inheritableContextLocations = Arrays.asList(resolver.getResources(ModuleLocationUtils.getInheritableContextLocation(baseDir, name))); + overrideContextLocations = Arrays.asList(resolver.getResources(ModuleLocationUtils.getOverrideContextLocation(baseDir, name))); + + valid = true; + } + + protected void resolveNameAndParent() throws IOException { + InputStream is = null; + + try { + is = moduleProperties.getInputStream(); + Properties props = new Properties(); + props.load(is); + + name = props.getProperty(NAME); + parent = props.getProperty(PARENT); + + if ( ! StringUtils.hasText(name) ) { + throw new IOException("Missing name property in [" + location() + "]"); + } + + if ( ! StringUtils.hasText(parent) ) { + parent = null; + } + + checkNameMatchesSelf(); + } finally { + IOUtils.closeQuietly(is); + } + } + + protected void checkNameMatchesSelf() throws IOException { + String expectedLocation = ModuleLocationUtils.getModuleLocation(baseDir, name); + Resource self = resolver.getResource(expectedLocation); + + if ( ! self.exists() ) { + throw new IOException("Resource [" + location() + "] is expected to exist at [" + + expectedLocation + "] please ensure the name property is correct"); + } + + String moduleUrl = moduleProperties.getURL().toExternalForm(); + String selfUrl = self.getURL().toExternalForm(); + + if ( ! moduleUrl.equals(selfUrl) ) { + throw new IOException("Resource [" + location() + "] and [" + + self.getURL() + "] do not appear to be the same resource, " + + "please ensure the name property is correct"); + } + } + + private String location() throws IOException { + return moduleProperties.getURL().toString(); + } + + public void addChild(ModuleDefinition def) { + children.put(def.getName(), def); + } + + public Collection getChildren() { + return children.values(); + } + + public String getName() { + return name; + } + + public String getParentName() { + return parent; + } + + public List getConfigLocations() { + return configLocations; + } + + public List getContextLocations() { + return contextLocations; + } + + public List getInheritableContextLocations() { + return inheritableContextLocations; + } + + @Override + public List getOverrideContextLocations() { + return overrideContextLocations; + } + + public boolean isValid() { + return valid; + } + + public ClassLoader getClassLoader() { + return resolver.getClassLoader(); + } + + +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java new file mode 100644 index 00000000000..15df839cf1a --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java @@ -0,0 +1,243 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.model.impl; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.EmptyStackException; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Stack; + +import org.apache.cloudstack.spring.module.context.ResourceApplicationContext; +import org.apache.cloudstack.spring.module.model.ModuleDefinition; +import org.apache.cloudstack.spring.module.model.ModuleDefinitionSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; + +public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { + + private static final Logger log = LoggerFactory.getLogger(DefaultModuleDefinitionSet.class); + + public static final String DEFAULT_CONFIG_RESOURCES = "DefaultConfigResources"; + public static final String DEFAULT_CONFIG_XML = "defaults-context.xml"; + + String root; + Map modules; + Map contexts = new HashMap(); + ApplicationContext rootContext = null; + + public DefaultModuleDefinitionSet(Map modules, String root) { + super(); + this.root = root; + this.modules = modules; + } + + public void load() throws IOException { + if ( ! loadRootContext() ) + return; + + printHierarchy(); + loadContexts(); + startContexts(); + } + + protected boolean loadRootContext() { + ModuleDefinition def = modules.get(root); + + if ( def == null ) + return false; + + ApplicationContext defaultsContext = getDefaultsContext(); + + rootContext = loadContext(def, defaultsContext); + + return true; + } + + protected void startContexts() { + withModule(new WithModule() { + public void with(ModuleDefinition def, Stack parents) { + try { + ApplicationContext context = getApplicationContext(def.getName()); + try { + Runnable runnable = context.getBean("moduleStartup", Runnable.class); + log.info("Starting module [{}]", def.getName()); + runnable.run(); + } catch ( BeansException e ) { + // Ignore + } + } catch ( EmptyStackException e ) { + // The root context is already loaded, so ignore the exception + } + } + }); + } + + protected void loadContexts() { + withModule(new WithModule() { + public void with(ModuleDefinition def, Stack parents) { + try { + ApplicationContext parent = getApplicationContext(parents.peek().getName()); + loadContext(def, parent); + } catch ( EmptyStackException e ) { + // The root context is already loaded, so ignore the exception + } + } + }); + } + protected ApplicationContext loadContext(ModuleDefinition def, ApplicationContext parent) { + ResourceApplicationContext context = new ResourceApplicationContext(); + context.setApplicationName("/" + def.getName()); + + Resource[] resources = getConfigResources(def.getName()); + context.setConfigResources(resources); + context.setParent(parent); + context.setClassLoader(def.getClassLoader()); + + long start = System.currentTimeMillis(); + if ( log.isInfoEnabled() ) { + for ( Resource resource : resources ) { + log.info("Loading module context [{}] from {}", def.getName(), resource); + } + } + context.refresh(); + log.info("Loaded module context [{}] in {} ms", def.getName(), (System.currentTimeMillis() - start)); + + contexts.put(def.getName(), context); + + return context; + } + + protected boolean shouldLoad(ModuleDefinition def) { + return true; + } + + protected ApplicationContext getDefaultsContext() { + URL config = DefaultModuleDefinitionSet.class.getResource(DEFAULT_CONFIG_XML); + + ResourceApplicationContext context = new ResourceApplicationContext(new UrlResource(config)); + context.setApplicationName("/defaults"); + context.refresh(); + + @SuppressWarnings("unchecked") + final List resources = (List) context.getBean(DEFAULT_CONFIG_RESOURCES); + + withModule(new WithModule() { + public void with(ModuleDefinition def, Stack parents) { + for ( Resource defaults : def.getConfigLocations() ) { + resources.add(defaults); + } + } + }); + + return context; + } + + protected void printHierarchy() { + withModule(new WithModule() { + public void with(ModuleDefinition def, Stack parents) { + log.info(String.format("Module Hierarchy:%" + ((parents.size() * 2) + 1) + "s%s", "", def.getName())); + } + }); + } + + protected void withModule(WithModule with) { + ModuleDefinition rootDef = modules.get(root); + withModule(rootDef, new Stack(), with); + } + + protected void withModule(ModuleDefinition def, Stack parents, WithModule with) { + if ( def == null ) + return; + + if ( ! shouldLoad(def) ) { + return; + } + + with.with(def, parents); + + parents.push(def); + + for ( ModuleDefinition child : def.getChildren() ) { + withModule(child, parents, with); + } + + parents.pop(); + } + + private static interface WithModule { + public void with(ModuleDefinition def, Stack parents); + } + + @Configuration + public static class ConfigContext { + + List resources; + + public ConfigContext(List resources) { + super(); + this.resources = resources; + } + + @Bean(name = DEFAULT_CONFIG_RESOURCES) + public List defaultConfigResources() { + return new ArrayList(); + } + } + + public ApplicationContext getApplicationContext(String name) { + return contexts.get(name); + } + + public Resource[] getConfigResources(String name) { + Set resources = new LinkedHashSet(); + + ModuleDefinition original = null; + ModuleDefinition def = original = modules.get(name); + + if ( def == null ) + return new Resource[] {}; + + resources.addAll(def.getContextLocations()); + + while ( def != null ) { + resources.addAll(def.getInheritableContextLocations()); + def = modules.get(def.getParentName()); + } + + resources.addAll(original.getOverrideContextLocations()); + + return resources.toArray(new Resource[resources.size()]); + } + + public ModuleDefinition getModuleDefinition(String name) { + return modules.get(name); + } +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/Main.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/Main.java new file mode 100644 index 00000000000..3a9660c4793 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/Main.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.util; + +import org.apache.cloudstack.spring.module.factory.CloudStackSpringContext; + +public class Main { + + long start = System.currentTimeMillis(); + + public Main() { + + } + + public void start() throws Exception { + CloudStackSpringContext context = new CloudStackSpringContext(); + context.registerShutdownHook(); + + if ( Boolean.getBoolean("force.exit") ) { + System.exit(0); + } + } + + public long getTime() { + return System.currentTimeMillis() - start; + } + + + public static void main(String... args) { + Main main = new Main(); + + try { + main.start(); + System.out.println("STARTUP COMPLETE [" + main.getTime() + "] ms"); + } catch ( Exception e ) { + e.printStackTrace(); + System.out.println("STARTUP FAILED [" + main.getTime() + "] ms"); + System.err.println("STARTUP FAILED [" + main.getTime() + "] ms"); + System.exit(1); + } + } +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/ModuleLocationUtils.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/ModuleLocationUtils.java new file mode 100644 index 00000000000..eeab154b395 --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/ModuleLocationUtils.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.util; + +public class ModuleLocationUtils { + + private static final String ALL_MODULE_PROPERTIES = "classpath*:%s/*/module.properties"; + private static final String MODULE_PROPERTIES = "classpath:%s/%s/module.properties"; + private static final String CONTEXT_LOCATION = "classpath*:%s/%s/*context.xml"; + private static final String INHERTIABLE_CONTEXT_LOCATION = "classpath*:%s/%s/*context-inheritable.xml"; + private static final String OVERRIDE_CONTEXT_LOCATION = "classpath*:%s/%s/*context-override.xml"; + private static final String DEFAULTS_LOCATION = "classpath*:%s/%s/*defaults.properties"; + + public static String getModulesLocation(String baseDir) { + return String.format(ALL_MODULE_PROPERTIES, baseDir); + } + + public static String getModuleLocation(String baseDir, String name) { + return String.format(MODULE_PROPERTIES, baseDir, name); + } + + public static String getContextLocation(String baseDir, String name) { + return String.format(CONTEXT_LOCATION, baseDir, name); + } + + public static String getInheritableContextLocation(String baseDir, String name) { + return String.format(INHERTIABLE_CONTEXT_LOCATION, baseDir, name); + } + + public static String getOverrideContextLocation(String baseDir, String name) { + return String.format(OVERRIDE_CONTEXT_LOCATION, baseDir, name); + } + + public static String getDefaultsLocation(String baseDir, String name) { + return String.format(DEFAULTS_LOCATION, baseDir, name); + } +} diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java new file mode 100644 index 00000000000..e704437774b --- /dev/null +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.web; + +import java.io.IOException; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.apache.cloudstack.spring.module.factory.CloudStackSpringContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.ConfigurableWebApplicationContext; +import org.springframework.web.context.ContextLoaderListener; + +public class CloudStackContextLoaderListener extends ContextLoaderListener { + + public static final String WEB_PARENT_MODULE = "parentModule"; + public static final String WEB_PARENT_MODULE_DEFAULT = "web"; + + private static final Logger log = LoggerFactory.getLogger(CloudStackContextLoaderListener.class); + + CloudStackSpringContext cloudStackContext; + String configuredParentName; + + @Override + protected ApplicationContext loadParentContext(ServletContext servletContext) { + return cloudStackContext.getApplicationContextForWeb(configuredParentName); + } + + @Override + public void contextInitialized(ServletContextEvent event) { + try { + cloudStackContext = new CloudStackSpringContext(); + } catch (IOException e) { + log.error("Failed to start CloudStack", e); + throw new RuntimeException("Failed to initialize CloudStack Spring modules", e); + } + + configuredParentName = event.getServletContext().getInitParameter(WEB_PARENT_MODULE); + if ( configuredParentName == null ) { + configuredParentName = WEB_PARENT_MODULE_DEFAULT; + } + + super.contextInitialized(event); + } + + @Override + protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { + super.customizeContext(servletContext, applicationContext); + + String[] newLocations = cloudStackContext.getConfigLocationsForWeb(configuredParentName, + applicationContext.getConfigLocations()); + + applicationContext.setConfigLocations(newLocations); + } + +} diff --git a/framework/spring/module/src/main/resources/org/apache/cloudstack/spring/module/model/impl/defaults-context.xml b/framework/spring/module/src/main/resources/org/apache/cloudstack/spring/module/model/impl/defaults-context.xml new file mode 100644 index 00000000000..b19833a735b --- /dev/null +++ b/framework/spring/module/src/main/resources/org/apache/cloudstack/spring/module/model/impl/defaults-context.xml @@ -0,0 +1,28 @@ + + + + + + diff --git a/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/factory/InitTest.java b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/factory/InitTest.java new file mode 100644 index 00000000000..db3549b73b1 --- /dev/null +++ b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/factory/InitTest.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.factory; + +import javax.annotation.PostConstruct; + +public class InitTest { + + public static boolean initted = false; + + @PostConstruct + public void init() { + setInitted(true); + } + + public boolean isInitted() { + return initted; + } + + public void setInitted(boolean initted) { + InitTest.initted = initted; + } +} diff --git a/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/factory/ModuleBasedContextFactoryTest.java b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/factory/ModuleBasedContextFactoryTest.java new file mode 100644 index 00000000000..2947615d597 --- /dev/null +++ b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/factory/ModuleBasedContextFactoryTest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.factory; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.Collection; + +import org.apache.cloudstack.spring.module.locator.impl.ClasspathModuleDefinitionLocator; +import org.apache.cloudstack.spring.module.model.ModuleDefinition; +import org.apache.cloudstack.spring.module.model.ModuleDefinitionSet; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.context.ApplicationContext; + +public class ModuleBasedContextFactoryTest { + + Collection defs; + + @Before + public void setUp() throws IOException { + InstantiationCounter.count = 0; + + ClasspathModuleDefinitionLocator locator = new ClasspathModuleDefinitionLocator(); + defs = locator.locateModules("testhierarchy"); + } + + @Test + public void testLoad() throws IOException { + + ModuleBasedContextFactory factory = new ModuleBasedContextFactory(); + + ModuleDefinitionSet set = factory.loadModules(defs, "base"); + + assertNotNull(set.getApplicationContext("base")); + } + + @Test + public void testOverride() throws IOException { + + InitTest.initted = false; + + ModuleBasedContextFactory factory = new ModuleBasedContextFactory(); + + ModuleDefinitionSet set = factory.loadModules(defs, "base"); + + assertTrue(!InitTest.initted); + assertEquals("a string", set.getApplicationContext("child1").getBean("override", String.class)); + } + + @Test + public void testBeans() throws IOException { + ModuleBasedContextFactory factory = new ModuleBasedContextFactory(); + ModuleDefinitionSet set = factory.loadModules(defs, "base"); + + testBeansInContext(set, "base", 1, new String[] { "base" }, new String[] { "child1", "child2", "child1-1" }); + testBeansInContext(set, "child1", 2, new String[] { "base", "child1" }, new String[] { "child2", "child1-1" }); + testBeansInContext(set, "child2", 4, new String[] { "base", "child2" }, new String[] { "child1", "child1-1" }); + testBeansInContext(set, "child1-1", 3, new String[] { "base", "child1", "child1-1" }, new String[] { "child2" }); + } + + protected void testBeansInContext(ModuleDefinitionSet set, String name, int order, String[] parents, String[] notTheres) { + ApplicationContext context = set.getApplicationContext(name); + + String nameBean = context.getBean("name", String.class); + assertEquals(name, nameBean); + + for ( String parent : parents ) { + String parentBean = context.getBean(parent, String.class); + assertEquals(parent, parentBean); + } + + for ( String notThere : notTheres ) { + try { + context.getBean(notThere, String.class); + fail(); + } catch ( NoSuchBeanDefinitionException e ) { + } + } + + int count = context.getBean("count", InstantiationCounter.class).getCount(); + + assertEquals(order, count); + } + + public static class InstantiationCounter { + public static Integer count = 0; + + int myCount; + + public InstantiationCounter() { + synchronized (count) { + myCount = count + 1; + count = myCount; + } + } + + public int getCount() { + return myCount; + } + + } +} diff --git a/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/locator/impl/ClasspathModuleDefinitionSetLocatorTest.java b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/locator/impl/ClasspathModuleDefinitionSetLocatorTest.java new file mode 100644 index 00000000000..5114187b9a5 --- /dev/null +++ b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/locator/impl/ClasspathModuleDefinitionSetLocatorTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.locator.impl; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.Collection; + +import org.apache.cloudstack.spring.module.model.ModuleDefinition; +import org.junit.Test; + +public class ClasspathModuleDefinitionSetLocatorTest { + + @Test + public void testDiscover() throws IOException { + ClasspathModuleDefinitionLocator factory = new ClasspathModuleDefinitionLocator(); + + Collection modules = factory.locateModules("testhierarchy"); + + assertEquals(5, modules.size()); + } + +} diff --git a/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionTest.java b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionTest.java new file mode 100644 index 00000000000..31a82baab20 --- /dev/null +++ b/framework/spring/module/src/test/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionTest.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.spring.module.model.impl; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.apache.cloudstack.spring.module.util.ModuleLocationUtils; +import org.junit.Test; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; + +public class DefaultModuleDefinitionTest { + + ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + + protected DefaultModuleDefinition createDef(String name) { + Resource resource = + resolver.getResource(ModuleLocationUtils.getModuleLocation("testfiles", name)); + + return new DefaultModuleDefinition("testfiles", resource, resolver); + } + + @Test + public void testBlankName() { + DefaultModuleDefinition def = createDef("blankname"); + + try { + def.init(); + fail(); + } catch ( IOException e ) { + assertTrue(e.getMessage().contains("Missing name property")); + } + + } + + @Test + public void testMissingName() { + DefaultModuleDefinition def = createDef("missingname"); + + try { + def.init(); + fail(); + } catch ( IOException e ) { + assertTrue(e.getMessage().contains("Missing name property")); + } + + } + + @Test + public void testBadName() { + DefaultModuleDefinition def = createDef("badname"); + + try { + def.init(); + fail(); + } catch ( IOException e ) { + assertTrue(e.getMessage().contains("is expected to exist at")); + } + } + + @Test + public void testGood() throws IOException { + DefaultModuleDefinition def = createDef("good"); + def.init(); + assertTrue(def.isValid()); + } + + @Test + public void testWrongName() { + DefaultModuleDefinition def = createDef("wrongname"); + + try { + def.init(); + fail(); + } catch ( IOException e ) { + assertTrue(e.getMessage().contains("do not appear to be the same resource")); + } + } + + @Test + public void testAllFiles() throws IOException { + DefaultModuleDefinition def = createDef("all"); + + def.init(); + + assertEquals(2, def.getContextLocations().size()); + has(def.getContextLocations(), "empty-context.xml", "empty2-context.xml"); + + assertEquals(2, def.getConfigLocations().size()); + has(def.getConfigLocations(), "test2-defaults.properties", "defaults.properties"); + + assertEquals(2, def.getInheritableContextLocations().size()); + has(def.getInheritableContextLocations(), "empty-context-inheritable.xml", "empty2-context-inheritable.xml"); + } + + protected void has(List resources, String... files) throws IOException { + int count = 0; + + for ( Resource r : resources ) { + for ( String file : files ) { + if ( r.getURL().toExternalForm().contains(file) ) { + count++; + break; + } + } + } + + assertEquals(resources + " does not contain " + Arrays.toString(files), files.length, count); + } +} diff --git a/framework/spring/module/src/test/resources/testfiles/all/defaults.properties b/framework/spring/module/src/test/resources/testfiles/all/defaults.properties new file mode 100644 index 00000000000..c08d10b386a --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/all/defaults.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +blah=1 diff --git a/framework/spring/module/src/test/resources/testfiles/all/empty-context-inheritable.xml b/framework/spring/module/src/test/resources/testfiles/all/empty-context-inheritable.xml new file mode 100644 index 00000000000..7c6b8fd47b1 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/all/empty-context-inheritable.xml @@ -0,0 +1,26 @@ + + + + diff --git a/framework/spring/module/src/test/resources/testfiles/all/empty-context.xml b/framework/spring/module/src/test/resources/testfiles/all/empty-context.xml new file mode 100644 index 00000000000..7c6b8fd47b1 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/all/empty-context.xml @@ -0,0 +1,26 @@ + + + + diff --git a/framework/spring/module/src/test/resources/testfiles/all/empty2-context-inheritable.xml b/framework/spring/module/src/test/resources/testfiles/all/empty2-context-inheritable.xml new file mode 100644 index 00000000000..7c6b8fd47b1 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/all/empty2-context-inheritable.xml @@ -0,0 +1,26 @@ + + + + diff --git a/framework/spring/module/src/test/resources/testfiles/all/empty2-context.xml b/framework/spring/module/src/test/resources/testfiles/all/empty2-context.xml new file mode 100644 index 00000000000..7c6b8fd47b1 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/all/empty2-context.xml @@ -0,0 +1,26 @@ + + + + diff --git a/framework/spring/module/src/test/resources/testfiles/all/module.properties b/framework/spring/module/src/test/resources/testfiles/all/module.properties new file mode 100644 index 00000000000..3faaf94b5ea --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/all/module.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=all diff --git a/framework/spring/module/src/test/resources/testfiles/all/test2-defaults.properties b/framework/spring/module/src/test/resources/testfiles/all/test2-defaults.properties new file mode 100644 index 00000000000..00ae6c00d2e --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/all/test2-defaults.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + diff --git a/framework/spring/module/src/test/resources/testfiles/badname/module.properties b/framework/spring/module/src/test/resources/testfiles/badname/module.properties new file mode 100644 index 00000000000..354accfa8ab --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/badname/module.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=what diff --git a/framework/spring/module/src/test/resources/testfiles/blankname/module.properties b/framework/spring/module/src/test/resources/testfiles/blankname/module.properties new file mode 100644 index 00000000000..b11279b50c6 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/blankname/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# A bunch of whitespace is after name +name= diff --git a/framework/spring/module/src/test/resources/testfiles/good/empty-context.xml b/framework/spring/module/src/test/resources/testfiles/good/empty-context.xml new file mode 100644 index 00000000000..7c6b8fd47b1 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/good/empty-context.xml @@ -0,0 +1,26 @@ + + + + diff --git a/framework/spring/module/src/test/resources/testfiles/good/module.properties b/framework/spring/module/src/test/resources/testfiles/good/module.properties new file mode 100644 index 00000000000..47e60ec2ce1 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/good/module.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=good diff --git a/framework/spring/module/src/test/resources/testfiles/missingname/module.properties b/framework/spring/module/src/test/resources/testfiles/missingname/module.properties new file mode 100644 index 00000000000..00ae6c00d2e --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/missingname/module.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + diff --git a/framework/spring/module/src/test/resources/testfiles/wrongname/module.properties b/framework/spring/module/src/test/resources/testfiles/wrongname/module.properties new file mode 100644 index 00000000000..47e60ec2ce1 --- /dev/null +++ b/framework/spring/module/src/test/resources/testfiles/wrongname/module.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=good diff --git a/framework/spring/module/src/test/resources/testhierarchy/base/module.properties b/framework/spring/module/src/test/resources/testhierarchy/base/module.properties new file mode 100644 index 00000000000..955a32c2521 --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/base/module.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=base diff --git a/framework/spring/module/src/test/resources/testhierarchy/base/test-context-inheritable.xml b/framework/spring/module/src/test/resources/testhierarchy/base/test-context-inheritable.xml new file mode 100644 index 00000000000..188301e599c --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/base/test-context-inheritable.xml @@ -0,0 +1,28 @@ + + + + + + diff --git a/framework/spring/module/src/test/resources/testhierarchy/base/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/base/test-context.xml new file mode 100644 index 00000000000..a72d8c6128a --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/base/test-context.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1-1/module.properties b/framework/spring/module/src/test/resources/testhierarchy/child1-1/module.properties new file mode 100644 index 00000000000..4abe53f1b94 --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/child1-1/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=child1-1 +parent=child1 diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1-1/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/child1-1/test-context.xml new file mode 100644 index 00000000000..7a2a9ad6d9b --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/child1-1/test-context.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1/module.properties b/framework/spring/module/src/test/resources/testhierarchy/child1/module.properties new file mode 100644 index 00000000000..9f4df489fe3 --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/child1/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=child1 +parent=base diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1/test-context-override.xml b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context-override.xml new file mode 100644 index 00000000000..ceffeb5bfff --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context-override.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context.xml new file mode 100644 index 00000000000..f906183fcc6 --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child2/module.properties b/framework/spring/module/src/test/resources/testhierarchy/child2/module.properties new file mode 100644 index 00000000000..f03edfcc347 --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/child2/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=child2 +parent=base diff --git a/framework/spring/module/src/test/resources/testhierarchy/child2/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/child2/test-context.xml new file mode 100644 index 00000000000..24bac54818d --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/child2/test-context.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + diff --git a/framework/spring/module/src/test/resources/testhierarchy/orphan1/module.properties b/framework/spring/module/src/test/resources/testhierarchy/orphan1/module.properties new file mode 100644 index 00000000000..d4a0e6cce2d --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/orphan1/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=orphan1 +parent=missing1 diff --git a/framework/spring/module/src/test/resources/testhierarchy/orphan1/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/orphan1/test-context.xml new file mode 100644 index 00000000000..658beeae5de --- /dev/null +++ b/framework/spring/module/src/test/resources/testhierarchy/orphan1/test-context.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/module.properties b/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/module.properties new file mode 100644 index 00000000000..28c79d3ac59 --- /dev/null +++ b/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/module.properties @@ -0,0 +1,2 @@ +name=acl-static-role-based +parent=api \ No newline at end of file diff --git a/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml b/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml new file mode 100644 index 00000000000..f13acc190b6 --- /dev/null +++ b/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/affinity-group-processors/explicit-dedication/resources/META-INF/cloudstack/explicit-dedication/module.properties b/plugins/affinity-group-processors/explicit-dedication/resources/META-INF/cloudstack/explicit-dedication/module.properties new file mode 100644 index 00000000000..bd19e527c51 --- /dev/null +++ b/plugins/affinity-group-processors/explicit-dedication/resources/META-INF/cloudstack/explicit-dedication/module.properties @@ -0,0 +1,2 @@ +name=explicit-dedication +parent=planner \ No newline at end of file diff --git a/plugins/affinity-group-processors/explicit-dedication/resources/META-INF/cloudstack/explicit-dedication/spring-explicit-dedication-context.xml b/plugins/affinity-group-processors/explicit-dedication/resources/META-INF/cloudstack/explicit-dedication/spring-explicit-dedication-context.xml new file mode 100644 index 00000000000..5864f947765 --- /dev/null +++ b/plugins/affinity-group-processors/explicit-dedication/resources/META-INF/cloudstack/explicit-dedication/spring-explicit-dedication-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + diff --git a/plugins/affinity-group-processors/host-anti-affinity/resources/META-INF/cloudstack/host-anti-affinity/module.properties b/plugins/affinity-group-processors/host-anti-affinity/resources/META-INF/cloudstack/host-anti-affinity/module.properties new file mode 100644 index 00000000000..80f912d7ee8 --- /dev/null +++ b/plugins/affinity-group-processors/host-anti-affinity/resources/META-INF/cloudstack/host-anti-affinity/module.properties @@ -0,0 +1,2 @@ +name=host-anti-affinity +parent=planner \ No newline at end of file diff --git a/plugins/affinity-group-processors/host-anti-affinity/resources/META-INF/cloudstack/host-anti-affinity/spring-host-anti-affinity-context.xml b/plugins/affinity-group-processors/host-anti-affinity/resources/META-INF/cloudstack/host-anti-affinity/spring-host-anti-affinity-context.xml new file mode 100644 index 00000000000..bc09cc3c60d --- /dev/null +++ b/plugins/affinity-group-processors/host-anti-affinity/resources/META-INF/cloudstack/host-anti-affinity/spring-host-anti-affinity-context.xml @@ -0,0 +1,37 @@ + + + + + + + + + + diff --git a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java index 860240faef0..5be109e533b 100755 --- a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java @@ -16,14 +16,24 @@ // under the License. package org.apache.cloudstack.discovery; -import com.cloud.serializer.Param; -import com.cloud.user.User; -import com.cloud.utils.ReflectUtil; -import com.cloud.utils.StringUtils; -import com.cloud.utils.component.PluggableService; -import com.google.gson.annotations.SerializedName; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ejb.Local; +import javax.inject.Inject; + import org.apache.cloudstack.acl.APIChecker; -import org.apache.cloudstack.api.*; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.command.user.discovery.ListApisCmd; import org.apache.cloudstack.api.response.ApiDiscoveryResponse; import org.apache.cloudstack.api.response.ApiParameterResponse; @@ -32,27 +42,29 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import javax.ejb.Local; -import javax.inject.Inject; -import java.lang.reflect.Field; -import java.util.*; +import com.cloud.serializer.Param; +import com.cloud.user.User; +import com.cloud.utils.ReflectUtil; +import com.cloud.utils.StringUtils; +import com.cloud.utils.component.ComponentLifecycleBase; +import com.cloud.utils.component.PluggableService; +import com.google.gson.annotations.SerializedName; @Component @Local(value = ApiDiscoveryService.class) -public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { +public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements ApiDiscoveryService { private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class); - @Inject protected List _apiAccessCheckers = null; - @Inject protected List _services = null; + List _apiAccessCheckers = null; + List _services = null; private static Map s_apiNameDiscoveryResponseMap = null; protected ApiDiscoveryServiceImpl() { super(); } - @PostConstruct - void init() { + @Override + public boolean start() { if (s_apiNameDiscoveryResponseMap == null) { long startTime = System.nanoTime(); s_apiNameDiscoveryResponseMap = new HashMap(); @@ -66,6 +78,8 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { long endTime = System.nanoTime(); s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); } + + return true; } protected Map> cacheResponseMap(Set> cmdClasses) { @@ -249,4 +263,21 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { cmdList.add(ListApisCmd.class); return cmdList; } + + public List getApiAccessCheckers() { + return _apiAccessCheckers; + } + + public void setApiAccessCheckers(List _apiAccessCheckers) { + this._apiAccessCheckers = _apiAccessCheckers; + } + + public List getServices() { + return _services; + } + + @Inject + public void setServices(List _services) { + this._services = _services; + } } diff --git a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java index afff746c848..a34484becab 100644 --- a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java +++ b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java @@ -65,7 +65,7 @@ public class ApiDiscoveryTest { Set> cmdClasses = new HashSet>(); cmdClasses.add(ListApisCmd.class); - _discoveryService.init(); + _discoveryService.start(); _discoveryService.cacheResponseMap(cmdClasses); } diff --git a/plugins/api/rate-limit/resources/META-INF/cloudstack/rate-limit/module.properties b/plugins/api/rate-limit/resources/META-INF/cloudstack/rate-limit/module.properties new file mode 100644 index 00000000000..4b8fbdbc564 --- /dev/null +++ b/plugins/api/rate-limit/resources/META-INF/cloudstack/rate-limit/module.properties @@ -0,0 +1,2 @@ +name=rate-limit +parent=api \ No newline at end of file diff --git a/plugins/api/rate-limit/resources/META-INF/cloudstack/rate-limit/spring-rate-limit-context.xml b/plugins/api/rate-limit/resources/META-INF/cloudstack/rate-limit/spring-rate-limit-context.xml new file mode 100644 index 00000000000..17153cf1c9d --- /dev/null +++ b/plugins/api/rate-limit/resources/META-INF/cloudstack/rate-limit/spring-rate-limit-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/plugins/dedicated-resources/resources/META-INF/cloudstack/core/spring-dedicated-resources-core-context.xml b/plugins/dedicated-resources/resources/META-INF/cloudstack/core/spring-dedicated-resources-core-context.xml new file mode 100644 index 00000000000..e2879f71086 --- /dev/null +++ b/plugins/dedicated-resources/resources/META-INF/cloudstack/core/spring-dedicated-resources-core-context.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/plugins/deployment-planners/implicit-dedication/resources/META-INF/cloudstack/implicit-dedication/module.properties b/plugins/deployment-planners/implicit-dedication/resources/META-INF/cloudstack/implicit-dedication/module.properties new file mode 100644 index 00000000000..a7dc4581cdd --- /dev/null +++ b/plugins/deployment-planners/implicit-dedication/resources/META-INF/cloudstack/implicit-dedication/module.properties @@ -0,0 +1,2 @@ +name=implicit-dedication +parent=planner \ No newline at end of file diff --git a/plugins/deployment-planners/implicit-dedication/resources/META-INF/cloudstack/implicit-dedication/spring-implicit-dedication-context.xml b/plugins/deployment-planners/implicit-dedication/resources/META-INF/cloudstack/implicit-dedication/spring-implicit-dedication-context.xml new file mode 100644 index 00000000000..d14b4502ab9 --- /dev/null +++ b/plugins/deployment-planners/implicit-dedication/resources/META-INF/cloudstack/implicit-dedication/spring-implicit-dedication-context.xml @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/plugins/deployment-planners/user-concentrated-pod/resources/META-INF/cloudstack/user-concentrated-pod/module.properties b/plugins/deployment-planners/user-concentrated-pod/resources/META-INF/cloudstack/user-concentrated-pod/module.properties new file mode 100644 index 00000000000..f685b9c9af0 --- /dev/null +++ b/plugins/deployment-planners/user-concentrated-pod/resources/META-INF/cloudstack/user-concentrated-pod/module.properties @@ -0,0 +1,2 @@ +name=user-concentrated-pod +parent=planner \ No newline at end of file diff --git a/plugins/deployment-planners/user-concentrated-pod/resources/META-INF/cloudstack/user-concentrated-pod/spring-user-concentrated-pod-context.xml b/plugins/deployment-planners/user-concentrated-pod/resources/META-INF/cloudstack/user-concentrated-pod/spring-user-concentrated-pod-context.xml new file mode 100644 index 00000000000..e26cb2be57e --- /dev/null +++ b/plugins/deployment-planners/user-concentrated-pod/resources/META-INF/cloudstack/user-concentrated-pod/spring-user-concentrated-pod-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/plugins/host-allocators/random/resources/META-INF/cloudstack/host-allocator-random/module.properties b/plugins/host-allocators/random/resources/META-INF/cloudstack/host-allocator-random/module.properties new file mode 100644 index 00000000000..95231f5799b --- /dev/null +++ b/plugins/host-allocators/random/resources/META-INF/cloudstack/host-allocator-random/module.properties @@ -0,0 +1,2 @@ +name=host-allocator-random +parent=allocator \ No newline at end of file diff --git a/plugins/host-allocators/random/resources/META-INF/cloudstack/host-allocator-random/spring-host-allocator-random-context.xml b/plugins/host-allocators/random/resources/META-INF/cloudstack/host-allocator-random/spring-host-allocator-random-context.xml new file mode 100644 index 00000000000..8df1bdb97cc --- /dev/null +++ b/plugins/host-allocators/random/resources/META-INF/cloudstack/host-allocator-random/spring-host-allocator-random-context.xml @@ -0,0 +1,34 @@ + + + + + + + diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-compute/module.properties b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-compute/module.properties new file mode 100644 index 00000000000..2cbce1c60d2 --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-compute/module.properties @@ -0,0 +1,2 @@ +name=baremetal-compute +parent=compute \ No newline at end of file diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-compute/spring-baremetal-compute-context.xml b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-compute/spring-baremetal-compute-context.xml new file mode 100644 index 00000000000..cce68051239 --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-compute/spring-baremetal-compute-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-discoverer/module.properties b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-discoverer/module.properties new file mode 100644 index 00000000000..049ed5111ce --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-discoverer/module.properties @@ -0,0 +1,2 @@ +name=baremetal-discoverer +parent=discoverer \ No newline at end of file diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-discoverer/spring-baremetal-discoverer-context.xml b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-discoverer/spring-baremetal-discoverer-context.xml new file mode 100644 index 00000000000..8792909ffed --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-discoverer/spring-baremetal-discoverer-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-network/module.properties b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-network/module.properties new file mode 100644 index 00000000000..1de6da33477 --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-network/module.properties @@ -0,0 +1,2 @@ +name=baremetal-network +parent=network \ No newline at end of file diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-network/spring-baremetal-network-context.xml b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-network/spring-baremetal-network-context.xml new file mode 100644 index 00000000000..40d9f505775 --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-network/spring-baremetal-network-context.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-planner/module.properties b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-planner/module.properties new file mode 100644 index 00000000000..2dc88f76f54 --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-planner/module.properties @@ -0,0 +1,2 @@ +name=baremetal-planner +parent=planner \ No newline at end of file diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-planner/spring-baremetal-planner-context.xml b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-planner/spring-baremetal-planner-context.xml new file mode 100644 index 00000000000..8c14c3e2903 --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-planner/spring-baremetal-planner-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-storage/module.properties b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-storage/module.properties new file mode 100644 index 00000000000..b22bc8e90e6 --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-storage/module.properties @@ -0,0 +1,2 @@ +name=baremetal-storage +parent=storage \ No newline at end of file diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-storage/spring-baremetal-storage-context.xml b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-storage/spring-baremetal-storage-context.xml new file mode 100644 index 00000000000..e0a9e36ef7d --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/baremetal-storage/spring-baremetal-storage-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/core/spring-baremetal-core-context.xml b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/core/spring-baremetal-core-context.xml new file mode 100644 index 00000000000..11cc6c89e3f --- /dev/null +++ b/plugins/hypervisors/baremetal/resources/META-INF/cloudstack/core/spring-baremetal-core-context.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + diff --git a/plugins/hypervisors/kvm/resources/META-INF/cloudstack/kvm-compute/module.properties b/plugins/hypervisors/kvm/resources/META-INF/cloudstack/kvm-compute/module.properties new file mode 100644 index 00000000000..43587c60fcf --- /dev/null +++ b/plugins/hypervisors/kvm/resources/META-INF/cloudstack/kvm-compute/module.properties @@ -0,0 +1,2 @@ +name=kvm-compute +parent=compute \ No newline at end of file diff --git a/plugins/hypervisors/kvm/resources/META-INF/cloudstack/kvm-compute/spring-kvm-compute-context.xml b/plugins/hypervisors/kvm/resources/META-INF/cloudstack/kvm-compute/spring-kvm-compute-context.xml new file mode 100644 index 00000000000..ce596f22bbf --- /dev/null +++ b/plugins/hypervisors/kvm/resources/META-INF/cloudstack/kvm-compute/spring-kvm-compute-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-compute/module.properties b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-compute/module.properties new file mode 100644 index 00000000000..6a74b523850 --- /dev/null +++ b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-compute/module.properties @@ -0,0 +1,2 @@ +name=ovm-compute +parent=compute \ No newline at end of file diff --git a/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-compute/spring-ovm-compute-context.xml b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-compute/spring-ovm-compute-context.xml new file mode 100644 index 00000000000..b12672a6a45 --- /dev/null +++ b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-compute/spring-ovm-compute-context.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + diff --git a/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-discoverer/module.properties b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-discoverer/module.properties new file mode 100644 index 00000000000..ce2fcbc6e0a --- /dev/null +++ b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-discoverer/module.properties @@ -0,0 +1,2 @@ +name=ovm-discoverer +parent=discoverer \ No newline at end of file diff --git a/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-discoverer/spring-ovm-discoverer-context.xml b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-discoverer/spring-ovm-discoverer-context.xml new file mode 100644 index 00000000000..b0f2a15519f --- /dev/null +++ b/plugins/hypervisors/ovm/resources/META-INF/cloudstack/ovm-discoverer/spring-ovm-discoverer-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/core/spring-simulator-core-context.xml b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/core/spring-simulator-core-context.xml new file mode 100644 index 00000000000..4905ae80b8f --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/core/spring-simulator-core-context.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-compute/module.properties b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-compute/module.properties new file mode 100644 index 00000000000..6a51de9570b --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-compute/module.properties @@ -0,0 +1,2 @@ +name=simulator-compute +parent=compute \ No newline at end of file diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-compute/spring-simulator-compute-context.xml b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-compute/spring-simulator-compute-context.xml new file mode 100644 index 00000000000..11462333d0e --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-compute/spring-simulator-compute-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-discoverer/module.properties b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-discoverer/module.properties new file mode 100644 index 00000000000..060d9da1a8a --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-discoverer/module.properties @@ -0,0 +1,2 @@ +name=simulator-discoverer +parent=discoverer \ No newline at end of file diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-discoverer/spring-simulator-discover-context.xml b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-discoverer/spring-simulator-discover-context.xml new file mode 100644 index 00000000000..323f64fdac7 --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-discoverer/spring-simulator-discover-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-planner/module.properties b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-planner/module.properties new file mode 100644 index 00000000000..e1f6e19e2fb --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-planner/module.properties @@ -0,0 +1,2 @@ +name=simulator-planner +parent=planner \ No newline at end of file diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-planner/spring-context.xml b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-planner/spring-context.xml new file mode 100644 index 00000000000..8c14c3e2903 --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-planner/spring-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-storage/module.properties b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-storage/module.properties new file mode 100644 index 00000000000..f804b877091 --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-storage/module.properties @@ -0,0 +1,2 @@ +name=simulator-storage +parent=storage \ No newline at end of file diff --git a/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-storage/spring-simulator-storage-context.xml b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-storage/spring-simulator-storage-context.xml new file mode 100644 index 00000000000..4cb73e60bae --- /dev/null +++ b/plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-storage/spring-simulator-storage-context.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java index fcc1b4f2209..4075c87f5bb 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java +++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java @@ -16,6 +16,26 @@ // under the License. package com.cloud.agent.manager; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.regex.PatternSyntaxException; + +import javax.ejb.Local; +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.storage.resource.SecondaryStorageDiscoverer; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckHealthCommand; @@ -31,7 +51,12 @@ import com.cloud.dc.dao.HostPodDao; import com.cloud.exception.DiscoveryException; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; -import com.cloud.resource.*; +import com.cloud.resource.AgentResourceBase; +import com.cloud.resource.AgentRoutingResource; +import com.cloud.resource.AgentStorageResource; +import com.cloud.resource.Discoverer; +import com.cloud.resource.ResourceManager; +import com.cloud.resource.SimulatorSecondaryDiscoverer; import com.cloud.simulator.MockHost; import com.cloud.simulator.MockHostVO; import com.cloud.simulator.MockVMVO; @@ -44,24 +69,6 @@ import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; -import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.regex.PatternSyntaxException; @Component @Local(value = { MockAgentManager.class }) @@ -81,10 +88,13 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage MockStorageManager _storageMgr = null; @Inject ResourceManager _resourceMgr; - @Inject + SimulatorSecondaryDiscoverer discoverer; @Inject HostDao hostDao; + + List discoverers; + private SecureRandom random; private final Map _resources = new ConcurrentHashMap(); private ThreadPoolExecutor _executor; @@ -452,6 +462,17 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage @Override public boolean start() { + for ( Discoverer discoverer : discoverers ) { + if ( discoverer instanceof SimulatorSecondaryDiscoverer ) { + this.discoverer = (SimulatorSecondaryDiscoverer)discoverer; + break; + } + } + + if ( this.discoverer == null ) { + throw new IllegalStateException("Failed to find SimulatorSecondaryDiscoverer"); + } + return true; } @@ -477,4 +498,13 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage } return new CheckNetworkAnswer(cmd, true, "Network Setup check by names is done"); } + + public List getDiscoverers() { + return discoverers; + } + + @Inject + public void setDiscoverers(List discoverers) { + this.discoverers = discoverers; + } } diff --git a/plugins/hypervisors/ucs/resources/META-INF/cloudstack/core/spring-ucs-core-context.xml b/plugins/hypervisors/ucs/resources/META-INF/cloudstack/core/spring-ucs-core-context.xml new file mode 100644 index 00000000000..47732f46092 --- /dev/null +++ b/plugins/hypervisors/ucs/resources/META-INF/cloudstack/core/spring-ucs-core-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/core/spring-vmware-core-context.xml b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/core/spring-vmware-core-context.xml new file mode 100644 index 00000000000..406ffe16b4e --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/core/spring-vmware-core-context.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/module.properties b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/module.properties new file mode 100644 index 00000000000..88bab99d012 --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/module.properties @@ -0,0 +1,2 @@ +name=vmware-compute +parent=compute \ No newline at end of file diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/spring-vmware-compute-context.xml b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/spring-vmware-compute-context.xml new file mode 100644 index 00000000000..402640db8fe --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/spring-vmware-compute-context.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/vmware-defaults.properties b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/vmware-defaults.properties new file mode 100644 index 00000000000..5c7ebe2f2ea --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-compute/vmware-defaults.properties @@ -0,0 +1 @@ +premium=true \ No newline at end of file diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-discoverer/module.properties b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-discoverer/module.properties new file mode 100644 index 00000000000..463e8b81785 --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-discoverer/module.properties @@ -0,0 +1,2 @@ +name=vmware-discoverer +parent=discoverer \ No newline at end of file diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-discoverer/spring-vmware-discoverer-context.xml b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-discoverer/spring-vmware-discoverer-context.xml new file mode 100644 index 00000000000..933f0e8a723 --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-discoverer/spring-vmware-discoverer-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-network/module.properties b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-network/module.properties new file mode 100644 index 00000000000..12573df4aa8 --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-network/module.properties @@ -0,0 +1,2 @@ +name=vmware-network +parent=network \ No newline at end of file diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-network/spring-vmware-network-context.xml b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-network/spring-vmware-network-context.xml new file mode 100644 index 00000000000..440356b3f53 --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-network/spring-vmware-network-context.xml @@ -0,0 +1,34 @@ + + + + + + + + \ No newline at end of file diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-storage/module.properties b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-storage/module.properties new file mode 100644 index 00000000000..70d5eeb19fa --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-storage/module.properties @@ -0,0 +1,2 @@ +name=vmware-storage +parent=storage \ No newline at end of file diff --git a/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-storage/spring-vmware-storage-context.xml b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-storage/spring-vmware-storage-context.xml new file mode 100644 index 00000000000..bb428bfbdeb --- /dev/null +++ b/plugins/hypervisors/vmware/resources/META-INF/cloudstack/vmware-storage/spring-vmware-storage-context.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java index fd7b3b48795..58255bf2e58 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java @@ -60,10 +60,12 @@ import com.cloud.hypervisor.vmware.resource.VmwareResource; import com.cloud.hypervisor.vmware.util.VmwareContext; import com.cloud.network.NetworkModel; import com.cloud.network.Networks.TrafficType; +import com.cloud.network.Network; import com.cloud.network.PhysicalNetwork; import com.cloud.network.VmwareTrafficLabel; import com.cloud.network.dao.CiscoNexusVSMDeviceDao; import com.cloud.network.element.CiscoNexusVSMElement; +import com.cloud.network.element.NetworkElement; import com.cloud.resource.Discoverer; import com.cloud.resource.DiscovererBase; import com.cloud.resource.ResourceManager; @@ -105,8 +107,8 @@ public class VmwareServerDiscoverer extends DiscovererBase implements ResourceManager _resourceMgr; @Inject CiscoNexusVSMDeviceDao _nexusDao; - @Inject CiscoNexusVSMElement _nexusElement; + List networkElements; @Inject NetworkModel _netmgr; @Inject @@ -450,6 +452,15 @@ public class VmwareServerDiscoverer extends DiscovererBase implements } } } + + protected CiscoNexusVSMElement getCiscoNexusVSMElement() { + for ( NetworkElement networkElement : networkElements ) { + if ( networkElement instanceof CiscoNexusVSMElement ) + return (CiscoNexusVSMElement)networkElement; + } + + throw new IllegalStateException("Failed to CiscoNexusVSMElement"); + } private VmwareDatacenterVO fetchVmwareDatacenterByZone(Long dcId) throws DiscoveryException { VmwareDatacenterVO vmwareDc; @@ -640,6 +651,16 @@ public class VmwareServerDiscoverer extends DiscovererBase implements } + @Override + public boolean start() { + if ( ! super.start() ) + return false; + + _nexusElement = getCiscoNexusVSMElement(); + + return true; + } + @Override public boolean stop() { _resourceMgr.unregisterResourceStateAdapter(this.getClass() @@ -791,4 +812,14 @@ public class VmwareServerDiscoverer extends DiscovererBase implements } _urlParams.putAll(params); } + + public List getNetworkElements() { + return networkElements; + } + + @Inject + public void setNetworkElements(List networkElements) { + this.networkElements = networkElements; + } + } diff --git a/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-compute/module.properties b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-compute/module.properties new file mode 100644 index 00000000000..9dca6f45863 --- /dev/null +++ b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-compute/module.properties @@ -0,0 +1,2 @@ +name=xenserver-compute +parent=compute \ No newline at end of file diff --git a/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-compute/spring-xenserver-compute-context.xml b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-compute/spring-xenserver-compute-context.xml new file mode 100644 index 00000000000..e024ad837c8 --- /dev/null +++ b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-compute/spring-xenserver-compute-context.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + diff --git a/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-discoverer/module.properties b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-discoverer/module.properties new file mode 100644 index 00000000000..82f40ae7cfa --- /dev/null +++ b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-discoverer/module.properties @@ -0,0 +1,2 @@ +name=xenserver-discoverer +parent=discoverer \ No newline at end of file diff --git a/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-discoverer/spring-xenserver-discoverer-context.xml b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-discoverer/spring-xenserver-discoverer-context.xml new file mode 100644 index 00000000000..c3010072dfe --- /dev/null +++ b/plugins/hypervisors/xen/resources/META-INF/cloudstack/xenserver-discoverer/spring-xenserver-discoverer-context.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/plugins/network-elements/bigswitch-vns/resources/META-INF/cloudstack/vns/module.properties b/plugins/network-elements/bigswitch-vns/resources/META-INF/cloudstack/vns/module.properties new file mode 100644 index 00000000000..f0af863000a --- /dev/null +++ b/plugins/network-elements/bigswitch-vns/resources/META-INF/cloudstack/vns/module.properties @@ -0,0 +1,2 @@ +name=vns +parent=network \ No newline at end of file diff --git a/plugins/network-elements/bigswitch-vns/resources/META-INF/cloudstack/vns/spring-vns-context.xml b/plugins/network-elements/bigswitch-vns/resources/META-INF/cloudstack/vns/spring-vns-context.xml new file mode 100644 index 00000000000..d5bb92afe3d --- /dev/null +++ b/plugins/network-elements/bigswitch-vns/resources/META-INF/cloudstack/vns/spring-vns-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/plugins/network-elements/elastic-loadbalancer/resources/META-INF/cloudstack/elb/module.properties b/plugins/network-elements/elastic-loadbalancer/resources/META-INF/cloudstack/elb/module.properties new file mode 100644 index 00000000000..afaf712fde0 --- /dev/null +++ b/plugins/network-elements/elastic-loadbalancer/resources/META-INF/cloudstack/elb/module.properties @@ -0,0 +1,2 @@ +name=elb +parent=network \ No newline at end of file diff --git a/plugins/network-elements/elastic-loadbalancer/resources/META-INF/cloudstack/elb/spring-elb-context.xml b/plugins/network-elements/elastic-loadbalancer/resources/META-INF/cloudstack/elb/spring-elb-context.xml new file mode 100644 index 00000000000..247153c4558 --- /dev/null +++ b/plugins/network-elements/elastic-loadbalancer/resources/META-INF/cloudstack/elb/spring-elb-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/network-elements/internal-loadbalancer/resources/META-INF/cloudstack/core/spring-internallb-core-context.xml b/plugins/network-elements/internal-loadbalancer/resources/META-INF/cloudstack/core/spring-internallb-core-context.xml new file mode 100644 index 00000000000..c03887931b8 --- /dev/null +++ b/plugins/network-elements/internal-loadbalancer/resources/META-INF/cloudstack/core/spring-internallb-core-context.xml @@ -0,0 +1,37 @@ + + + + + + + + + + diff --git a/plugins/network-elements/midonet/resources/META-INF/cloudstack/midonet/module.properties b/plugins/network-elements/midonet/resources/META-INF/cloudstack/midonet/module.properties new file mode 100644 index 00000000000..e5ecdddbb86 --- /dev/null +++ b/plugins/network-elements/midonet/resources/META-INF/cloudstack/midonet/module.properties @@ -0,0 +1,2 @@ +name=midonet +parent=network \ No newline at end of file diff --git a/plugins/network-elements/midonet/resources/META-INF/cloudstack/midonet/spring-midonet-context.xml b/plugins/network-elements/midonet/resources/META-INF/cloudstack/midonet/spring-midonet-context.xml new file mode 100644 index 00000000000..400f7dd6ed6 --- /dev/null +++ b/plugins/network-elements/midonet/resources/META-INF/cloudstack/midonet/spring-midonet-context.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + diff --git a/plugins/network-elements/nicira-nvp/resources/META-INF/cloudstack/nvp/module.properties b/plugins/network-elements/nicira-nvp/resources/META-INF/cloudstack/nvp/module.properties new file mode 100644 index 00000000000..98338c4626d --- /dev/null +++ b/plugins/network-elements/nicira-nvp/resources/META-INF/cloudstack/nvp/module.properties @@ -0,0 +1,2 @@ +name=nvp +parent=network \ No newline at end of file diff --git a/plugins/network-elements/nicira-nvp/resources/META-INF/cloudstack/nvp/spring-nvp-context.xml b/plugins/network-elements/nicira-nvp/resources/META-INF/cloudstack/nvp/spring-nvp-context.xml new file mode 100644 index 00000000000..302b072c8d0 --- /dev/null +++ b/plugins/network-elements/nicira-nvp/resources/META-INF/cloudstack/nvp/spring-nvp-context.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + diff --git a/plugins/network-elements/ovs/resources/META-INF/cloudstack/ovs/module.properties b/plugins/network-elements/ovs/resources/META-INF/cloudstack/ovs/module.properties new file mode 100644 index 00000000000..dac33c60012 --- /dev/null +++ b/plugins/network-elements/ovs/resources/META-INF/cloudstack/ovs/module.properties @@ -0,0 +1,2 @@ +name=ovs +parent=network diff --git a/plugins/network-elements/ovs/resources/META-INF/cloudstack/ovs/spring-ovs-context.xml b/plugins/network-elements/ovs/resources/META-INF/cloudstack/ovs/spring-ovs-context.xml new file mode 100644 index 00000000000..9180eebd040 --- /dev/null +++ b/plugins/network-elements/ovs/resources/META-INF/cloudstack/ovs/spring-ovs-context.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + diff --git a/plugins/network-elements/stratosphere-ssp/resources/META-INF/cloudstack/ssp/module.properties b/plugins/network-elements/stratosphere-ssp/resources/META-INF/cloudstack/ssp/module.properties new file mode 100644 index 00000000000..2fdde5463df --- /dev/null +++ b/plugins/network-elements/stratosphere-ssp/resources/META-INF/cloudstack/ssp/module.properties @@ -0,0 +1,2 @@ +name=ssp +parent=network \ No newline at end of file diff --git a/plugins/network-elements/stratosphere-ssp/resources/META-INF/cloudstack/ssp/spring-ssp-context.xml b/plugins/network-elements/stratosphere-ssp/resources/META-INF/cloudstack/ssp/spring-ssp-context.xml new file mode 100644 index 00000000000..528f3e3e38c --- /dev/null +++ b/plugins/network-elements/stratosphere-ssp/resources/META-INF/cloudstack/ssp/spring-ssp-context.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + diff --git a/plugins/network-elements/vxlan/resources/META-INF/cloudstack/vxlan/module.properties b/plugins/network-elements/vxlan/resources/META-INF/cloudstack/vxlan/module.properties new file mode 100644 index 00000000000..69ce71682b2 --- /dev/null +++ b/plugins/network-elements/vxlan/resources/META-INF/cloudstack/vxlan/module.properties @@ -0,0 +1,2 @@ +name=vxlan +parent=network \ No newline at end of file diff --git a/plugins/network-elements/vxlan/resources/META-INF/cloudstack/vxlan/spring-vxlan-context.xml b/plugins/network-elements/vxlan/resources/META-INF/cloudstack/vxlan/spring-vxlan-context.xml new file mode 100644 index 00000000000..fcf0b0189eb --- /dev/null +++ b/plugins/network-elements/vxlan/resources/META-INF/cloudstack/vxlan/spring-vxlan-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/storage/image/default/resources/META-INF/cloudstack/storage-image-default/module.properties b/plugins/storage/image/default/resources/META-INF/cloudstack/storage-image-default/module.properties new file mode 100644 index 00000000000..a1706984693 --- /dev/null +++ b/plugins/storage/image/default/resources/META-INF/cloudstack/storage-image-default/module.properties @@ -0,0 +1,2 @@ +name=storage-image-default +parent=storage \ No newline at end of file diff --git a/plugins/storage/image/default/resources/META-INF/cloudstack/storage-image-default/spring-storage-image-default-context.xml b/plugins/storage/image/default/resources/META-INF/cloudstack/storage-image-default/spring-storage-image-default-context.xml new file mode 100644 index 00000000000..6d3c63c2772 --- /dev/null +++ b/plugins/storage/image/default/resources/META-INF/cloudstack/storage-image-default/spring-storage-image-default-context.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/plugins/storage/image/s3/resources/META-INF/cloudstack/storage-image-s3/module.properties b/plugins/storage/image/s3/resources/META-INF/cloudstack/storage-image-s3/module.properties new file mode 100644 index 00000000000..e3bc333a0e3 --- /dev/null +++ b/plugins/storage/image/s3/resources/META-INF/cloudstack/storage-image-s3/module.properties @@ -0,0 +1,2 @@ +name=storage-image-s3 +parent=storage \ No newline at end of file diff --git a/plugins/storage/image/s3/resources/META-INF/cloudstack/storage-image-s3/spring-storage-image-s3-context.xml b/plugins/storage/image/s3/resources/META-INF/cloudstack/storage-image-s3/spring-storage-image-s3-context.xml new file mode 100644 index 00000000000..610506340a8 --- /dev/null +++ b/plugins/storage/image/s3/resources/META-INF/cloudstack/storage-image-s3/spring-storage-image-s3-context.xml @@ -0,0 +1,34 @@ + + + + + + + diff --git a/plugins/storage/image/swift/resources/META-INF/cloudstack/storage-image-swift/module.properties b/plugins/storage/image/swift/resources/META-INF/cloudstack/storage-image-swift/module.properties new file mode 100644 index 00000000000..c232a632fc7 --- /dev/null +++ b/plugins/storage/image/swift/resources/META-INF/cloudstack/storage-image-swift/module.properties @@ -0,0 +1,2 @@ +name=storage-image-swift +parent=storage \ No newline at end of file diff --git a/plugins/storage/image/swift/resources/META-INF/cloudstack/storage-image-swift/spring-storage-image-swift-context.xml b/plugins/storage/image/swift/resources/META-INF/cloudstack/storage-image-swift/spring-storage-image-swift-context.xml new file mode 100644 index 00000000000..5e986e88360 --- /dev/null +++ b/plugins/storage/image/swift/resources/META-INF/cloudstack/storage-image-swift/spring-storage-image-swift-context.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/plugins/storage/volume/default/resources/META-INF/cloudstack/storage-volume-default/module.properties b/plugins/storage/volume/default/resources/META-INF/cloudstack/storage-volume-default/module.properties new file mode 100644 index 00000000000..84405eddf53 --- /dev/null +++ b/plugins/storage/volume/default/resources/META-INF/cloudstack/storage-volume-default/module.properties @@ -0,0 +1,2 @@ +name=storage-volume-default +parent=storage \ No newline at end of file diff --git a/plugins/storage/volume/default/resources/META-INF/cloudstack/storage-volume-default/spring-storage-volume-default-context.xml b/plugins/storage/volume/default/resources/META-INF/cloudstack/storage-volume-default/spring-storage-volume-default-context.xml new file mode 100644 index 00000000000..8b50455315d --- /dev/null +++ b/plugins/storage/volume/default/resources/META-INF/cloudstack/storage-volume-default/spring-storage-volume-default-context.xml @@ -0,0 +1,35 @@ + + + + + + + + diff --git a/plugins/storage/volume/solidfire/resources/META-INF/cloudstack/storage-volume-solidfire/module.properties b/plugins/storage/volume/solidfire/resources/META-INF/cloudstack/storage-volume-solidfire/module.properties new file mode 100644 index 00000000000..7d3fadc28a8 --- /dev/null +++ b/plugins/storage/volume/solidfire/resources/META-INF/cloudstack/storage-volume-solidfire/module.properties @@ -0,0 +1,2 @@ +name=storage-volume-solidfire +parent=storage \ No newline at end of file diff --git a/plugins/storage/volume/solidfire/resources/META-INF/cloudstack/storage-volume-solidfire/spring-storage-volume-solidfire-context.xml b/plugins/storage/volume/solidfire/resources/META-INF/cloudstack/storage-volume-solidfire/spring-storage-volume-solidfire-context.xml new file mode 100644 index 00000000000..a83e3cab7e3 --- /dev/null +++ b/plugins/storage/volume/solidfire/resources/META-INF/cloudstack/storage-volume-solidfire/spring-storage-volume-solidfire-context.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/module.properties b/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/module.properties new file mode 100644 index 00000000000..b8227cee8fd --- /dev/null +++ b/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/module.properties @@ -0,0 +1,2 @@ +name=ldap +parent=api \ No newline at end of file diff --git a/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/spring-ldap-context.xml b/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/spring-ldap-context.xml new file mode 100644 index 00000000000..34a2befe971 --- /dev/null +++ b/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/spring-ldap-context.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + diff --git a/plugins/user-authenticators/md5/resources/META-INF/cloudstack/md5/module.properties b/plugins/user-authenticators/md5/resources/META-INF/cloudstack/md5/module.properties new file mode 100644 index 00000000000..97b5b3e3cac --- /dev/null +++ b/plugins/user-authenticators/md5/resources/META-INF/cloudstack/md5/module.properties @@ -0,0 +1,2 @@ +name=md5 +parent=api \ No newline at end of file diff --git a/plugins/user-authenticators/md5/resources/META-INF/cloudstack/md5/spring-md5-context.xml b/plugins/user-authenticators/md5/resources/META-INF/cloudstack/md5/spring-md5-context.xml new file mode 100644 index 00000000000..4a8e64dd864 --- /dev/null +++ b/plugins/user-authenticators/md5/resources/META-INF/cloudstack/md5/spring-md5-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/plugins/user-authenticators/plain-text/resources/META-INF/cloudstack/plaintext/module.properties b/plugins/user-authenticators/plain-text/resources/META-INF/cloudstack/plaintext/module.properties new file mode 100644 index 00000000000..34a00a4de87 --- /dev/null +++ b/plugins/user-authenticators/plain-text/resources/META-INF/cloudstack/plaintext/module.properties @@ -0,0 +1,2 @@ +name=plaintext +parent=api \ No newline at end of file diff --git a/plugins/user-authenticators/plain-text/resources/META-INF/cloudstack/plaintext/spring-plaintext-context.xml b/plugins/user-authenticators/plain-text/resources/META-INF/cloudstack/plaintext/spring-plaintext-context.xml new file mode 100644 index 00000000000..639411a1086 --- /dev/null +++ b/plugins/user-authenticators/plain-text/resources/META-INF/cloudstack/plaintext/spring-plaintext-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/plugins/user-authenticators/sha256salted/resources/META-INF/cloudstack/sha256salted/module.properties b/plugins/user-authenticators/sha256salted/resources/META-INF/cloudstack/sha256salted/module.properties new file mode 100644 index 00000000000..4431a3d8ff9 --- /dev/null +++ b/plugins/user-authenticators/sha256salted/resources/META-INF/cloudstack/sha256salted/module.properties @@ -0,0 +1,2 @@ +name=sha256salted +parent=api \ No newline at end of file diff --git a/plugins/user-authenticators/sha256salted/resources/META-INF/cloudstack/sha256salted/spring-sha256salted-context.xml b/plugins/user-authenticators/sha256salted/resources/META-INF/cloudstack/sha256salted/spring-sha256salted-context.xml new file mode 100644 index 00000000000..e379718549e --- /dev/null +++ b/plugins/user-authenticators/sha256salted/resources/META-INF/cloudstack/sha256salted/spring-sha256salted-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/quickcloud/pom.xml b/quickcloud/pom.xml new file mode 100644 index 00000000000..1b9975e8e42 --- /dev/null +++ b/quickcloud/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + cloud-quickcloud + Apache CloudStack Framework - QuickCloud + + org.apache.cloudstack + cloud-maven-standard + 4.3.0-SNAPSHOT + ../maven-standard/pom.xml + + diff --git a/quickcloud/src/main/resources/META-INF/cloudstack/core/spring-quickcloud-core-context-override.xml b/quickcloud/src/main/resources/META-INF/cloudstack/core/spring-quickcloud-core-context-override.xml new file mode 100644 index 00000000000..35e4cbe54e1 --- /dev/null +++ b/quickcloud/src/main/resources/META-INF/cloudstack/core/spring-quickcloud-core-context-override.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml new file mode 100644 index 00000000000..11b69d213ad --- /dev/null +++ b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml new file mode 100644 index 00000000000..fd2f5fbb3fd --- /dev/null +++ b/server/resources/META-INF/cloudstack/core/spring-server-core-misc-context.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-alert-adapter-backend/module.properties b/server/resources/META-INF/cloudstack/server-alert-adapter-backend/module.properties new file mode 100644 index 00000000000..37176f957c8 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-alert-adapter-backend/module.properties @@ -0,0 +1,2 @@ +name=server-alert-adapter-backend +parent=backend \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-alert-adapter-backend/spring-server-alert-adapter-backend-context.xml b/server/resources/META-INF/cloudstack/server-alert-adapter-backend/spring-server-alert-adapter-backend-context.xml new file mode 100644 index 00000000000..f7670e5810b --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-alert-adapter-backend/spring-server-alert-adapter-backend-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-alert-adapter-compute/module.properties b/server/resources/META-INF/cloudstack/server-alert-adapter-compute/module.properties new file mode 100644 index 00000000000..ae39622309a --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-alert-adapter-compute/module.properties @@ -0,0 +1,2 @@ +name=server-alert-adapter-compute +parent=compute \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-alert-adapter-compute/spring-server-alert-adapter-compute-context.xml b/server/resources/META-INF/cloudstack/server-alert-adapter-compute/spring-server-alert-adapter-compute-context.xml new file mode 100644 index 00000000000..e918ce08e40 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-alert-adapter-compute/spring-server-alert-adapter-compute-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-alert-adapter-storage/module.properties b/server/resources/META-INF/cloudstack/server-alert-adapter-storage/module.properties new file mode 100644 index 00000000000..1175d81648b --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-alert-adapter-storage/module.properties @@ -0,0 +1,2 @@ +name=server-alert-adapter-storage +parent=storage \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-alert-adapter-storage/spring-server-alert-adapter-storage-context.xml b/server/resources/META-INF/cloudstack/server-alert-adapter-storage/spring-server-alert-adapter-storage-context.xml new file mode 100644 index 00000000000..713d9e363cc --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-alert-adapter-storage/spring-server-alert-adapter-storage-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-allocator/module.properties b/server/resources/META-INF/cloudstack/server-allocator/module.properties new file mode 100644 index 00000000000..11a66de118e --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-allocator/module.properties @@ -0,0 +1,2 @@ +name=server-allocator +parent=allocator \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-allocator/spring-server-allocator-context.xml b/server/resources/META-INF/cloudstack/server-allocator/spring-server-allocator-context.xml new file mode 100644 index 00000000000..cc2924e5e02 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-allocator/spring-server-allocator-context.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-api/module.properties b/server/resources/META-INF/cloudstack/server-api/module.properties new file mode 100644 index 00000000000..202dd5d3104 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-api/module.properties @@ -0,0 +1,2 @@ +name=server-api +parent=api \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-api/spring-server-api-context.xml b/server/resources/META-INF/cloudstack/server-api/spring-server-api-context.xml new file mode 100644 index 00000000000..20e2f460933 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-api/spring-server-api-context.xml @@ -0,0 +1,33 @@ + + + + + + + \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-compute/module.properties b/server/resources/META-INF/cloudstack/server-compute/module.properties new file mode 100644 index 00000000000..6d6737ad9cc --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-compute/module.properties @@ -0,0 +1,2 @@ +name=server-compute +parent=compute \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-compute/spring-server-compute-context.xml b/server/resources/META-INF/cloudstack/server-compute/spring-server-compute-context.xml new file mode 100644 index 00000000000..1311902ff5d --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-compute/spring-server-compute-context.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-discoverer/module.properties b/server/resources/META-INF/cloudstack/server-discoverer/module.properties new file mode 100644 index 00000000000..5f39c7636fc --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-discoverer/module.properties @@ -0,0 +1,2 @@ +name=server-discoverer +parent=discoverer \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-discoverer/spring-server-discoverer-context.xml b/server/resources/META-INF/cloudstack/server-discoverer/spring-server-discoverer-context.xml new file mode 100644 index 00000000000..90666d13143 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-discoverer/spring-server-discoverer-context.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-fencer/module.properties b/server/resources/META-INF/cloudstack/server-fencer/module.properties new file mode 100644 index 00000000000..547d855a46e --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-fencer/module.properties @@ -0,0 +1,2 @@ +name=server-fencer +parent=compute \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-fencer/spring-server-fencer-context.xml b/server/resources/META-INF/cloudstack/server-fencer/spring-server-fencer-context.xml new file mode 100644 index 00000000000..3312d5fb288 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-fencer/spring-server-fencer-context.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-investigator/module.properties b/server/resources/META-INF/cloudstack/server-investigator/module.properties new file mode 100644 index 00000000000..0752ecbc860 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-investigator/module.properties @@ -0,0 +1,2 @@ +name=server-investigator +parent=compute \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-investigator/spring-server-investigator-context.xml b/server/resources/META-INF/cloudstack/server-investigator/spring-server-investigator-context.xml new file mode 100644 index 00000000000..24e6e33c456 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-investigator/spring-server-investigator-context.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-network/module.properties b/server/resources/META-INF/cloudstack/server-network/module.properties new file mode 100644 index 00000000000..eb5f750a79c --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-network/module.properties @@ -0,0 +1,2 @@ +name=server-network +parent=network \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-network/spring-server-network-context.xml b/server/resources/META-INF/cloudstack/server-network/spring-server-network-context.xml new file mode 100644 index 00000000000..553ae44eacb --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-network/spring-server-network-context.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-planner/module.properties b/server/resources/META-INF/cloudstack/server-planner/module.properties new file mode 100644 index 00000000000..fa82ba58635 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-planner/module.properties @@ -0,0 +1,2 @@ +name=server-planner +parent=planner \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-planner/spring-server-planner-context.xml b/server/resources/META-INF/cloudstack/server-planner/spring-server-planner-context.xml new file mode 100644 index 00000000000..36f3ed02a3f --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-planner/spring-server-planner-context.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-storage/module.properties b/server/resources/META-INF/cloudstack/server-storage/module.properties new file mode 100644 index 00000000000..2874a1b65e8 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-storage/module.properties @@ -0,0 +1,2 @@ +name=server-storage +parent=storage \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-storage/spring-server-storage-context.xml b/server/resources/META-INF/cloudstack/server-storage/spring-server-storage-context.xml new file mode 100644 index 00000000000..8b90200a97e --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-storage/spring-server-storage-context.xml @@ -0,0 +1,34 @@ + + + + + + + diff --git a/server/resources/META-INF/cloudstack/server-template-adapter/module.properties b/server/resources/META-INF/cloudstack/server-template-adapter/module.properties new file mode 100644 index 00000000000..45531d9426f --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-template-adapter/module.properties @@ -0,0 +1,2 @@ +name=server-template-adapter +parent=storage \ No newline at end of file diff --git a/server/resources/META-INF/cloudstack/server-template-adapter/spring-server-template-adapter-context.xml b/server/resources/META-INF/cloudstack/server-template-adapter/spring-server-template-adapter-context.xml new file mode 100644 index 00000000000..1eeb27c7099 --- /dev/null +++ b/server/resources/META-INF/cloudstack/server-template-adapter/spring-server-template-adapter-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index b73045d5fce..fd3492d56ca 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -82,7 +82,6 @@ import org.apache.http.protocol.ResponseDate; import org.apache.http.protocol.ResponseServer; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; - import org.apache.cloudstack.acl.APIChecker; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -186,11 +185,11 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer @Override public boolean configure(String name, Map params) throws ConfigurationException { - init(); return true; } - public void init() { + @Override + public boolean start() { Integer apiPort = null; // api port, null by default SearchCriteria sc = _configDao.createSearchCriteria(); sc.addAnd("name", SearchCriteria.Op.EQ, Config.IntegrationAPIPort.key()); @@ -245,6 +244,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer ListenerThread listenerThread = new ListenerThread(this, apiPort); listenerThread.start(); } + + return true; } // NOTE: handle() only handles over the wire (OTW) requests from integration.api.port 8096 diff --git a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java index 675ff2505bb..ef161338a1c 100755 --- a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java @@ -70,6 +70,9 @@ public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager imp private String _ip = null; + public StaticConsoleProxyManager() { + + } @Override protected HostVO findHost(VMInstanceVO vm) { diff --git a/server/src/com/cloud/event/ActionEventInterceptor.java b/server/src/com/cloud/event/ActionEventInterceptor.java index 83965120883..1820b346fbf 100644 --- a/server/src/com/cloud/event/ActionEventInterceptor.java +++ b/server/src/com/cloud/event/ActionEventInterceptor.java @@ -20,14 +20,45 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; import org.apache.cloudstack.context.CallContext; import com.cloud.utils.component.ComponentMethodInterceptor; -public class ActionEventInterceptor implements ComponentMethodInterceptor { +public class ActionEventInterceptor implements ComponentMethodInterceptor, MethodInterceptor { public ActionEventInterceptor() { } + + @Override + public Object invoke(MethodInvocation invocation) throws Throwable { + Method m = invocation.getMethod(); + Object target = invocation.getThis(); + + if ( getActionEvents(m).size() == 0 ) { + /* Look for annotation on impl class */ + m = target.getClass().getMethod(m.getName(), m.getParameterTypes()); + } + + Object interceptorData = null; + + boolean success = true; + try { + interceptorData = interceptStart(m, target); + + Object result = invocation.proceed(); + success = true; + + return result; + } finally { + if ( success ) { + interceptComplete(m, target, interceptorData); + } else { + interceptException(m, target, interceptorData); + } + } + } @Override public Object interceptStart(Method method, Object target) { diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 651e82c6d21..f2fe69fe40d 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -1204,7 +1204,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } - protected List getVpcElements() { + public List getVpcElements() { if (vpcElements == null) { vpcElements = new ArrayList(); vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCVirtualRouter.getName())); @@ -2178,4 +2178,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return new ArrayList(providers.values()); } + + @Inject + public void setVpcElements(List vpcElements) { + this.vpcElements = vpcElements; + } } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 7a9343cff41..66591096e2b 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -2491,4 +2491,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, return false; } } + + @Override + public boolean start() { + // TODO Auto-generated method stub + return super.start(); + } + + } diff --git a/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties b/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties new file mode 100644 index 00000000000..31cb715dbf0 --- /dev/null +++ b/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/module.properties @@ -0,0 +1,2 @@ +name=secondary-storage-discoverer +parent=discoverer \ No newline at end of file diff --git a/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml b/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml new file mode 100644 index 00000000000..30521aa3261 --- /dev/null +++ b/services/secondary-storage/resources/META-INF/cloudstack/secondary-storage-discoverer/spring-secondary-storage-discoverer-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + diff --git a/utils/src/com/cloud/utils/component/ComponentContext.java b/utils/src/com/cloud/utils/component/ComponentContext.java index 332e4eca1a0..ae2aefe057f 100644 --- a/utils/src/com/cloud/utils/component/ComponentContext.java +++ b/utils/src/com/cloud/utils/component/ComponentContext.java @@ -49,6 +49,7 @@ public class ComponentContext implements ApplicationContextAware { private static final Logger s_logger = Logger.getLogger(ComponentContext.class); private static ApplicationContext s_appContext; + private static Map, ApplicationContext> s_appContextDelegates; private static boolean s_initializeBeans = true; @Override @@ -234,11 +235,35 @@ public class ComponentContext implements ApplicationContextAware { public static T inject(Object instance) { // autowire dynamically loaded object - AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory(); + AutowireCapableBeanFactory beanFactory = getApplicationContext(instance).getAutowireCapableBeanFactory(); beanFactory.autowireBean(instance); return (T)instance; } + private static ApplicationContext getApplicationContext(Object instance) { + ApplicationContext result = null; + + if (instance != null && s_appContextDelegates != null) { + result = s_appContextDelegates.get(instance.getClass()); + } + + return result == null ? s_appContext : result; + } + + public static synchronized void addDelegateContext(Class clazz, ApplicationContext context) { + if (s_appContextDelegates == null) { + s_appContextDelegates = new HashMap, ApplicationContext>(); + } + + s_appContextDelegates.put(clazz, context); + } + + public static synchronized void removeDelegateContext(Class clazz) { + if (s_appContextDelegates != null) { + s_appContextDelegates.remove(clazz); + } + } + public boolean isInitializeBeans() { return s_initializeBeans; }