Fixed up unit testing to use only an in class TestConfiguration

This commit is contained in:
Alex Huang 2013-05-06 06:29:59 -07:00 committed by Alena Prokharchyk
parent 6727571403
commit e9953cd1a8
25 changed files with 518 additions and 334 deletions

View File

@ -30,11 +30,6 @@
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
@ -55,6 +50,11 @@
<artifactId>cloud-framework-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-ipc</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>

View File

@ -50,11 +50,11 @@ public class StoragePoolHostVO implements StoragePoolHostAssoc {
private String localPath;
@Column(name=GenericDaoBase.CREATED_COLUMN)
private final Date created = null;
private Date created = null;
@Column(name="last_updated")
@Temporal(value=TemporalType.TIMESTAMP)
private final Date lastUpdated = null;
private Date lastUpdated = null;
public StoragePoolHostVO() {

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import org.apache.cloudstack.storage.allocator.StorageAllocatorTestConfiguration.Library;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -36,7 +37,6 @@ import com.cloud.host.dao.HostDaoImpl;
import com.cloud.storage.StorageManager;
import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
import com.cloud.storage.dao.VMTemplateDaoImpl;
import com.cloud.utils.component.SpringComponentScanUtils;
import com.cloud.vm.UserVmManager;
@ -67,7 +67,7 @@ public class StorageAllocatorTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = StorageAllocatorTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}
}

View File

@ -24,6 +24,7 @@ import org.apache.cloudstack.framework.rpc.RpcProvider;
import org.apache.cloudstack.storage.HostEndpointRpcServer;
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
import org.apache.cloudstack.storage.test.ChildTestConfiguration.Library;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -75,7 +76,6 @@ import com.cloud.storage.swift.SwiftManager;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.template.TemplateManager;
import com.cloud.user.dao.UserDaoImpl;
import com.cloud.utils.component.SpringComponentScanUtils;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.ConsoleProxyDaoImpl;
import com.cloud.vm.dao.DomainRouterDao;
@ -222,7 +222,7 @@ public class ChildTestConfiguration extends TestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -16,12 +16,74 @@
// under the License.
package com.cloud.agent.manager;
import com.cloud.agent.api.*;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.AttachIsoCommand;
import com.cloud.agent.api.AttachVolumeCommand;
import com.cloud.agent.api.BackupSnapshotCommand;
import com.cloud.agent.api.BumpUpPriorityCommand;
import com.cloud.agent.api.CheckHealthCommand;
import com.cloud.agent.api.CheckNetworkCommand;
import com.cloud.agent.api.CheckRouterCommand;
import com.cloud.agent.api.CheckVirtualMachineCommand;
import com.cloud.agent.api.CleanupNetworkRulesCmd;
import com.cloud.agent.api.ClusterSyncCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.ComputeChecksumCommand;
import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
import com.cloud.agent.api.CreateStoragePoolCommand;
import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
import com.cloud.agent.api.DeleteStoragePoolCommand;
import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.GetHostStatsCommand;
import com.cloud.agent.api.GetStorageStatsCommand;
import com.cloud.agent.api.GetVmStatsCommand;
import com.cloud.agent.api.GetVncPortCommand;
import com.cloud.agent.api.MaintainCommand;
import com.cloud.agent.api.ManageSnapshotCommand;
import com.cloud.agent.api.MigrateCommand;
import com.cloud.agent.api.ModifyStoragePoolCommand;
import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.PingTestCommand;
import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.RebootCommand;
import com.cloud.agent.api.SecStorageSetupCommand;
import com.cloud.agent.api.SecStorageVMSetupCommand;
import com.cloud.agent.api.SecurityGroupRulesCmd;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.StoragePoolInfo;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
import com.cloud.agent.api.routing.*;
import com.cloud.agent.api.storage.*;
import com.cloud.agent.api.routing.DhcpEntryCommand;
import com.cloud.agent.api.routing.IpAssocCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
import com.cloud.agent.api.routing.SavePasswordCommand;
import com.cloud.agent.api.routing.SetFirewallRulesCommand;
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
import com.cloud.agent.api.routing.VmDataCommand;
import com.cloud.agent.api.storage.CopyVolumeCommand;
import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.DeleteTemplateCommand;
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.ListTemplateCommand;
import com.cloud.agent.api.storage.ListVolumeCommand;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
import com.cloud.simulator.MockConfigurationVO;
import com.cloud.simulator.MockHost;
import com.cloud.simulator.MockVMVO;
@ -34,14 +96,6 @@ import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine.State;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import java.util.HashMap;
import java.util.Map;
@Component
@Local(value = { SimulatorManager.class })
@ -256,7 +310,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
return Answer.createUnsupportedCommandAnswer(cmd);
}
} catch(Exception e) {
s_logger.error("Failed execute cmd: " + e.toString());
s_logger.error("Failed execute cmd: ", e);
txn.rollback();
return new Answer(cmd, false, e.toString());
} finally {

62
pom.xml
View File

@ -1,13 +1,12 @@
<!-- 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. -->
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. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -171,6 +170,7 @@
<module>framework</module>
<module>test</module>
<module>client</module>
<module>services</module>
</modules>
<dependencyManagement>
@ -206,22 +206,18 @@
<version>${org.springframework.version}</version>
</dependency>
<!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency>
<groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId> <version>${org.springframework.version}</version>
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId> <version>${org.springframework.version}</version>
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId> <version>${org.springframework.version}</version>
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId> <version>${org.springframework.version}</version>
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version> </dependency> -->
<dependency>
<groupId>org.mockito</groupId>
@ -265,6 +261,20 @@
<testOutputDirectory>${basedir}/${cs.target.dir}/test-classes</testOutputDirectory>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
@ -504,7 +514,7 @@
<cs.target.dir>target-eclipse</cs.target.dir>
</properties>
</profile>
<profile>
<profile>
<id>developer</id>
<properties>
<marvin.config>tools/devcloud/devcloud.cfg</marvin.config>
@ -521,7 +531,7 @@
</properties>
<modules>
<module>developer</module>
<!--module>tools/devcloud</module-->
<!--module>tools/devcloud</module -->
</modules>
</profile>
<profile>

View File

@ -95,6 +95,11 @@
<artifactId>cloud-framework-events</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>

View File

@ -5,7 +5,7 @@
// 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,
@ -40,6 +40,8 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
@ -92,6 +94,8 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork.BroadcastDomainRange;
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.AccountGuestVlanMapDao;
import com.cloud.network.dao.AccountGuestVlanMapVO;
import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
@ -167,6 +171,7 @@ import com.cloud.vm.dao.NicSecondaryIpDao;
import com.cloud.vm.dao.NicSecondaryIpVO;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
<<<<<<< HEAD
import com.cloud.vm.*;
import com.cloud.vm.dao.*;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
@ -238,9 +243,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
@Inject
UsageEventDao _usageEventDao;
@Inject List<NetworkGuru> _networkGurus;
@Inject
NetworkDomainDao _networkDomainDao;
@Inject
@ -248,10 +253,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
@Inject
FirewallRulesDao _firewallDao;
@Inject
ResourceLimitService _resourceLimitMgr;
@Inject
DomainManager _domainMgr;
@Inject
@ -262,7 +267,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
PhysicalNetworkDao _physicalNetworkDao;
@Inject
PhysicalNetworkServiceProviderDao _pNSPDao;
@Inject
PhysicalNetworkTrafficTypeDao _pNTrafficTypeDao;
@ -344,7 +349,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (purposes == null || purposes.isEmpty()) {
// since no active rules are there check if any rules are applied on the public IP but are in
// revoking state
purposes = getPublicIpPurposeInRules(ip, true, includingFirewall);
if (ip.isOneToOneNat()) {
if (purposes == null) {
@ -461,9 +466,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
return true;
}
private Set<Purpose> getPublicIpPurposeInRules(PublicIp ip, boolean includeRevoked, boolean includingFirewall) {
Set<Purpose> result = new HashSet<Purpose>();
@ -492,15 +497,15 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networksDao.listByZoneAndGuestType(owner.getId(), zoneId, Network.GuestType.Isolated, false);
}
@Override
public List<? extends Network> getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner) {
return _networksDao.listSourceNATEnabledNetworks(owner.getId(), zoneId, Network.GuestType.Isolated);
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true)
@ -546,7 +551,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
_accountMgr.checkAccess(caller, null, false, ipOwner);
long callerUserId = UserContext.current().getCallerUserId();
DataCenter zone = _configMgr.getZone(zoneId);
return _networkMgr.allocateIp(ipOwner, isSystem, caller, callerUserId, zone);
}
@ -578,6 +583,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
@Override
public NicSecondaryIp allocateSecondaryGuestIP (Account ipOwner, long zoneId, Long nicId, Long networkId, String requestedIp) throws InsufficientAddressCapacityException {
Long accountId = null;
@ -685,6 +691,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
@Override
@DB
public boolean releaseSecondaryIpFromNic (long ipAddressId) {
Account caller = UserContext.current().getCaller();
@ -846,7 +853,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
public Network getNetwork(long id) {
return _networksDao.findById(id);
}
private void checkSharedNetworkCidrOverlap(Long zoneId, long physicalNetworkId, String cidr) {
if (zoneId == null || cidr == null) {
@ -897,7 +904,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_CREATE, eventDescription = "creating network")
@ -929,15 +936,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (ntwkOff == null || ntwkOff.isSystemOnly()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering by specified id");
if (ntwkOff != null) {
ex.addProxyObject(ntwkOff, networkOfferingId, "networkOfferingId");
ex.addProxyObject(ntwkOff, networkOfferingId, "networkOfferingId");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(ntwkOff);
if (tablename != null) {
ex.addProxyObject(tablename, networkOfferingId, "networkOfferingId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
throw ex;
}
throw ex;
}
@ -959,12 +963,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (zone == null) {
throw new InvalidParameterValueException("Specified zone id was not found");
}
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
// See DataCenterVO.java
PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled");
ex.addProxyObject(zone, zoneId, "zoneId");
throw ex;
throw ex;
}
// Only domain and account ACL types are supported in Acton.
@ -984,7 +988,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
} else if (ntwkOff.getGuestType() == GuestType.Shared) {
if (!(aclType == ACLType.Domain || aclType == ACLType.Account)) {
throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " +
throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " +
ACLType.Account + " for network of type " + Network.GuestType.Shared);
}
}
@ -1020,7 +1024,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
DomainVO domain = _domainDao.findById(domainId);
if (domain == null) {
if (domain == null) {
throw new InvalidParameterValueException("Unable to find domain by specified id");
}
_accountMgr.checkAccess(caller, domain);
@ -1046,7 +1050,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (startIPv6 != null) {
ipv6 = true;
}
if (gateway != null) {
try {
// getByName on a literal representation will only check validity of the address
@ -1063,8 +1067,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw new InvalidParameterValueException("Gateway parameter is invalid");
}
}
String cidr = null;
if (ipv4) {
// if end ip is not specified, default it to startIp
@ -1097,18 +1101,18 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
if (ipv6) {
if (endIPv6 == null) {
endIPv6 = startIPv6;
}
_networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
if (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared) {
throw new InvalidParameterValueException("Can only support create IPv6 network with advance shared network!");
}
}
// Regular user can create Guest Isolated Source Nat enabled network only
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL
&& (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Isolated
@ -1122,7 +1126,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL && (ntwkOff.getSpecifyVlan() || vlanId != null)) {
throw new InvalidParameterValueException("Regular user is not allowed to specify vlanId");
}
if (ipv4) {
// For non-root admins check cidr limit - if it's allowed by global config value
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && cidr != null) {
@ -1140,7 +1144,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (ipv6 && providersConfiguredForExternalNetworking(ntwkProviders)) {
throw new InvalidParameterValueException("Cannot support IPv6 on network offering with external devices!");
}
if (cidr != null && providersConfiguredForExternalNetworking(ntwkProviders)) {
if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) &&
isSharedNetworkOfferingWithServices(networkOfferingId)) {
@ -1156,9 +1160,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// 2) GuestType is Isolated, but SourceNat service is disabled
boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced
&& ((ntwkOff.getGuestType() == Network.GuestType.Shared)
|| (ntwkOff.getGuestType() == GuestType.Isolated &&
|| (ntwkOff.getGuestType() == GuestType.Isolated &&
!areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))));
if (!createVlan) {
// Only support advance shared network in IPv6, which means createVlan is a must
if (ipv6) {
@ -1176,7 +1180,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
throw ex;
throw ex;
}
Transaction txn = Transaction.currentTxn();
@ -1203,7 +1207,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (!_configMgr.isOfferingForVpc(ntwkOff)){
throw new InvalidParameterValueException("Network offering can't be used for VPC networks");
}
network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, caller);
} else {
if (_configMgr.isOfferingForVpc(ntwkOff)){
@ -1213,9 +1217,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only");
}
network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr);
}
}
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) {
// Create vlan ip range
@ -1325,13 +1329,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
} else {
permittedAccounts.clear();
Project project = _projectMgr.getProject(projectId);
if (project == null) {
if (project == null) {
throw new InvalidParameterValueException("Unable to find project by specified id");
}
if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) {
// getProject() returns type ProjectVO.
InvalidParameterValueException ex = new InvalidParameterValueException("Account " + caller + " cannot access specified project id");
ex.addProxyObject(project, projectId, "projectId");
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
permittedAccounts.add(project.getProjectAccountId());
@ -1343,15 +1347,15 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
path = _domainDao.findById(domainId).getPath();
} else {
path = _domainDao.findById(caller.getDomainId()).getPath();
}
}
if (listAll && domainId == null) {
isRecursive = true;
}
Filter searchFilter = new Filter(NetworkVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<NetworkVO> sb = _networksDao.createSearchBuilder();
if (forVpc != null) {
if (forVpc) {
sb.and("vpc", sb.entity().getVpcId(), Op.NNULL);
@ -1395,8 +1399,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
accountSearch.and("typeNEQ", accountSearch.entity().getType(), SearchCriteria.Op.NEQ);
accountSearch.and("typeEQ", accountSearch.entity().getType(), SearchCriteria.Op.EQ);
sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
List<NetworkVO> networksToReturn = new ArrayList<NetworkVO>();
@ -1405,7 +1409,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (!permittedAccounts.isEmpty()) {
//get account level networks
networksToReturn.addAll(listAccountSpecificNetworks(
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter,
permittedAccounts));
//get domain level networks
@ -1419,12 +1423,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
} else {
//add account specific networks
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter, path,
isRecursive));
//add domain specific networks of domain + parent domains
networksToReturn.addAll(listDomainSpecificNetworksByDomainPath(
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, zoneType), searchFilter, path,
isRecursive));
//add networks of subdomains
@ -1464,7 +1468,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
networksToReturn=supportedNetworks;
}
if (canUseForDeploy != null) {
List<NetworkVO> networksForDeploy = new ArrayList<NetworkVO>();
for (NetworkVO network : networksToReturn) {
@ -1472,16 +1476,16 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
networksForDeploy.add(network);
}
}
networksToReturn=networksForDeploy;
}
return networksToReturn;
}
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id,
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id,
Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId,
String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId, Map<String, String> tags, String zoneType) {
@ -1506,9 +1510,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
if(zoneType != null) {
sc.setJoinParameters("zoneSearch", "networkType", zoneType);
sc.setJoinParameters("zoneSearch", "networkType", zoneType);
}
if (guestIpType != null) {
sc.addAnd("guestType", SearchCriteria.Op.EQ, guestIpType);
}
@ -1538,11 +1542,11 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (specifyIpRanges != null) {
sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges);
}
if (vpcId != null) {
sc.addAnd("vpcId", SearchCriteria.Op.EQ, vpcId);
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Network.toString());
@ -1625,7 +1629,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
List<Long> networkIds = new ArrayList<Long>();
List<NetworkDomainVO> maps = _networkDomainDao.listDomainNetworkMapByDomain(allowedDomains.toArray());
for (NetworkDomainVO map : maps) {
@ -1654,16 +1658,16 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
NetworkVO network = _networksDao.findById(networkId);
if (network == null) {
// see NetworkVO.java
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find network with specified id");
ex.addProxyObject(network, networkId, "networkId");
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
// don't allow to delete system network
if (isNetworkSystem(network)) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id is system and can't be removed");
ex.addProxyObject(network, network.getId(), "networkId");
ex.addProxyObject(network, network.getId(), "networkId");
throw ex;
}
@ -1678,7 +1682,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networkMgr.destroyNetwork(networkId, context);
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true)
public boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
@ -1690,7 +1694,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// Check if network exists
NetworkVO network = _networksDao.findById(networkId);
if (network == null) {
if (network == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist");
ex.addProxyObject("networks", networkId, "networkId");
throw ex;
@ -1700,9 +1704,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (!(network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) {
throw new InvalidParameterValueException("Network is not in the right state to be restarted. Correct states are: " + Network.State.Implemented + ", " + Network.State.Setup);
}
if (network.getBroadcastDomainType() == BroadcastDomainType.Lswitch ) {
/**
/**
* Unable to restart these networks now.
* TODO Restarting a SDN based network requires updating the nics and the configuration
* in the controller. This requires a non-trivial rewrite of the restart procedure.
@ -1728,15 +1732,15 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networksDao.getActiveNicsIn(networkId);
}
protected Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) {
if (!areServicesSupportedByNetworkOffering(offering.getId(), service)) {
// TBD: We should be sending networkOfferingId and not the offering object itself.
// TBD: We should be sending networkOfferingId and not the offering object itself.
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the network offering " + offering);
}
@ -1769,14 +1773,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return serviceCapabilities;
}
@Override
public IpAddress getIp(long ipAddressId) {
return _ipAddressDao.findById(ipAddressId);
}
protected boolean providersConfiguredForExternalNetworking(Collection<String> providers) {
for(String providerStr : providers){
Provider provider = Network.Provider.getProvider(providerStr);
@ -1800,32 +1804,32 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return false;
}
protected boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) {
return (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(networkOfferingId, services));
}
protected boolean areServicesSupportedInNetwork(long networkId, Service... services) {
return (_ntwkSrvcDao.areServicesSupportedInNetwork(networkId, services));
}
private boolean checkForNonStoppedVmInNetwork(long networkId) {
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Starting,
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Starting,
VirtualMachine.State.Running, VirtualMachine.State.Migrating, VirtualMachine.State.Stopping);
return vms.isEmpty();
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_UPDATE, eventDescription = "updating network", async = true)
public Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount,
public Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount,
User callerUser, String domainSuffix, Long networkOfferingId, Boolean changeCidr, String guestVmCidr) {
boolean restartNetwork = false;
@ -1837,7 +1841,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
ex.addProxyObject("networks", networkId, "networkId");
throw ex;
}
//perform below validation if the network is vpc network
if (network.getVpcId() != null && networkOfferingId != null) {
Vpc vpc = _vpcMgr.getVpc(network.getVpcId());
@ -1859,7 +1863,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (network.getTrafficType() != Networks.TrafficType.Guest) {
throw new InvalidParameterValueException("Can't allow networks which traffic type is not " + TrafficType.Guest);
}
_accountMgr.checkAccess(callerAccount, null, true, network);
if (name != null) {
@ -1883,14 +1887,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (networkOfferingId != null) {
if (networkOffering == null || networkOffering.isSystemOnly()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering with specified id");
ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId");
ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId");
throw ex;
}
// network offering should be in Enabled state
if (networkOffering.getState() != NetworkOffering.State.Enabled) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network offering with specified id is not in " + NetworkOffering.State.Enabled + " state, can't upgrade to it");
ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId");
ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId");
throw ex;
}
//can't update from vpc to non-vpc network offering
@ -1904,7 +1908,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (networkOfferingId != oldNetworkOfferingId) {
Collection<String> newProviders = _networkMgr.finalizeServicesAndProvidersForNetwork(networkOffering, network.getPhysicalNetworkId()).values();
Collection<String> oldProviders = _networkMgr.finalizeServicesAndProvidersForNetwork(oldNtwkOff, network.getPhysicalNetworkId()).values();
if (providersConfiguredForExternalNetworking(newProviders) != providersConfiguredForExternalNetworking(oldProviders)
&& !changeCidr) {
throw new InvalidParameterValueException("Updating network failed since guest CIDR needs to be changed!");
@ -1912,7 +1916,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (changeCidr) {
if (!checkForNonStoppedVmInNetwork(network.getId())) {
InvalidParameterValueException ex = new InvalidParameterValueException("All user vm of network of specified id should be stopped before changing CIDR!");
ex.addProxyObject(network, networkId, "networkId");
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
}
@ -2045,7 +2049,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (!_networkMgr.shutdownNetworkElementsAndResources(context, true, network)) {
s_logger.warn("Failed to shutdown the network elements and resources as a part of network restart: " + network);
CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of update to network of specified id");
ex.addProxyObject(network, networkId, "networkId");
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
} else {
@ -2064,13 +2068,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (!_networkMgr.shutdownNetwork(network.getId(), context, true)) {
s_logger.warn("Failed to shutdown the network as a part of update to network with specified id");
CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network as a part of update of specified network id");
ex.addProxyObject(network, networkId, "networkId");
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
}
} else {
CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of update to network with specified id; network is in wrong state: " + network.getState());
ex.addProxyObject(network, networkId, "networkId");
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
}
@ -2132,7 +2136,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
} catch (Exception ex) {
s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network update due to ", ex);
CloudRuntimeException e = new CloudRuntimeException("Failed to implement network (with specified id) elements and resources as a part of network update");
e.addProxyObject(network, networkId, "networkId");
e.addProxyObject(network, networkId, "networkId");
throw e;
}
}
@ -2163,7 +2167,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
protected Set<Long> getAvailableIps(Network network, String requestedIp) {
String[] cidr = network.getCidr().split("/");
List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
Set<Long> usedIps = new TreeSet<Long>();
Set<Long> usedIps = new TreeSet<Long>();
for (String ip : ips) {
if (requestedIp != null && requestedIp.equals(ip)) {
@ -2182,7 +2186,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return allPossibleIps;
}
protected boolean canUpgrade(Network network, long oldNetworkOfferingId, long newNetworkOfferingId) {
NetworkOffering oldNetworkOffering = _networkOfferingDao.findByIdIncludingRemoved(oldNetworkOfferingId);
NetworkOffering newNetworkOffering = _networkOfferingDao.findById(newNetworkOfferingId);
@ -2260,12 +2263,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return canIpsUseOffering(publicIps, newNetworkOfferingId);
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_CREATE, eventDescription = "Creating Physical Network", create = true)
public PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List<String>
public PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List<String>
isolationMethods, String broadcastDomainRangeStr, Long domainId, List<String> tags, String name) {
// Check if zone exists
@ -2370,7 +2373,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// add security group provider to the physical network
addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId());
// add VPCVirtualRouter as the defualt network service provider
addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId());
@ -2418,7 +2421,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
PhysicalNetworkVO network = _physicalNetworkDao.findById(id);
if (network == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
ex.addProxyObject(network, id, "physicalNetworkId");
ex.addProxyObject(network, id, "physicalNetworkId");
throw ex;
}
@ -2426,7 +2429,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
DataCenter zone = _dcDao.findById(network.getDataCenterId());
if (zone == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Zone with id=" + network.getDataCenterId() + " doesn't exist in the system");
ex.addProxyObject(zone, network.getDataCenterId(), "dataCenterId");
ex.addProxyObject(zone, network.getDataCenterId(), "dataCenterId");
throw ex;
}
if (newVnetRangeString != null) {
@ -2699,7 +2702,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (pNetwork == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
ex.addProxyObject(pNetwork, physicalNetworkId, "physicalNetworkId");
ex.addProxyObject(pNetwork, physicalNetworkId, "physicalNetworkId");
throw ex;
}
@ -2726,7 +2729,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// delete service providers
List<PhysicalNetworkServiceProviderVO> providers = _pNSPDao.listBy(physicalNetworkId);
for(PhysicalNetworkServiceProviderVO provider : providers){
try {
deleteNetworkServiceProvider(provider.getId());
@ -2743,7 +2746,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
_pNTrafficTypeDao.deleteTrafficTypes(physicalNetworkId);
boolean success = _physicalNetworkDao.remove(physicalNetworkId);
txn.commit();
return success;
@ -3095,7 +3098,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_CREATE, eventDescription = "Creating Physical Network ServiceProvider", create = true)
@ -3114,7 +3117,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId);
if (destNetwork == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system");
ex.addProxyObject(destNetwork, destinationPhysicalNetworkId, "destinationPhysicalNetworkId");
ex.addProxyObject(destNetwork, destinationPhysicalNetworkId, "destinationPhysicalNetworkId");
throw ex;
}
}
@ -3356,7 +3359,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
} else {
pNtwks = _physicalNetworkDao.listByZone(zoneId);
}
if (pNtwks.isEmpty()) {
throw new InvalidParameterValueException("Unable to find physical network in zone id=" + zoneId);
}
@ -3383,8 +3386,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_TRAFFIC_TYPE_CREATE, eventDescription = "Creating Physical Network TrafficType", create = true)
@ -3549,7 +3552,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return new Pair<List<? extends PhysicalNetworkTrafficType>, Integer>(result.first(), result.second());
}
@ -3576,23 +3579,23 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (networkElement == null) {
throw new CloudRuntimeException("Unable to find the Network Element implementing the VirtualRouter Provider");
}
VirtualRouterElement element = (VirtualRouterElement)networkElement;
element.addElement(nsp.getId(), VirtualRouterProviderType.VirtualRouter);
return nsp;
}
protected PhysicalNetworkServiceProvider addDefaultVpcVirtualRouterToPhysicalNetwork(long physicalNetworkId) {
PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId,
PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId,
Network.Provider.VPCVirtualRouter.getName(), null, null);
NetworkElement networkElement = _networkModel.getElementImplementingProvider(Network.Provider.VPCVirtualRouter.getName());
if (networkElement == null) {
throw new CloudRuntimeException("Unable to find the Network Element implementing the VPCVirtualRouter Provider");
}
VpcVirtualRouterElement element = (VpcVirtualRouterElement)networkElement;
element.addElement(nsp.getId(), VirtualRouterProviderType.VPCVirtualRouter);
@ -3617,7 +3620,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
protected PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) {
PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId,
PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId,
Network.Provider.SecurityGroupProvider.getName(), null, null);
return nsp;
@ -3629,13 +3632,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
PhysicalNetworkVO pvo = _physicalNetworkDao.findById(physicalNetworkId);
DataCenterVO dvo = _dcDao.findById(pvo.getDataCenterId());
if (dvo.getNetworkType() == NetworkType.Basic) {
// Baremetal is currently disabled
/*
addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalDhcpProvider", null, null);
addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalPxeProvider", null, null);
addProviderToPhysicalNetwork(physicalNetworkId, "BaremetaUserdataProvider", null, null);
*/
*/
}
return null;
}
@ -3649,13 +3652,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
private boolean getAllowSubdomainAccessGlobal() {
return _allowSubdomainNetworkAccess;
}
@Override
public List<Pair<TrafficType, String>> listTrafficTypeImplementor(ListTrafficTypeImplementorsCmd cmd) {
@ -3680,7 +3683,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return results;
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true)
public IpAddress associateIPToNetwork(long ipId, long networkId) throws InsufficientAddressCapacityException,
@ -3696,20 +3699,20 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
" to VPC.Specify vpcId to associate ip address to VPC");
}
return _networkMgr.associateIPToGuestNetwork(ipId, networkId, true);
}
@Override @DB
public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId,
String vlan, String startIp, String endIp, String gateway, String netmask, long networkOwnerId, Long vpcId, Boolean sourceNat)
throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
Account owner = _accountMgr.getAccount(networkOwnerId);
// Get system network offeirng
NetworkOfferingVO ntwkOff = findSystemNetworkOffering(NetworkOffering.SystemPrivateGatewayNetworkOffering);
// Validate physical network
PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
if (pNtwk == null) {
@ -3718,7 +3721,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
ex.addProxyObject("physical_network", physicalNetworkId, "physicalNetworkId");
throw ex;
}
// VALIDATE IP INFO
// if end ip is not specified, default it to startIp
if (!NetUtils.isValidIp(startIp)) {
@ -3739,49 +3742,49 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
Transaction txn = Transaction.currentTxn();
txn.start();
//lock datacenter as we need to get mac address seq from there
DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true);
//check if we need to create guest network
Network privateNetwork = _networksDao.getPrivateNetwork(BroadcastDomainType.Vlan.toUri(vlan).toString(), cidr,
networkOwnerId, pNtwk.getDataCenterId());
if (privateNetwork == null) {
//create Guest network
privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan,
privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan,
null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, null, null, null);
s_logger.debug("Created private network " + privateNetwork);
} else {
s_logger.debug("Private network already exists: " + privateNetwork);
}
//add entry to private_ip_address table
PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkId(privateNetwork.getId(), startIp);
if (privateIp != null) {
throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" +
" in zone " + _configMgr.getZone(pNtwk.getDataCenterId()).getName());
}
Long mac = dc.getMacAddress();
Long nextMac = mac + 1;
dc.setMacAddress(nextMac);
privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac, vpcId, sourceNat);
_privateIpDao.persist(privateIp);
_dcDao.update(dc.getId(), dc);
txn.commit();
s_logger.debug("Private network " + privateNetwork + " is created");
return privateNetwork;
}
private NetworkOfferingVO findSystemNetworkOffering(String offeringName) {
List<NetworkOfferingVO> allOfferings = _networkOfferingDao.listSystemNetworkOfferings();
for (NetworkOfferingVO offer: allOfferings){

View File

@ -73,7 +73,7 @@ public class ConsoleProxyServlet extends HttpServlet {
@Inject AccountManager _accountMgr;
@Inject VirtualMachineManager _vmMgr;
@Inject ManagementServer _ms;
@Inject IdentityService _identityService;
@Inject IdentityService _identityService;
static ManagementServer s_ms;
@ -81,13 +81,13 @@ public class ConsoleProxyServlet extends HttpServlet {
public ConsoleProxyServlet() {
}
@Override
public void init(ServletConfig config) throws ServletException {
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
s_ms = _ms;
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
doGet(req, resp);
@ -274,7 +274,7 @@ public class ConsoleProxyServlet extends HttpServlet {
private void handleAuthRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) {
// TODO authentication channel between console proxy VM and management server needs to be secured,
// TODO authentication channel between console proxy VM and management server needs to be secured,
// the data is now being sent through private network, but this is apparently not enough
VMInstanceVO vm = _vmMgr.findById(vmId);
if(vm == null) {
@ -334,11 +334,11 @@ public class ConsoleProxyServlet extends HttpServlet {
private String getEncryptorPassword() {
String key = _ms.getEncryptionKey();
String iv = _ms.getEncryptionIV();
ConsoleProxyPasswordBasedEncryptor.KeyIVPair keyIvPair = new ConsoleProxyPasswordBasedEncryptor.KeyIVPair(key, iv);
return _gson.toJson(keyIvPair);
}
private String composeThumbnailUrl(String rootUrl, VMInstanceVO vm, HostVO hostVo, int w, int h) {
StringBuffer sb = new StringBuffer(rootUrl);
@ -385,8 +385,7 @@ public class ConsoleProxyServlet extends HttpServlet {
Ternary<String, String, String> parsedHostInfo = parseHostInfo(portInfo.first());
String sid = vm.getVncPassword();
String tag = String.valueOf(vm.getId());
tag = _identityService.getIdentityUuid("vm_instance", tag);
String tag = vm.getUuid();
String ticket = genAccessTicket(host, String.valueOf(portInfo.second()), sid, tag);
ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(getEncryptorPassword());
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
@ -473,12 +472,12 @@ public class ConsoleProxyServlet extends HttpServlet {
} catch (PermissionDeniedException ex) {
if (accountObj.getType() == Account.ACCOUNT_TYPE_NORMAL) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
+ " does not match the account id in session " + accountObj.getId() + " and caller is a normal user");
}
} else if(accountObj.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || accountObj.getType() == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
+ " does not match the account id in session " + accountObj.getId() + " and the domain-admin caller does not manage the target domain");
}
}
@ -515,7 +514,7 @@ public class ConsoleProxyServlet extends HttpServlet {
account = _accountMgr.getAccount(user.getAccountId());
}
if ((user == null) || (user.getRemoved() != null) || !user.getState().equals(Account.State.enabled)
if ((user == null) || (user.getRemoved() != null) || !user.getState().equals(Account.State.enabled)
|| (account == null) || !account.getState().equals(Account.State.enabled)) {
s_logger.warn("Deleted/Disabled/Locked user with id=" + userId + " attempting to access public API");
return false;
@ -586,7 +585,7 @@ public class ConsoleProxyServlet extends HttpServlet {
if (!user.getState().equals(Account.State.enabled) || !account.getState().equals(Account.State.enabled)) {
s_logger.debug("disabled or locked user accessing the api, userid = " + user.getId() + "; name = " + user.getUsername() + "; state: " + user.getState() + "; accountState: " + account.getState());
return false;
}
}
// verify secret key exists
secretKey = user.getSecretKey();
@ -632,10 +631,10 @@ public class ConsoleProxyServlet extends HttpServlet {
case '>': sb.append("&gt;"); break;
case '&': sb.append("&amp;"); break;
case '"': sb.append("&quot;"); break;
case ' ': sb.append("&nbsp;");break;
case ' ': sb.append("&nbsp;");break;
default: sb.append(c); break;
}
}
return sb.toString();
}
}
}

View File

@ -19,6 +19,7 @@ package com.cloud.network.security;
import java.io.IOException;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -60,7 +61,6 @@ import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.user.AccountManager;
import com.cloud.user.DomainManager;
import com.cloud.user.dao.AccountDaoImpl;
import com.cloud.utils.component.SpringComponentScanUtils;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.NicDaoImpl;
@ -151,7 +151,7 @@ public class SecurityGroupManagerTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = SecurityGroupManagerTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -19,6 +19,7 @@ package com.cloud.snapshot;
import java.io.IOException;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
@ -36,7 +37,6 @@ import com.cloud.host.dao.HostTagsDaoImpl;
import com.cloud.storage.dao.SnapshotDaoImpl;
import com.cloud.storage.dao.VolumeDaoImpl;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.SpringComponentScanUtils;
import com.cloud.vm.dao.NicDaoImpl;
import com.cloud.vm.dao.VMInstanceDaoImpl;
@ -65,7 +65,7 @@ public class SnapshotDaoTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = SnapshotDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -20,6 +20,7 @@ package com.cloud.storage.dao;
import java.io.IOException;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
@ -28,7 +29,6 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import com.cloud.utils.component.SpringComponentScanUtils;
@Configuration
@ComponentScan(basePackageClasses={
@ -46,7 +46,7 @@ public class StoragePoolDaoTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = StoragePoolDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -19,6 +19,7 @@ package com.cloud.vm.dao;
import java.io.IOException;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
@ -27,7 +28,6 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import com.cloud.utils.component.SpringComponentScanUtils;
import com.cloud.vm.dao.UserVmCloneSettingDaoImpl;
@Configuration
@ -45,7 +45,7 @@ public class UserVmCloneSettingDaoTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = UserVmCloneSettingDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -19,6 +19,7 @@ package com.cloud.vm.dao;
import java.io.IOException;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
@ -27,7 +28,6 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import com.cloud.utils.component.SpringComponentScanUtils;
@Configuration
@ComponentScan(basePackageClasses={
@ -43,7 +43,7 @@ public class UserVmDaoTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = UserVmDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -19,6 +19,7 @@ package com.cloud.vpc;
import java.io.IOException;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -91,7 +92,6 @@ import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.user.AccountManager;
import com.cloud.user.dao.AccountDaoImpl;
import com.cloud.user.dao.UserStatisticsDaoImpl;
import com.cloud.utils.component.SpringComponentScanUtils;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.dao.DomainRouterDaoImpl;
import com.cloud.vm.dao.NicDaoImpl;
@ -236,7 +236,7 @@ public class VpcTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = VpcTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}
}

View File

@ -24,6 +24,7 @@ import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -32,13 +33,23 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.cloud.event.EventUtils;
import com.cloud.event.EventVO;
@ -48,6 +59,7 @@ import com.cloud.exception.ResourceInUseException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountService;
import com.cloud.user.AccountVO;
import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
@ -57,7 +69,7 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.dao.UserVmDao;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/affinityContext.xml")
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
public class AffinityApiUnitTest {
@Inject
@ -188,4 +200,57 @@ public class AffinityApiUnitTest {
_affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
}
@Configuration
@ComponentScan(basePackageClasses = {AffinityGroupServiceImpl.class, EventUtils.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)}, useDefaultFilters = false)
public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
@Bean
public AccountDao accountDao() {
return Mockito.mock(AccountDao.class);
}
@Bean
public AccountService accountService() {
return Mockito.mock(AccountService.class);
}
@Bean
public AffinityGroupProcessor affinityGroupProcessor() {
return Mockito.mock(AffinityGroupProcessor.class);
}
@Bean
public AffinityGroupDao affinityGroupDao() {
return Mockito.mock(AffinityGroupDao.class);
}
@Bean
public AffinityGroupVMMapDao affinityGroupVMMapDao() {
return Mockito.mock(AffinityGroupVMMapDao.class);
}
@Bean
public AccountManager accountManager() {
return Mockito.mock(AccountManager.class);
}
@Bean
public EventDao eventDao() {
return Mockito.mock(EventDao.class);
}
@Bean
public UserVmDao userVMDao() {
return Mockito.mock(UserVmDao.class);
}
public static class Library implements TypeFilter {
@Override
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}
}
}

View File

@ -27,6 +27,7 @@ import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -94,7 +95,6 @@ import com.cloud.storage.swift.SwiftManager;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.user.dao.AccountDaoImpl;
import com.cloud.user.dao.UserDaoImpl;
import com.cloud.utils.component.SpringComponentScanUtils;
import com.cloud.vm.dao.InstanceGroupDaoImpl;
import com.cloud.vm.dao.NicDaoImpl;
import com.cloud.vm.dao.NicSecondaryIpDaoImpl;
@ -338,7 +338,7 @@ public class ChildTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -1,42 +0,0 @@
<!-- 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 />
<!-- @DB support -->
<bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
<bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
<bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
<property name="Interceptors">
<list>
<ref bean="transactionContextBuilder" />
<ref bean="actionEventInterceptor" />
</list>
</property>
</bean>
<bean class="org.apache.cloudstack.affinity.AffinityApiTestConfiguration" />
</beans>

View File

@ -23,9 +23,9 @@
<packaging>pom</packaging>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack</artifactId>
<artifactId>cloudstack-services</artifactId>
<version>4.2.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
<defaultGoal>install</defaultGoal>

View File

@ -18,13 +18,13 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloudstack-service-secondary-storage</artifactId>
<artifactId>cloud-secondary-storage</artifactId>
<name>Apache CloudStack Secondary Storage Service</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack</artifactId>
<artifactId>cloudstack-services</artifactId>
<version>4.2.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>

View File

@ -1,15 +1,14 @@
<!-- 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. -->
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. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-marvin</artifactId>
<name>Apache CloudStack marvin</name>
@ -35,7 +34,7 @@
</goals>
<configuration>
<target>
<delete dir="marvin/cloudstackAPI"/>
<delete dir="marvin/cloudstackAPI" />
<echo>Deleting ${project.artifactId} API sources</echo>
</target>
</configuration>
@ -83,7 +82,7 @@
</plugin>
</plugins>
</build>
<!-- Custom profiles for sync and integration tests-->
<!-- Custom profiles for sync and integration tests -->
<profiles>
<profile>
<id>marvin.sync</id>
@ -160,6 +159,26 @@
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>setproperty</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
pom.properties['resolved.basedir']=project.basedir.absolutePath.replace('\','/').replace('D:','/cyg/d');
pom.properties['resolved.userdir']='${user.dir}'.replace('\','/').replace('D:','/cyg/d');
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
@ -177,18 +196,18 @@
<arguments>
<argument>deployAndRun.py</argument>
<argument>-c</argument>
<argument>${user.dir}/${marvin.config}</argument>
<argument>${resolved.userdir}/${marvin.config}</argument>
<argument>-t</argument>
<argument>/tmp/t.log</argument>
<argument>-r</argument>
<argument>/tmp/r.log</argument>
<argument>-f</argument>
<argument>${basedir}/marvin/testSetupSuccess.py</argument>
<argument>${resolved.basedir}/marvin/testSetupSuccess.py</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</executions>
</plugin>
</plugins>
</build>
</profile>

View File

@ -25,7 +25,8 @@ import com.cloud.usage.dao.*;
import com.cloud.usage.parser.*;
import com.cloud.user.dao.AccountDaoImpl;
import com.cloud.user.dao.UserStatisticsDaoImpl;
import com.cloud.utils.component.SpringComponentScanUtils;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -87,7 +88,7 @@ public class UsageManagerTestConfiguration {
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
mdr.getClassMetadata().getClassName();
ComponentScan cs = UsageManagerTestConfiguration.class.getAnnotation(ComponentScan.class);
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
}
}

View File

@ -20,40 +20,38 @@ import javax.persistence.Table;
import org.apache.log4j.Logger;
import com.cloud.utils.exception.CSExceptionErrorCode;
public class AnnotationHelper extends Object {
// This class contains routines to help query annotation elements of objects.
public static final Logger s_logger = Logger.getLogger(AnnotationHelper.class.getName());
public static String getTableName(Object proxyObj) {
// The cglib class is generated by cglib during runtime.
Class<?> curClass = proxyObj.getClass();
if (curClass == null) {
s_logger.info("\nCould not retrieve class information for proxy object\n");
s_logger.trace("Could not retrieve class information for proxy object");
return null;
}
while (curClass.getSuperclass() != null && curClass.getSuperclass().getName() != "java.lang.Object") {
curClass = curClass.getSuperclass();
}
// At this point, curClass is the root base class of proxyObj's class, and curClass is not java.lang.Object.
Table tabObj = (Table)curClass.getAnnotation(Table.class);
Table tabObj = curClass.getAnnotation(Table.class);
if (tabObj == null) {
s_logger.info("\n" + curClass + "does not have a Table annotation\n");
s_logger.trace(curClass + "does not have a Table annotation");
return null;
}
return tabObj.name();
}
}

View File

@ -1,41 +0,0 @@
// 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.utils.component;
import org.springframework.context.annotation.ComponentScan;
import com.cloud.utils.exception.CloudRuntimeException;
public class SpringComponentScanUtils {
public static boolean includedInBasePackageClasses(String clazzName, ComponentScan cs) {
Class<?> clazzToCheck;
try {
clazzToCheck = Class.forName(clazzName);
} catch (ClassNotFoundException e) {
throw new CloudRuntimeException("Unable to find " + clazzName);
}
Class<?>[] clazzes = cs.basePackageClasses();
for (Class<?> clazz : clazzes) {
if (clazzToCheck.isAssignableFrom(clazz)) {
return true;
}
}
return false;
}
}

View File

@ -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
// 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.test.utils;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.ComponentInstantiationPostProcessor;
import com.cloud.utils.component.ComponentMethodInterceptor;
import com.cloud.utils.db.TransactionContextBuilder;
import com.cloud.utils.exception.CloudRuntimeException;
public class SpringUtils {
/**
* This method allows you to use @ComponentScan for your unit testing but
* it limits the scope of the classes found to the class specified in
* the @ComponentScan annotation.
*
* Without using this method, the default behavior of @ComponentScan is
* to actually scan in the package of the class specified rather than
* only the class. This can cause extra classes to be loaded which causes
* the classes these extra classes depend on to be loaded. The end effect
* is often most of the project gets loaded.
*
* In order to use this method properly, you must do the following: <li>
* - Specify @ComponentScan with basePackageClasses, includeFilters, and
* useDefaultFilters=true. See the following example.
*
* <pre>
* @ComponentScan(basePackageClasses={AffinityGroupServiceImpl.class, EventUtils.class},
* includeFilters={@Filter(value=TestConfiguration.Library.class, type=FilterType.CUSTOM)},
* useDefaultFilters=false)
* </pre>
*
* - Create a Library class and use that to call this method. See the
* following example. The Library class you define here is the Library
* class being added in the filter above.
*
* <pre>
* public static class Library implements TypeFilter {
* @Override
* public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
* ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
* return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
* }
* }
* </pre>
*
* @param clazzName name of the class that should be included in the Spring components
* @param cs ComponentScan annotation that was declared on the configuration
*
* @return
*/
public static boolean includedInBasePackageClasses(String clazzName, ComponentScan cs) {
Class<?> clazzToCheck;
try {
clazzToCheck = Class.forName(clazzName);
} catch (ClassNotFoundException e) {
throw new CloudRuntimeException("Unable to find " + clazzName);
}
Class<?>[] clazzes = cs.basePackageClasses();
for (Class<?> clazz : clazzes) {
if (clazzToCheck.isAssignableFrom(clazz)) {
return true;
}
}
return false;
}
public static class CloudStackTestConfiguration {
@Bean
public ComponentContext componentContext() {
return new ComponentContext();
}
@Bean
public TransactionContextBuilder transactionContextBuilder() {
return new TransactionContextBuilder();
}
@Bean
public ComponentInstantiationPostProcessor instantiatePostProcessor() {
ComponentInstantiationPostProcessor processor = new ComponentInstantiationPostProcessor();
List<ComponentMethodInterceptor> interceptors = new ArrayList<ComponentMethodInterceptor>();
interceptors.add(new TransactionContextBuilder());
processor.setInterceptors(interceptors);
return processor;
}
}
}