diff --git a/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/TestConfiguration.java b/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/TestConfiguration.java index d5190719733..1d3202f123b 100644 --- a/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/TestConfiguration.java +++ b/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/TestConfiguration.java @@ -27,7 +27,6 @@ import org.springframework.context.annotation.Configuration; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.ClusterDaoImpl; - @Configuration public class TestConfiguration { @Bean diff --git a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java index a43c2b32049..062103e3198 100644 --- a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java +++ b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java @@ -43,7 +43,7 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase ServiceOfferingsByKeywordSearch; protected final SearchBuilder PublicServiceOfferingSearch; - protected ServiceOfferingDaoImpl() { + public ServiceOfferingDaoImpl() { super(); UniqueNameSearch = createSearchBuilder(); diff --git a/server/src/com/cloud/tags/dao/ResourceTagsDaoImpl.java b/server/src/com/cloud/tags/dao/ResourceTagsDaoImpl.java index 2eb729f37dc..97639564967 100644 --- a/server/src/com/cloud/tags/dao/ResourceTagsDaoImpl.java +++ b/server/src/com/cloud/tags/dao/ResourceTagsDaoImpl.java @@ -34,7 +34,7 @@ import com.cloud.utils.db.SearchCriteria.Op; public class ResourceTagsDaoImpl extends GenericDaoBase implements ResourceTagDao{ final SearchBuilder AllFieldsSearch; - protected ResourceTagsDaoImpl() { + public ResourceTagsDaoImpl() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("resourceId", AllFieldsSearch.entity().getResourceId(), Op.EQ); AllFieldsSearch.and("uuid", AllFieldsSearch.entity().getResourceUuid(), Op.EQ); diff --git a/server/src/com/cloud/user/dao/AccountDaoImpl.java b/server/src/com/cloud/user/dao/AccountDaoImpl.java index ae102a3d446..c8bf46a7362 100755 --- a/server/src/com/cloud/user/dao/AccountDaoImpl.java +++ b/server/src/com/cloud/user/dao/AccountDaoImpl.java @@ -55,7 +55,7 @@ public class AccountDaoImpl extends GenericDaoBase implements A protected final SearchBuilder CleanupForDisabledAccountsSearch; protected final SearchBuilder NonProjectAccountSearch; - protected AccountDaoImpl() { + public AccountDaoImpl() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("accountName", AllFieldsSearch.entity().getAccountName(), SearchCriteria.Op.EQ); AllFieldsSearch.and("domainId", AllFieldsSearch.entity().getDomainId(), SearchCriteria.Op.EQ); diff --git a/server/src/com/cloud/user/dao/UserAccountDaoImpl.java b/server/src/com/cloud/user/dao/UserAccountDaoImpl.java index 9edfe4aa310..fa87d8682bc 100644 --- a/server/src/com/cloud/user/dao/UserAccountDaoImpl.java +++ b/server/src/com/cloud/user/dao/UserAccountDaoImpl.java @@ -32,7 +32,7 @@ public class UserAccountDaoImpl extends GenericDaoBase impl protected final SearchBuilder userAccountSearch; - protected UserAccountDaoImpl() { + public UserAccountDaoImpl() { userAccountSearch = createSearchBuilder(); userAccountSearch.and("apiKey", userAccountSearch.entity().getApiKey(), SearchCriteria.Op.EQ); userAccountSearch.done(); diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java index e09b0abff51..5cf152f9f90 100644 --- a/server/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java @@ -42,7 +42,7 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { final GenericSearchBuilder CountBy; - protected NicDaoImpl() { + public NicDaoImpl() { super(); AllFieldsSearch = createSearchBuilder(); diff --git a/server/src/com/cloud/vm/dao/UserVmDaoImpl.java b/server/src/com/cloud/vm/dao/UserVmDaoImpl.java index 13883cf7439..93780b155ca 100755 --- a/server/src/com/cloud/vm/dao/UserVmDaoImpl.java +++ b/server/src/com/cloud/vm/dao/UserVmDaoImpl.java @@ -116,7 +116,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use @Inject protected UserVmDetailsDao _detailsDao; @Inject protected NicDao _nicDao; - protected UserVmDaoImpl() { + public UserVmDaoImpl() { } @PostConstruct diff --git a/server/src/com/cloud/vm/dao/UserVmDetailsDaoImpl.java b/server/src/com/cloud/vm/dao/UserVmDetailsDaoImpl.java index 93c481ead5d..6ec6f68ada6 100644 --- a/server/src/com/cloud/vm/dao/UserVmDetailsDaoImpl.java +++ b/server/src/com/cloud/vm/dao/UserVmDetailsDaoImpl.java @@ -36,7 +36,7 @@ public class UserVmDetailsDaoImpl extends GenericDaoBase i protected final SearchBuilder VmSearch; protected final SearchBuilder DetailSearch; - protected UserVmDetailsDaoImpl() { + public UserVmDetailsDaoImpl() { VmSearch = createSearchBuilder(); VmSearch.and("vmId", VmSearch.entity().getVmId(), SearchCriteria.Op.EQ); VmSearch.done(); diff --git a/usage/conf/usageApplicationContext.xml.in b/usage/conf/usageApplicationContext.xml.in new file mode 100644 index 00000000000..32da93eecbc --- /dev/null +++ b/usage/conf/usageApplicationContext.xml.in @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java index 4944a14b14e..438ab723ec1 100644 --- a/usage/src/com/cloud/usage/UsageManagerImpl.java +++ b/usage/src/com/cloud/usage/UsageManagerImpl.java @@ -144,7 +144,8 @@ public class UsageManagerImpl implements UsageManager, Runnable { final Class c = UsageServer.class; m_version = c.getPackage().getImplementationVersion(); if (m_version == null) { - throw new CloudRuntimeException("Unable to find the implementation version of this usage server"); + // TODO + // throw new CloudRuntimeException("Unable to find the implementation version of this usage server"); } if (s_logger.isInfoEnabled()) { diff --git a/usage/src/com/cloud/usage/UsageServer.java b/usage/src/com/cloud/usage/UsageServer.java index eaf91328929..ce87b885d2f 100644 --- a/usage/src/com/cloud/usage/UsageServer.java +++ b/usage/src/com/cloud/usage/UsageServer.java @@ -16,31 +16,47 @@ // under the License. package com.cloud.usage; -import javax.inject.Inject; +import java.io.File; import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; +import org.apache.log4j.xml.DOMConfigurator; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; - +import com.cloud.utils.PropertiesUtil; +import com.cloud.utils.component.ComponentContext; public class UsageServer { private static final Logger s_logger = Logger.getLogger(UsageServer.class.getName()); public static final String Name = "usage-server"; - - @Inject UsageManager mgr; + + UsageManager mgr; + /** * @param args */ public static void main(String[] args) { + initLog4j(); + ApplicationContext appContext = new ClassPathXmlApplicationContext("usageApplicationContext.xml"); + UsageServer usage = new UsageServer(); usage.init(args); - usage.start(); + usage.start(appContext); } public void init(String[] args) { - } - public void start() { + public void start(ApplicationContext appContext) { + try { + ComponentContext.initComponentsLifeCycle(); + } catch(Exception e) { + e.printStackTrace(); + } + + mgr = appContext.getBean(UsageManager.class); + if (mgr != null) { if (s_logger.isInfoEnabled()) { s_logger.info("UsageServer ready..."); @@ -55,4 +71,18 @@ public class UsageServer { public void destroy() { } + + static private void initLog4j() { + File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); + if (file != null) { + s_logger.info("log4j configuration found at " + file.getAbsolutePath()); + DOMConfigurator.configureAndWatch(file.getAbsolutePath()); + } else { + file = PropertiesUtil.findConfigFile("log4j-cloud.properties"); + if (file != null) { + s_logger.info("log4j configuration found at " + file.getAbsolutePath()); + PropertyConfigurator.configureAndWatch(file.getAbsolutePath()); + } + } + } } diff --git a/usage/src/com/cloud/usage/UsageServerComponentConfig.java b/usage/src/com/cloud/usage/UsageServerComponentConfig.java new file mode 100644 index 00000000000..aa8682c54d9 --- /dev/null +++ b/usage/src/com/cloud/usage/UsageServerComponentConfig.java @@ -0,0 +1,180 @@ +// 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 +// 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.usage; + +import org.springframework.context.annotation.Bean; + +import org.springframework.context.annotation.Configuration; + +import com.cloud.cluster.agentlb.dao.HostTransferMapDao; +import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl; +import com.cloud.dc.dao.*; +import com.cloud.service.dao.ServiceOfferingDaoImpl; +import com.cloud.vm.dao.*; +import com.cloud.network.dao.*; +import com.cloud.host.dao.*; + +import com.cloud.utils.crypt.EncryptionSecretKeyChecker; +import com.cloud.vm.dao.VMInstanceDaoImpl; +import com.cloud.vm.dao.UserVmDaoImpl; +import com.cloud.event.dao.EventDaoImpl; +import com.cloud.user.dao.UserStatisticsDaoImpl; +import com.cloud.network.dao.IPAddressDaoImpl; +import com.cloud.domain.dao.DomainDaoImpl; +import com.cloud.user.dao.AccountDaoImpl; +import com.cloud.user.dao.UserAccountDaoImpl; +import com.cloud.configuration.dao.ConfigurationDaoImpl; +import com.cloud.alert.dao.AlertDaoImpl; +import com.cloud.event.dao.UsageEventDaoImpl; +import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.event.dao.EventDao; +import com.cloud.user.dao.UserStatisticsDao; +import com.cloud.domain.dao.DomainDao; +import com.cloud.user.dao.*; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.alert.dao.AlertDao; +import com.cloud.event.dao.UsageEventDao; +import com.cloud.tags.dao.*; + +@Configuration +public class UsageServerComponentConfig { + + @Bean + public HostTransferMapDao HostTransferDao() { + return new HostTransferMapDaoImpl(); + } + + @Bean + public ClusterDao ClusterDao() { + return new ClusterDaoImpl(); + } + + @Bean + public HostPodDao HostPodDao() { + return new HostPodDaoImpl(); + } + + @Bean + public UserVmDetailsDao UserVmDetailsDao() { + return new UserVmDetailsDaoImpl(); + } + + @Bean + public VlanDaoImpl VlanDaoImpl() { + return new VlanDaoImpl(); + } + + @Bean + public PodVlanMapDao PodVlanMapDao() { + return new PodVlanMapDaoImpl(); + } + + @Bean + public AccountVlanMapDao AccountVlanMapDao() { + return new AccountVlanMapDaoImpl(); + } + + @Bean + public EncryptionSecretKeyChecker EncryptionSecretKeyChecker() { + return new EncryptionSecretKeyChecker(); + } + + @Bean + public VMInstanceDao VmInstanceDao() { + return new VMInstanceDaoImpl(); + } + + @Bean + public UserVmDao UserVmDao() { + return new UserVmDaoImpl(); + } + + @Bean + public ServiceOfferingDao ServiceOfferingDao() { + return new ServiceOfferingDaoImpl(); + } + + @Bean + public EventDao EventDao() { + return new EventDaoImpl(); + } + + @Bean + public UserStatisticsDao UserStatisticsDao() { + return new UserStatisticsDaoImpl(); + } + + @Bean + public IPAddressDao IPAddressDao() { + return new IPAddressDaoImpl(); + } + + @Bean + public DomainDao DomainDao() { + return new DomainDaoImpl(); + } + + @Bean + public AccountDao AccountDao() { + return new AccountDaoImpl(); + } + + @Bean + public UserAccountDao UserAccountDao() { + return new UserAccountDaoImpl(); + } + + @Bean + public ConfigurationDao ConfigurationDao() { + return new ConfigurationDaoImpl(); + } + + @Bean + public AlertDao AlertDao() { + return new AlertDaoImpl(); + } + + @Bean + public UsageEventDao UsageEventDao() { + return new UsageEventDaoImpl(); + } + + @Bean + public ResourceTagsDaoImpl ResourceTagsDaoImpl() { + return new ResourceTagsDaoImpl(); + } + + @Bean + public NicDao NicDao() { + return new NicDaoImpl(); + } + + @Bean + public HostDao HostDao() { + return new HostDaoImpl(); + } + + @Bean + public HostDetailsDao HostDetailsDao() { + return new HostDetailsDaoImpl(); + } + + @Bean + public HostTagsDao HostTagsDao() { + return new HostTagsDaoImpl(); + } +}