missing mac fields

This commit is contained in:
Alex Huang 2010-12-10 17:20:13 -08:00
parent 790bf40be6
commit 7cfbd5b7e0
8 changed files with 65 additions and 20 deletions

View File

@ -156,6 +156,7 @@ public enum Config {
DirectAttachNetworkExternalAPIURL("Advanced", ManagementServer.class, String.class, "direct.attach.network.externalIpAllocator.url", null, "Direct-attach VMs using external DHCP server (API url)", null),
CheckPodCIDRs("Advanced", ManagementServer.class, String.class, "check.pod.cidrs", "true", "If true, different pods must belong to different CIDR subnets.", "true,false"),
MD5Hashed("Advanced", ManagementServer.class, Boolean.class, "security.password.md5hashed", "true", "If set to false password is sent in clear text or else md5hashed", null),
NetworkGcWait("Advanced", ManagementServer.class, Integer.class, "network.gc.wait", "600", "Seconds to wait before shutting down a network that's not in used", null),
ControlCidr("Advanced", ManagementServer.class, String.class, "control.cidr", "169.254.0.0/16", "Changes the cidr for the control network traffic. Defaults to using link local. Must be unique within pods", null),
ControlGateway("Advanced", ManagementServer.class, String.class, "control.gateway", "169.254.0.1", "gateway for the control network traffic", null),
@ -270,18 +271,19 @@ public enum Config {
}
public String getComponent() {
if (_componentClass == ManagementServer.class)
return "management-server";
else if (_componentClass == AgentManager.class)
return "AgentManager";
else if (_componentClass == UserVmManager.class)
return "UserVmManager";
else if (_componentClass == HighAvailabilityManager.class)
return "HighAvailabilityManager";
else if (_componentClass == StoragePoolAllocator.class)
return "StorageAllocator";
else
return "none";
if (_componentClass == ManagementServer.class) {
return "management-server";
} else if (_componentClass == AgentManager.class) {
return "AgentManager";
} else if (_componentClass == UserVmManager.class) {
return "UserVmManager";
} else if (_componentClass == HighAvailabilityManager.class) {
return "HighAvailabilityManager";
} else if (_componentClass == StoragePoolAllocator.class) {
return "StorageAllocator";
} else {
return "none";
}
}
public String getRange() {
@ -302,8 +304,9 @@ public enum Config {
for (String category : categories) {
List<Config> currentList = getConfigs(category);
for (Config c : currentList) {
if (c.key().equals(name))
return c;
if (c.key().equals(name)) {
return c;
}
}
}

View File

@ -56,6 +56,9 @@ public class DataCenterIpAddressVO {
@Column(name="instance_id")
private Long instanceId;
@Column(name="mac_address")
long macAddress;
protected DataCenterIpAddressVO() {
}
@ -104,4 +107,8 @@ public class DataCenterIpAddressVO {
public Date getTakenAt() {
return takenAt;
}
public long getMacAddress() {
return macAddress;
}
}

View File

@ -26,7 +26,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ScheduledExecutorService;
import javax.ejb.Local;
@ -116,6 +115,7 @@ import com.cloud.user.UserStatisticsVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.Inject;
@ -184,13 +184,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Adapters<NetworkElement> _networkElements;
private HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5);
Random _rand = new Random(System.currentTimeMillis());
ScheduledExecutorService _executor;
SearchBuilder<AccountVO> AccountsUsingNetworkSearch;
SearchBuilder<IPAddressVO> AssignIpAddressSearch;
SearchBuilder<IPAddressVO> IpAddressSearch;
int _networkGcWait;
private Map<String, String> _configs;
@ -305,7 +305,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
assert(sourceNat != null) : "How do we get a bunch of ip addresses but none of them are source nat? account=" + ownerId + "; dc=" + dcId;
ip = new PublicIp(sourceNat, _vlanDao.findById(sourceNat.getVlanId()), sourceNat.getMacAddress() | 0x060000000000l | (((long)_rand.nextInt(32768) << 25) & 0x00fffe000000l));
ip = new PublicIp(sourceNat, _vlanDao.findById(sourceNat.getVlanId()), NetUtils.createSequenceBasedMacAddress(sourceNat.getMacAddress()));
}
UserStatisticsVO stats = _userStatsDao.findBy(ownerId, dcId);
@ -747,6 +747,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
validateRemoteAccessVpnConfiguration();
Integer rateMbps = getIntegerConfigValue(Config.NetworkThrottlingRate.key(), null);
Integer multicastRateMbps = getIntegerConfigValue(Config.MulticastThrottlingRate.key(), null);
_networkGcWait = NumbersUtil.parseInt(_configs.get(Config.NetworkGcWait.key()), 600);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmPublicNetwork, TrafficType.Public, null);
publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering);
@ -2047,7 +2048,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
long currentTime = System.currentTimeMillis() >> 10;
HashMap<Long, Long> stillFree = new HashMap<Long, Long>();
List<Long> networkIds = _nicDao.listNetworksWithNoActiveNics();
List<Long> networkIds = _networksDao.findNetworksToGarbageCollect();
for (Long networkId : networkIds) {
Long time = _lastNetworkIdsToFree.remove(networkId);
if (time == null) {
@ -2055,7 +2056,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
s_logger.debug("We found network " + networkId + " to be free for the first time. Adding it to the list: " + currentTime);
}
stillFree.put(networkId, currentTime);
} else if (time < (currentTime + 600)) {
} else if (time < (currentTime + _networkGcWait)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Network " + networkId + " is still free but it's not time to shutdown yet: " + time);
}

View File

@ -52,4 +52,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
void changeActiveNicsBy(long networkId, int nicsCount);
int getActiveNicsIn(long networkId);
List<Long> findNetworksToGarbageCollect();
void clearCheckForGc(long networkId);
}

View File

@ -219,4 +219,14 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
public int getActiveNicsIn(long networkId) {
return _opDao.getActiveNics(networkId);
}
@Override
public List<Long> findNetworksToGarbageCollect() {
return _opDao.getNetworksToGarbageCollect();
}
@Override
public void clearCheckForGc(long networkId) {
_opDao.clearCheckForGc(networkId);
}
}

View File

@ -51,6 +51,7 @@ public class NetworkOpDaoImpl extends GenericDaoBase<NetworkOpVO, Long> implemen
GarbageCollectSearch.selectField(GarbageCollectSearch.entity().getId());
GarbageCollectSearch.and("activenics", GarbageCollectSearch.entity().getActiveNicsCount(), Op.EQ);
GarbageCollectSearch.and("gc", GarbageCollectSearch.entity().isGarbageCollected(), Op.EQ);
GarbageCollectSearch.and("check", GarbageCollectSearch.entity().isCheckForGc(), Op.EQ);
GarbageCollectSearch.done();
_activeNicsAttribute = _allAttributes.get("activeNicsCount");
@ -61,6 +62,7 @@ public class NetworkOpDaoImpl extends GenericDaoBase<NetworkOpVO, Long> implemen
SearchCriteria<Long> sc = GarbageCollectSearch.create();
sc.setParameters("activenics", 0);
sc.setParameters("gc", true);
sc.setParameters("check", true);
return customSearch(sc, null);
}
@ -77,9 +79,16 @@ public class NetworkOpDaoImpl extends GenericDaoBase<NetworkOpVO, Long> implemen
sc.setParameters("network", networkId);
NetworkOpVO vo = createForUpdate();
vo.setCheckForGc(true);
UpdateBuilder builder = getUpdateBuilder(vo);
builder.incr(_activeNicsAttribute, count);
update(builder, sc, null);
}
public void clearCheckForGc(long networkId) {
NetworkOpVO vo = createForUpdate();
vo.setCheckForGc(false);
update(networkId, vo);
}
}

View File

@ -36,12 +36,16 @@ public class NetworkOpVO {
@Column(name="gc")
boolean garbageCollected;
@Column(name="check_for_gc")
boolean checkForGc;
protected NetworkOpVO() {
}
public NetworkOpVO(long id, boolean gc) {
this.id = id;
this.garbageCollected = gc;
this.checkForGc = gc;
this.activeNicsCount = 0;
}
@ -60,4 +64,12 @@ public class NetworkOpVO {
public boolean isGarbageCollected() {
return garbageCollected;
}
public boolean isCheckForGc() {
return checkForGc;
}
public void setCheckForGc(boolean check) {
checkForGc = check;
}
}

View File

@ -115,6 +115,7 @@ CREATE TABLE `cloud`.`op_networks`(
`mac_address_seq` bigint unsigned NOT NULL DEFAULT 1 COMMENT 'mac address',
`nics_count` int unsigned NOT NULL DEFAULT 0 COMMENT '# of nics',
`gc` tinyint unsigned NOT NULL DEFAULT 1 COMMENT 'gc this network or not',
`check_for_gc` tinyint unsigned NOT NULL DEFAULT 1 COMMENT 'check this network for gc or not',
PRIMARY KEY(`id`),
CONSTRAINT `fk_op_networks__id` FOREIGN KEY (`id`) REFERENCES `networks`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -485,7 +486,7 @@ CREATE TABLE `cloud`.`load_balancer_vm_map` (
`id` bigint unsigned NOT NULL auto_increment,
`load_balancer_id` bigint unsigned NOT NULL,
`instance_id` bigint unsigned NOT NULL,
`revoke` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 when vm is set for revoke from load balancer',
`pending` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'whether the vm is being applied to the load balancer (pending=1) or has already been applied (pending=0)',
PRIMARY KEY (`id`),
UNIQUE KEY (`load_balancer_id`, `instance_id`),
CONSTRAINT `fk_load_balancer_vm_map__load_balancer_id` FOREIGN KEY(`load_balancer_id`) REFERENCES `load_balancing_rules`(`id`) ON DELETE CASCADE,