http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/296c2033/server/src/com/cloud/server/ConfigurationServerImpl.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/server/ConfigurationServerImpl.java index ebf140f,fa68514..5fa4c60 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@@ -77,56 -111,42 +111,42 @@@ import org.apache.cloudstack.region.dao import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; - import javax.crypto.KeyGenerator; - import javax.crypto.SecretKey; - import java.io.*; - import java.net.InetAddress; - import java.net.UnknownHostException; - import java.security.NoSuchAlgorithmException; - import java.sql.PreparedStatement; - import java.sql.ResultSet; - import java.sql.SQLException; - import java.util.*; - import java.util.regex.Pattern; - - public class ConfigurationServerImpl implements ConfigurationServer { + @Component + public class ConfigurationServerImpl extends ManagerBase implements ConfigurationServer { public static final Logger s_logger = Logger.getLogger(ConfigurationServerImpl.class.getName()); - private final ConfigurationDao _configDao; - private final DataCenterDao _zoneDao; - private final HostPodDao _podDao; - private final DiskOfferingDao _diskOfferingDao; - private final ServiceOfferingDao _serviceOfferingDao; - private final NetworkOfferingDao _networkOfferingDao; - private final DataCenterDao _dataCenterDao; - private final NetworkDao _networkDao; - private final VlanDao _vlanDao; + @Inject private ConfigurationDao _configDao; + @Inject private DataCenterDao _zoneDao; + @Inject private HostPodDao _podDao; + @Inject private DiskOfferingDao _diskOfferingDao; + @Inject private ServiceOfferingDao _serviceOfferingDao; + @Inject private NetworkOfferingDao _networkOfferingDao; + @Inject private DataCenterDao _dataCenterDao; + @Inject private NetworkDao _networkDao; + @Inject private VlanDao _vlanDao; private String _domainSuffix; - private final DomainDao _domainDao; - private final AccountDao _accountDao; - private final ResourceCountDao _resourceCountDao; - private final NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao; - private final IdentityDao _identityDao; - private final RegionDao _regionDao; + @Inject private DomainDao _domainDao; + @Inject private AccountDao _accountDao; + @Inject private ResourceCountDao _resourceCountDao; + @Inject private NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao; + @Inject private IdentityDao _identityDao; + @Inject private RegionDao _regionDao; public ConfigurationServerImpl() { - ComponentLocator locator = ComponentLocator.getLocator(Name); - _configDao = locator.getDao(ConfigurationDao.class); - _zoneDao = locator.getDao(DataCenterDao.class); - _podDao = locator.getDao(HostPodDao.class); - _diskOfferingDao = locator.getDao(DiskOfferingDao.class); - _serviceOfferingDao = locator.getDao(ServiceOfferingDao.class); - _networkOfferingDao = locator.getDao(NetworkOfferingDao.class); - _dataCenterDao = locator.getDao(DataCenterDao.class); - _networkDao = locator.getDao(NetworkDao.class); - _vlanDao = locator.getDao(VlanDao.class); - _domainDao = locator.getDao(DomainDao.class); - _accountDao = locator.getDao(AccountDao.class); - _resourceCountDao = locator.getDao(ResourceCountDao.class); - _ntwkOfferingServiceMapDao = locator.getDao(NetworkOfferingServiceMapDao.class); - _identityDao = locator.getDao(IdentityDao.class); - _regionDao = locator.getDao(RegionDao.class); + setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK_BOOTSTRAP); + } + + @Override + public boolean configure(String name, Map<String, Object> params) + throws ConfigurationException { + + try { + persistDefaultValues(); + } catch (InternalErrorException e) { + throw new RuntimeException("Unhandled configuration exception", e); + } + return true; - } + } @Override @DB
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/296c2033/server/src/com/cloud/user/AccountManagerImpl.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/user/AccountManagerImpl.java index 23cd5b9,4fc849e..54447a2 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@@ -272,12 -266,10 +266,10 @@@ public class AccountManagerImpl extend @Override public UserVO getSystemUser() { - return _systemUser; + if (_systemUser == null) { + _systemUser = _userDao.findById(User.UID_SYSTEM); - } + } - - @Override - public String getName() { - return _name; + return _systemUser; } @Override @@@ -1755,20 -1748,8 +1748,19 @@@ if (s_logger.isDebugEnabled()) { s_logger.debug("Creating user: " + userName + ", accountId: " + accountId + " timezone:" + timezone); } - - UserVO user = _userDao.persist(new UserVO(accountId, userName, password, firstName, lastName, email, timezone, UUID.randomUUID().toString(), _regionMgr.getId())); + + String encodedPassword = null; - for (Enumeration<UserAuthenticator> en = _userAuthenticators.enumeration(); en.hasMoreElements();) { - UserAuthenticator authenticator = en.nextElement(); ++ for (UserAuthenticator authenticator : _userAuthenticators) { + encodedPassword = authenticator.encode(password); + if (encodedPassword != null) { + break; + } + } + if (encodedPassword == null) { + throw new CloudRuntimeException("Failed to encode password"); + } + + UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, UUID.randomUUID().toString(), _regionMgr.getId())); return user; } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/296c2033/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java index afa6545,ee06a97..390a2a2 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@@ -67,10 -138,20 +138,21 @@@ import com.cloud.network.* import com.cloud.network.Network.IpAddresses; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; + import com.cloud.network.NetworkManager; + import com.cloud.network.NetworkModel; import com.cloud.network.Networks.TrafficType; - import com.cloud.network.dao.*; + import com.cloud.network.PhysicalNetwork; + import com.cloud.network.dao.FirewallRulesDao; + import com.cloud.network.dao.IPAddressDao; + import com.cloud.network.dao.IPAddressVO; + import com.cloud.network.dao.LoadBalancerVMMapDao; + import com.cloud.network.dao.LoadBalancerVMMapVO; + import com.cloud.network.dao.NetworkDao; + import com.cloud.network.dao.NetworkServiceMapDao; + import com.cloud.network.dao.NetworkVO; + import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.element.UserDataServiceProvider; +import com.cloud.network.guru.NetworkGuru; import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.rules.FirewallManager; import com.cloud.network.rules.FirewallRuleVO; @@@ -281,7 -386,9 +388,9 @@@ public class UserVmManagerImpl extends PhysicalNetworkDao _physicalNetworkDao; @Inject VpcManager _vpcMgr; - @Inject + @Inject + protected GuestOSCategoryDao _guestOSCategoryDao; + @Inject UsageEventDao _usageEventDao; protected ScheduledExecutorService _executor = null; @@@ -632,16 -790,17 +792,17 @@@ } } - //permission check + // permission check _accountMgr.checkAccess(caller, null, true, volume, vm); - //Check if volume is stored on secondary Storage. + // Check if volume is stored on secondary Storage. boolean isVolumeOnSec = false; - VolumeHostVO volHostVO = _volumeHostDao.findByVolumeId(volume.getId()); + VolumeHostVO volHostVO = _volumeHostDao.findByVolumeId(volume.getId()); - if (volHostVO != null){ + if (volHostVO != null) { isVolumeOnSec = true; - if( !(volHostVO.getDownloadState() == Status.DOWNLOADED) ){ - throw new InvalidParameterValueException("Volume is not uploaded yet. Please try this operation once the volume is uploaded"); + if (!(volHostVO.getDownloadState() == Status.DOWNLOADED)) { + throw new InvalidParameterValueException( + "Volume is not uploaded yet. Please try this operation once the volume is uploaded"); } } @@@ -844,12 -1087,17 +1089,17 @@@ } @Override - @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DETACH, eventDescription = "detaching volume", async = true) + @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DETACH, eventDescription = "detaching volume", async = true) public Volume detachVolumeFromVM(DetachVolumeCmd cmmd) { Account caller = UserContext.current().getCaller(); - if ((cmmd.getId() == null && cmmd.getDeviceId() == null && cmmd.getVirtualMachineId() == null) || (cmmd.getId() != null && (cmmd.getDeviceId() != null || cmmd.getVirtualMachineId() != null)) - || (cmmd.getId() == null && (cmmd.getDeviceId() == null || cmmd.getVirtualMachineId() == null))) { - throw new InvalidParameterValueException("Please provide either a volume id, or a tuple(device id, instance id)"); + if ((cmmd.getId() == null && cmmd.getDeviceId() == null && cmmd + .getVirtualMachineId() == null) + || (cmmd.getId() != null && (cmmd.getDeviceId() != null || cmmd + .getVirtualMachineId() != null)) + || (cmmd.getId() == null && (cmmd.getDeviceId() == null || cmmd + .getVirtualMachineId() == null))) { + throw new InvalidParameterValueException( + "Please provide either a volume id, or a tuple(device id, instance id)"); } Long volumeId = cmmd.getId(); @@@ -2466,9 -2949,10 +2951,10 @@@ // if network is security group enabled, and no security group is specified, then add the default security group automatically if (isSecurityGroupEnabledNetworkUsed && !isVmWare && _networkModel.canAddDefaultSecurityGroup()) { - + - //add the default securityGroup only if no security group is specified - if(securityGroupIdList == null || securityGroupIdList.isEmpty()){ + // add the default securityGroup only if no security group is + // specified + if (securityGroupIdList == null || securityGroupIdList.isEmpty()) { if (securityGroupIdList == null) { securityGroupIdList = new ArrayList<Long>(); } @@@ -2562,13 -3075,17 +3077,17 @@@ } } - + _networkModel.checkNetworkPermissions(owner, network); - //don't allow to use system networks - NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); + // don't allow to use system networks + NetworkOffering networkOffering = _configMgr + .getNetworkOffering(network.getNetworkOfferingId()); if (networkOffering.isSystemOnly()) { - throw new InvalidParameterValueException("Network id=" + networkId + " is system only and can't be used for vm deployment"); + throw new InvalidParameterValueException( + "Network id=" + + networkId + + " is system only and can't be used for vm deployment"); } networkList.add(network); } @@@ -2626,19 -3151,27 +3153,27 @@@ } // check if we have available pools for vm deployment - long availablePools = _storagePoolDao.countPoolsByStatus(StoragePoolStatus.Up); + long availablePools = _storagePoolDao + .countPoolsByStatus(StoragePoolStatus.Up); - if (availablePools < 1) { + if (availablePools < 1) { - throw new StorageUnavailableException("There are no available pools in the UP state for vm deployment", -1); + throw new StorageUnavailableException( + "There are no available pools in the UP state for vm deployment", + -1); } - ServiceOfferingVO offering = _serviceOfferingDao.findById(serviceOffering.getId()); + ServiceOfferingVO offering = _serviceOfferingDao + .findById(serviceOffering.getId()); if (template.getTemplateType().equals(TemplateType.SYSTEM)) { - throw new InvalidParameterValueException("Unable to use system template " + template.getId() + " to deploy a user vm"); + throw new InvalidParameterValueException( + "Unable to use system template " + template.getId() + + " to deploy a user vm"); } - List<VMTemplateZoneVO> listZoneTemplate = _templateZoneDao.listByZoneTemplate(zone.getId(), template.getId()); + List<VMTemplateZoneVO> listZoneTemplate = _templateZoneDao + .listByZoneTemplate(zone.getId(), template.getId()); if (listZoneTemplate == null || listZoneTemplate.isEmpty()) { - throw new InvalidParameterValueException("The template " + template.getId() + " is not available for use"); + throw new InvalidParameterValueException("The template " + + template.getId() + " is not available for use"); } if (isIso && !template.isBootable()) { @@@ -2776,12 -3291,13 +3293,13 @@@ if (hostName == null) { hostName = uuidName; } else { - //1) check is hostName is RFC complient + // 1) check is hostName is RFC complient if (!NetUtils.verifyDomainNameLabel(hostName, true)) { - throw new InvalidParameterValueException("Invalid name. Vm name can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + throw new InvalidParameterValueException( + "Invalid name. Vm name can contain ASCII letters 'a' through 'z', the digits '0' through '9', " - + "and the hyphen ('-'), must be between 1 and 63 characters long, and can't start or end with \"-\" and can't start with digit"); + + "and the hyphen ('-'), must be between 1 and 63 characters long, and can't start or end with \"-\" and can't start with digit"); } - //2) hostName has to be unique in the network domain + // 2) hostName has to be unique in the network domain Map<String, List<Long>> ntwkDomains = new HashMap<String, List<Long>>(); for (NetworkVO network : networkList) { String ntwkDomain = network.getNetworkDomain(); @@@ -2836,12 -3362,26 +3364,26 @@@ s_logger.debug("Allocating in the DB for vm"); DataCenterDeployment plan = new DataCenterDeployment(zone.getId()); - if (_itMgr.allocate(vm, _templateDao.findById(template.getId()), offering, rootDiskOffering, dataDiskOfferings, networks, null, plan, hypervisorType, owner) == null) { - return null; + + long guestOSId = template.getGuestOSId(); + GuestOSVO guestOS = _guestOSDao.findById(guestOSId); + long guestOSCategoryId = guestOS.getCategoryId(); + GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId); + + List<String> computeTags = new ArrayList<String>(); + computeTags.add(offering.getHostTag()); + + List<String> rootDiskTags = new ArrayList<String>(); + rootDiskTags.add(offering.getTags()); + + if(isIso){ + VirtualMachineEntity vmEntity = _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), new Long(owner.getAccountId()).toString(), vm.getIsoId().toString(), hostName, displayName, hypervisor.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan); + }else { + VirtualMachineEntity vmEntity = _orchSrvc.createVirtualMachine(vm.getUuid(), new Long(owner.getAccountId()).toString(), new Long(template.getId()).toString(), hostName, displayName, hypervisor.name(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan); } - _vmDao.saveDetails(vm); + - + if (s_logger.isDebugEnabled()) { s_logger.debug("Successfully allocated DB entry for " + vm); } @@@ -2908,8 -3457,10 +3459,10 @@@ return startVirtualMachine(cmd, null); } - protected UserVm startVirtualMachine(DeployVMCmd cmd, Map<VirtualMachineProfile.Param, Object> additonalParams) throws ResourceUnavailableException, InsufficientCapacityException, + protected UserVm startVirtualMachine(DeployVMCmd cmd, + Map<VirtualMachineProfile.Param, Object> additonalParams) + throws ResourceUnavailableException, InsufficientCapacityException, - ConcurrentOperationException { + ConcurrentOperationException { long vmId = cmd.getEntityId(); Long hostId = cmd.getHostId(); @@@ -3508,8 -4133,10 +4135,10 @@@ } @Override - public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, + public UserVm createVirtualMachine(DeployVMCmd cmd) + throws InsufficientCapacityException, ResourceUnavailableException, + ConcurrentOperationException, StorageUnavailableException, - ResourceAllocationException { + ResourceAllocationException { // TODO Auto-generated method stub return null; } @@@ -3796,15 -4499,17 +4501,17 @@@ List<Long> securityGroupIdList = cmd.getSecurityGroupIdList(); if (zone.getNetworkType() == NetworkType.Basic) { - if (networkIdList != null && !networkIdList.isEmpty()) { + if (networkIdList != null && !networkIdList.isEmpty()) { - throw new InvalidParameterValueException("Can't move vm with network Ids; this is a basic zone VM"); + throw new InvalidParameterValueException( + "Can't move vm with network Ids; this is a basic zone VM"); - } + } - //cleanup the old security groups + // cleanup the old security groups - _securityGroupMgr.removeInstanceFromGroups(cmd.getVmId()); + _securityGroupMgr.removeInstanceFromGroups(cmd.getVmId()); - //cleanup the network for the oldOwner + // cleanup the network for the oldOwner _networkMgr.cleanupNics(vmOldProfile); _networkMgr.expungeNics(vmOldProfile); - //security groups will be recreated for the new account, when the VM is started + // security groups will be recreated for the new account, when the + // VM is started List<NetworkVO> networkList = new ArrayList<NetworkVO>(); // Get default guest network in Basic zone @@@ -3852,24 -4565,31 +4567,31 @@@ List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(); NicProfile profile = new NicProfile(); profile.setDefaultNic(true); - networks.add(new Pair<NetworkVO, NicProfile>(networkList.get(0), profile)); + networks.add(new Pair<NetworkVO, NicProfile>(networkList.get(0), + profile)); VMInstanceVO vmi = _itMgr.findByIdAndType(vm.getType(), vm.getId()); - VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmi); + VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>( + vmi); _networkMgr.allocate(vmProfile, networks); - _securityGroupMgr.addInstanceToGroups(vm.getId(), securityGroupIdList); + _securityGroupMgr.addInstanceToGroups(vm.getId(), + securityGroupIdList); - s_logger.debug("AssignVM: Basic zone, adding security groups no " + securityGroupIdList.size() + " to " + vm.getInstanceName() ); + s_logger.debug("AssignVM: Basic zone, adding security groups no " + + securityGroupIdList.size() + " to " + + vm.getInstanceName()); } else { - if (zone.isSecurityGroupEnabled()) { + if (zone.isSecurityGroupEnabled()) { - throw new InvalidParameterValueException("Not yet implemented for SecurityGroupEnabled advanced networks."); + throw new InvalidParameterValueException( + "Not yet implemented for SecurityGroupEnabled advanced networks."); } else { - if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) { - throw new InvalidParameterValueException("Can't move vm with security groups; security group feature is not enabled in this zone"); + if (securityGroupIdList != null + && !securityGroupIdList.isEmpty()) { + throw new InvalidParameterValueException( + "Can't move vm with security groups; security group feature is not enabled in this zone"); } - //cleanup the network for the oldOwner + // cleanup the network for the oldOwner _networkMgr.cleanupNics(vmOldProfile); _networkMgr.expungeNics(vmOldProfile); @@@ -3919,34 -4646,12 +4648,36 @@@ Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), newAccount.getAccountName() + "-network", newAccount.getAccountName() + "-network", null, null, null, null, newAccount, null, physicalNetwork, zone.getId(), ACLType.Account, null, null, null, null); + // if the network offering has persistent set to true, implement the network + if (requiredOfferings.get(0).getIsPersistent()) { + DeployDestination dest = new DeployDestination(zone, null, null, null); + UserVO callerUser = _userDao.findById(UserContext.current().getCallerUserId()); + Journal journal = new Journal.LogJournal("Implementing " + newNetwork, s_logger); + ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), + journal, callerUser, caller); + s_logger.debug("Implementing the network for account" + newNetwork + " as a part of" + + " network provision for persistent networks"); + try { + Pair<NetworkGuru, NetworkVO> implementedNetwork = _networkMgr.implementNetwork(newNetwork.getId(), dest, context); + if (implementedNetwork.first() == null) { + s_logger.warn("Failed to implement the network " + newNetwork); + } + newNetwork = implementedNetwork.second(); + } catch (Exception ex) { + s_logger.warn("Failed to implement network " + newNetwork + " elements and" + + " resources as a part of network provision for persistent network due to ", ex); + CloudRuntimeException e = new CloudRuntimeException("Failed to implement network" + + " (with specified id) elements and resources as a part of network provision"); + e.addProxyObject(newNetwork, newNetwork.getId(), "networkId"); + throw e; + } + } defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { - throw new InvalidParameterValueException("More than 1 default Isolated networks are found " + - "for account " + newAccount + "; please specify networkIds"); + throw new InvalidParameterValueException( + "More than 1 default Isolated networks are found " + + "for account " + newAccount + + "; please specify networkIds"); } else { defaultNetwork = _networkDao.findById(virtualNetworks.get(0).getId()); } @@@ -4068,8 -4797,9 +4823,9 @@@ @Override public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + ReservationContext context, DeployDestination dest) + throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { + InsufficientCapacityException { UserVmVO vmVO = _vmDao.findById(vm.getId()); if (vmVO.getState() == State.Running) { try { http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/296c2033/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/296c2033/server/test/com/cloud/vpc/MockNetworkManagerImpl.java ---------------------------------------------------------------------- diff --cc server/test/com/cloud/vpc/MockNetworkManagerImpl.java index 382068a,534df1c..bcaaa26 --- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java @@@ -91,9 -93,10 +93,10 @@@ public class MockNetworkManagerImpl ext NetworkServiceMapDao _ntwkSrvcDao; @Inject NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao; - @Inject(adapter = NetworkElement.class) - Adapters<NetworkElement> _networkElements; + + @Inject + List<NetworkElement> _networkElements; - + private static HashMap<String, String> s_providerToNetworkElementMap = new HashMap<String, String>(); private static final Logger s_logger = Logger.getLogger(MockNetworkManagerImpl.class); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/296c2033/server/test/com/cloud/vpc/dao/MockNetworkOfferingDaoImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/296c2033/setup/db/create-schema.sql ----------------------------------------------------------------------
