Put usage server under Spring

This commit is contained in:
Kelven Yang 2013-01-25 23:00:33 -08:00
parent 221ac72a2e
commit 1450547987
12 changed files with 279 additions and 16 deletions

View File

@ -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

View File

@ -43,7 +43,7 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
protected final SearchBuilder<ServiceOfferingVO> ServiceOfferingsByKeywordSearch;
protected final SearchBuilder<ServiceOfferingVO> PublicServiceOfferingSearch;
protected ServiceOfferingDaoImpl() {
public ServiceOfferingDaoImpl() {
super();
UniqueNameSearch = createSearchBuilder();

View File

@ -34,7 +34,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
public class ResourceTagsDaoImpl extends GenericDaoBase<ResourceTagVO, Long> implements ResourceTagDao{
final SearchBuilder<ResourceTagVO> AllFieldsSearch;
protected ResourceTagsDaoImpl() {
public ResourceTagsDaoImpl() {
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("resourceId", AllFieldsSearch.entity().getResourceId(), Op.EQ);
AllFieldsSearch.and("uuid", AllFieldsSearch.entity().getResourceUuid(), Op.EQ);

View File

@ -55,7 +55,7 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
protected final SearchBuilder<AccountVO> CleanupForDisabledAccountsSearch;
protected final SearchBuilder<AccountVO> 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);

View File

@ -32,7 +32,7 @@ public class UserAccountDaoImpl extends GenericDaoBase<UserAccountVO, Long> impl
protected final SearchBuilder<UserAccountVO> userAccountSearch;
protected UserAccountDaoImpl() {
public UserAccountDaoImpl() {
userAccountSearch = createSearchBuilder();
userAccountSearch.and("apiKey", userAccountSearch.entity().getApiKey(), SearchCriteria.Op.EQ);
userAccountSearch.done();

View File

@ -42,7 +42,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
final GenericSearchBuilder<NicVO, Integer> CountBy;
protected NicDaoImpl() {
public NicDaoImpl() {
super();
AllFieldsSearch = createSearchBuilder();

View File

@ -116,7 +116,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
@Inject protected UserVmDetailsDao _detailsDao;
@Inject protected NicDao _nicDao;
protected UserVmDaoImpl() {
public UserVmDaoImpl() {
}
@PostConstruct

View File

@ -36,7 +36,7 @@ public class UserVmDetailsDaoImpl extends GenericDaoBase<UserVmDetailVO, Long> i
protected final SearchBuilder<UserVmDetailVO> VmSearch;
protected final SearchBuilder<UserVmDetailVO> DetailSearch;
protected UserVmDetailsDaoImpl() {
public UserVmDetailsDaoImpl() {
VmSearch = createSearchBuilder();
VmSearch.and("vmId", VmSearch.entity().getVmId(), SearchCriteria.Op.EQ);
VmSearch.done();

View File

@ -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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.cloud.usage" />
<!--
@DB support
-->
<aop:config proxy-target-class="true">
<aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
<aop:pointcut id="captureAnyMethod"
expression="execution(* *(..))"
/>
<aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/>
</aop:aspect>
</aop:config>
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
<bean id="ComponentContext" class="com.cloud.utils.component.ComponentContext" />
<bean id="UsageServerConfig" class="com.cloud.usage.UsageServerComponentConfig" />
</beans>

View File

@ -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()) {

View File

@ -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());
}
}
}
}

View File

@ -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();
}
}