Skip to content

Commit 40db230

Browse files
author
Alex Huang
committed
more changes for db upgrade
1 parent 8eaa53f commit 40db230

11 files changed

Lines changed: 47 additions & 105 deletions

File tree

‎server/src/com/cloud/agent/AgentManager.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,5 +230,4 @@ public List<HostVO> discoverHosts(Long dcId, Long podId, Long clusterId, String
230230
boolean isHostNativeHAEnabled(long hostId);
231231

232232
Answer sendTo(Long dcId, HypervisorType type, Command cmd);
233-
234233
}

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@
8686
import com.cloud.dc.ClusterDetailsDao;
8787
import com.cloud.dc.ClusterDetailsVO;
8888
import com.cloud.dc.ClusterVO;
89-
import com.cloud.dc.DataCenter;
9089
import com.cloud.dc.DataCenterIpAddressVO;
9190
import com.cloud.dc.DataCenterVO;
9291
import com.cloud.dc.HostPodVO;
93-
import com.cloud.dc.Pod;
9492
import com.cloud.dc.PodCluster;
9593
import com.cloud.dc.dao.ClusterDao;
9694
import com.cloud.dc.dao.DataCenterDao;
@@ -108,8 +106,6 @@
108106
import com.cloud.exception.InsufficientServerCapacityException;
109107
import com.cloud.exception.InvalidParameterValueException;
110108
import com.cloud.exception.OperationTimedoutException;
111-
import com.cloud.exception.StorageUnavailableException;
112-
import com.cloud.exception.ResourceUnavailableException;
113109
import com.cloud.exception.UnsupportedVersionException;
114110
import com.cloud.ha.HighAvailabilityManager;
115111
import com.cloud.ha.HighAvailabilityManager.WorkType;
@@ -122,6 +118,7 @@
122118
import com.cloud.host.Status.Event;
123119
import com.cloud.host.dao.DetailsDao;
124120
import com.cloud.host.dao.HostDao;
121+
import com.cloud.host.dao.HostTagsDao;
125122
import com.cloud.hypervisor.Hypervisor;
126123
import com.cloud.hypervisor.Hypervisor.HypervisorType;
127124
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
@@ -140,11 +137,9 @@
140137
import com.cloud.storage.GuestOSCategoryVO;
141138
import com.cloud.storage.Storage;
142139
import com.cloud.storage.StorageManager;
143-
import com.cloud.storage.StoragePool;
144140
import com.cloud.storage.StoragePoolVO;
145141
import com.cloud.storage.VMTemplateHostVO;
146142
import com.cloud.storage.VMTemplateVO;
147-
import com.cloud.storage.Volume;
148143
import com.cloud.storage.dao.GuestOSCategoryDao;
149144
import com.cloud.storage.dao.StoragePoolDao;
150145
import com.cloud.storage.dao.StoragePoolHostDao;
@@ -177,10 +172,8 @@
177172
import com.cloud.utils.nio.NioServer;
178173
import com.cloud.utils.nio.Task;
179174
import com.cloud.vm.VMInstanceVO;
180-
import com.cloud.vm.VirtualMachineProfile;
181175
import com.cloud.vm.VirtualMachineProfileImpl;
182176
import com.cloud.vm.dao.VMInstanceDao;
183-
import com.cloud.host.dao.HostTagsDao;
184177

185178
/**
186179
* Implementation of the Agent Manager. This class controls the connection to
@@ -1790,21 +1783,6 @@ public Pair<HostPodVO, Long> findPod(final VirtualMachineTemplate template,
17901783
return null;
17911784
}
17921785

1793-
public Pod findPod(VirtualMachineProfile vm, DataCenter dc,
1794-
Set<? extends Pod> avoids) {
1795-
for (PodAllocator allocator : _podAllocators) {
1796-
Pod pod = allocator.allocateTo(vm, dc, avoids);
1797-
if (pod != null) {
1798-
s_logger.debug("Pod " + pod.getId() + " is found by "
1799-
+ allocator.getName());
1800-
return pod;
1801-
}
1802-
}
1803-
1804-
s_logger.debug("Unable to find any pod for " + vm);
1805-
return null;
1806-
}
1807-
18081786
@Override
18091787
public HostStats getHostStatistics(long hostId) {
18101788
Answer answer = easySend(hostId, new GetHostStatsCommand(_hostDao

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -920,12 +920,12 @@ public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair
920920

921921
for (Pair<NetworkVO, NicProfile> network : networks) {
922922
NetworkVO config = network.first();
923-
NetworkGuru concierge = _networkGurus.get(config.getGuruName());
923+
NetworkGuru guru = _networkGurus.get(config.getGuruName());
924924
NicProfile requested = network.second();
925925
if (requested != null && requested.getMode() == null) {
926926
requested.setMode(config.getMode());
927927
}
928-
NicProfile profile = concierge.allocate(config, requested, vm);
928+
NicProfile profile = guru.allocate(config, requested, vm);
929929

930930
if (vm != null && vm.getVirtualMachine().getType() == Type.User && config.isDefault()) {
931931
profile.setDefaultNic(true);
@@ -943,7 +943,7 @@ public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair
943943
vmType = Nic.VmType.System;
944944
}
945945

946-
NicVO vo = new NicVO(concierge.getName(), vm.getId(), config.getId(), vmType);
946+
NicVO vo = new NicVO(guru.getName(), vm.getId(), config.getId(), vmType);
947947

948948
while (deviceIds[deviceId] && deviceId < deviceIds.length) {
949949
deviceId++;
@@ -1091,7 +1091,7 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDesti
10911091
}
10921092

10931093
if (s_logger.isDebugEnabled()) {
1094-
s_logger.debug("Asking " + guru + " to implement " + network);
1094+
s_logger.debug("Asking " + guru.getName() + " to implement " + network);
10951095
}
10961096

10971097
NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
@@ -1160,7 +1160,7 @@ public void prepare(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Dep
11601160
List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
11611161
for (NicVO nic : nics) {
11621162
Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context);
1163-
NetworkGuru concierge = implemented.first();
1163+
NetworkGuru guru = implemented.first();
11641164
NetworkVO network = implemented.second();
11651165
NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
11661166
Integer networkRate = _configMgr.getNetworkRate(no.getId());
@@ -1177,13 +1177,13 @@ public void prepare(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Dep
11771177
URI isolationUri = nic.getIsolationUri();
11781178

11791179
profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate);
1180-
concierge.reserve(profile, network, vmProfile, dest, context);
1180+
guru.reserve(profile, network, vmProfile, dest, context);
11811181
nic.setIp4Address(profile.getIp4Address());
11821182
nic.setIp6Address(profile.getIp6Address());
11831183
nic.setMacAddress(profile.getMacAddress());
11841184
nic.setIsolationUri(profile.getIsolationUri());
11851185
nic.setBroadcastUri(profile.getBroadCastUri());
1186-
nic.setReserver(concierge.getName());
1186+
nic.setReserver(guru.getName());
11871187
nic.setState(Nic.State.Reserved);
11881188
nic.setNetmask(profile.getNetmask());
11891189
nic.setGateway(profile.getGateway());
@@ -1202,7 +1202,7 @@ public void prepare(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Dep
12021202
element.prepare(network, profile, vmProfile, dest, context);
12031203
}
12041204
profile.setSecurityGroupEnabled(network.isSecurityGroupEnabled());
1205-
concierge.updateNicProfile(profile, network);
1205+
guru.updateNicProfile(profile, network);
12061206
vmProfile.addNic(profile);
12071207
}
12081208
}
@@ -1215,9 +1215,9 @@ public <T extends VMInstanceVO> void prepareNicForMigration(VirtualMachineProfil
12151215
NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
12161216
Integer networkRate = _configMgr.getNetworkRate(no.getId());
12171217

1218-
NetworkGuru concierge = _networkGurus.get(network.getGuruName());
1218+
NetworkGuru guru = _networkGurus.get(network.getGuruName());
12191219
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate);
1220-
concierge.updateNicProfile(profile, network);
1220+
guru.updateNicProfile(profile, network);
12211221
vm.addNic(profile);
12221222
}
12231223
}
@@ -1230,11 +1230,11 @@ public void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boo
12301230
if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
12311231
Nic.State originalState = nic.getState();
12321232
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
1233-
NetworkGuru concierge = _networkGurus.get(network.getGuruName());
1233+
NetworkGuru guru = _networkGurus.get(network.getGuruName());
12341234
nic.setState(Nic.State.Releasing);
12351235
_nicDao.update(nic.getId(), nic);
12361236
NicProfile profile = new NicProfile(nic, network, null, null, null);
1237-
if (concierge.release(profile, vmProfile, nic.getReservationId())) {
1237+
if (guru.release(profile, vmProfile, nic.getReservationId())) {
12381238
applyProfileToNicForRelease(nic, profile);
12391239
nic.setState(Nic.State.Allocated);
12401240
if (originalState == Nic.State.Reserved) {
@@ -1280,9 +1280,9 @@ public List<NicProfile> getNicProfiles(VirtualMachine vm) {
12801280
NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
12811281
Integer networkRate = _configMgr.getNetworkRate(no.getId());
12821282

1283-
NetworkGuru concierge = _networkGurus.get(network.getGuruName());
1283+
NetworkGuru guru = _networkGurus.get(network.getGuruName());
12841284
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate);
1285-
concierge.updateNicProfile(profile, network);
1285+
guru.updateNicProfile(profile, network);
12861286
profiles.add(profile);
12871287
}
12881288
}
@@ -1870,7 +1870,7 @@ public void shutdownNetwork(long networkId, ReservationContext context) {
18701870
for (NetworkElement element : _networkElements) {
18711871
try {
18721872
if (s_logger.isDebugEnabled()) {
1873-
s_logger.debug("Sending network shutdown to " + element);
1873+
s_logger.debug("Sending network shutdown to " + element.getName());
18741874
}
18751875

18761876
element.shutdown(network, context);
@@ -2479,9 +2479,9 @@ public IpAddress getIp(long ipAddressId) {
24792479
@Override
24802480
public NetworkProfile convertNetworkToNetworkProfile(long networkId) {
24812481
NetworkVO network = _networksDao.findById(networkId);
2482-
NetworkGuru concierge = _networkGurus.get(network.getGuruName());
2482+
NetworkGuru guru = _networkGurus.get(network.getGuruName());
24832483
NetworkProfile profile = new NetworkProfile(network);
2484-
concierge.updateNetworkProfile(profile);
2484+
guru.updateNetworkProfile(profile);
24852485

24862486
return profile;
24872487
}

‎server/src/com/cloud/server/ManagementServer.java‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.cloud.domain.DomainVO;
3232
import com.cloud.event.EventVO;
3333
import com.cloud.exception.ConcurrentOperationException;
34-
import com.cloud.exception.InternalErrorException;
3534
import com.cloud.exception.InvalidParameterValueException;
3635
import com.cloud.exception.OperationTimedoutException;
3736
import com.cloud.exception.ResourceUnavailableException;
@@ -297,17 +296,6 @@ public interface ManagementServer extends ManagementService {
297296
*/
298297
DataCenterVO findDataCenterById(long dataCenterId);
299298

300-
/**
301-
* Copies a template from one secondary storage server to another
302-
* @param userId
303-
* @param templateId
304-
* @param sourceZoneId - the source zone
305-
* @param destZoneId - the destination zone
306-
* @return true if success
307-
* @throws InternalErrorException
308-
*/
309-
boolean copyTemplate(long userId, long templateId, long sourceZoneId, long destZoneId);
310-
311299
/**
312300
* Finds a template by the specified ID.
313301
* @param templateId

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@
183183
import com.cloud.hypervisor.Hypervisor.HypervisorType;
184184
import com.cloud.info.ConsoleProxyInfo;
185185
import com.cloud.network.IPAddressVO;
186-
import com.cloud.network.Network;
187186
import com.cloud.network.NetworkManager;
188187
import com.cloud.network.NetworkVO;
189188
import com.cloud.network.dao.IPAddressDao;
@@ -1110,8 +1109,9 @@ private List<ServiceOfferingVO> searchServiceOfferingsInternal(Account account,
11101109
while(true){
11111110
if(id != null) {
11121111
ServiceOfferingVO so = _offeringsDao.findById((Long)id);
1113-
if(so != null)
1114-
sol.add(so);
1112+
if(so != null) {
1113+
sol.add(so);
1114+
}
11151115
return sol;
11161116
}
11171117

@@ -1983,18 +1983,6 @@ private VMTemplateVO updateTemplateOrIso(UpdateTemplateOrIsoCmd cmd) throws Inva
19831983
return _templateDao.findById(id);
19841984
}
19851985

1986-
@Override
1987-
public boolean copyTemplate(long userId, long templateId, long sourceZoneId, long destZoneId) {
1988-
boolean success = false;
1989-
try {
1990-
success = _tmpltMgr.copy(userId, templateId, sourceZoneId, destZoneId);
1991-
} catch (Exception e) {
1992-
s_logger.warn("Unable to copy template " + templateId + " from zone " + sourceZoneId + " to " + destZoneId , e);
1993-
success = false;
1994-
}
1995-
return success;
1996-
}
1997-
19981986
@Override
19991987
public VMTemplateVO findTemplateById(long templateId) {
20001988
return _templateDao.findById(templateId);

‎server/src/com/cloud/upgrade/dao/Upgrade217to22.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected void upgradeDataCenter(Connection conn) {
143143
try {
144144
pstmt = conn.prepareStatement("SELECT value FROM configuration WHERE name='direct.attach.untagged.vlan.enabled'");
145145
ResultSet rs = pstmt.executeQuery();
146-
_basicZone = !(rs.next() && Boolean.parseBoolean(rs.getString(1)));
146+
_basicZone = !rs.next() || Boolean.parseBoolean(rs.getString(1));
147147
rs.close();
148148
pstmt.close();
149149
pstmt = conn.prepareStatement("UPDATE data_center SET networktype=?, dns_provider=?, gateway_provider=?, firewall_provider=?, dhcp_provider=?, lb_provider=?, vpn_provider=?, userdata_provider=?");

‎server/src/com/cloud/upgrade/dao/VersionDaoImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class VersionDaoImpl extends GenericDaoBase<VersionVO, Long> implements V
6464
protected VersionDaoImpl() {
6565
super();
6666

67-
_upgradeMap.put(new Pair<String, String>("2.1.7", "2.2.1"), new DbUpgrade[] { new Upgrade217to22() });
67+
_upgradeMap.put(new Pair<String, String>("2.1.7", "2.2.2"), new DbUpgrade[] { new Upgrade217to22(), new Upgrade221to222() });
6868

6969
CurrentVersionSearch = createSearchBuilder(String.class);
7070
CurrentVersionSearch.select(null, Func.FIRST, CurrentVersionSearch.entity().getVersion());

server/test/com/cloud/upgrade/dao/VersionDaoImplTest.java renamed to server/test/com/cloud/upgrade/dao/AdvanceZone217To221UpgradeTest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import com.cloud.utils.db.Transaction;
3838
import com.cloud.utils.exception.CloudRuntimeException;
3939

40-
public class VersionDaoImplTest extends TestCase {
41-
private static final Logger s_logger = Logger.getLogger(VersionDaoImplTest.class);
40+
public class AdvanceZone217To221UpgradeTest extends TestCase {
41+
private static final Logger s_logger = Logger.getLogger(AdvanceZone217To221UpgradeTest.class);
4242

4343
@Override
4444
@Before
@@ -56,7 +56,23 @@ public void tearDown() throws Exception {
5656
public void test217to22Upgrade() {
5757
s_logger.debug("Finding sample data from 2.1.7");
5858
DbTestUtils.executeScript("VersionDaoImplTest/2.1.7/2.1.7.sample.sql", false, true);
59-
59+
60+
Connection conn = Transaction.getStandaloneConnection();
61+
PreparedStatement pstmt;
62+
try {
63+
pstmt = conn.prepareStatement("UPDATE configuration set value='true' WHERE name = 'direct.attach.untagged.vlan.enabled'");
64+
pstmt.executeUpdate();
65+
pstmt.close();
66+
} catch(SQLException e) {
67+
68+
} finally {
69+
try {
70+
conn.close();
71+
} catch(SQLException e) {
72+
73+
}
74+
}
75+
6076
VersionDaoImpl dao = ComponentLocator.inject(VersionDaoImpl.class);
6177

6278
String version = dao.getCurrentVersion();
@@ -69,8 +85,7 @@ public void test217to22Upgrade() {
6985
assert false : "The test failed. Check logs";
7086
}
7187

72-
Connection conn = Transaction.getStandaloneConnection();
73-
PreparedStatement pstmt;
88+
conn = Transaction.getStandaloneConnection();
7489
try {
7590
pstmt = conn.prepareStatement("SELECT version FROm version");
7691
ResultSet rs = pstmt.executeQuery();

‎setup/db/schema-21to22.sql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `mac_address` bigint unsigned N
192192
ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `source_network_id` bigint unsigned NOT NULL;
193193
ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `network_id` bigint unsigned;
194194

195+
UPDATE `cloud`.`user_ip_address` set state=`Allocated` WHERE allocated IS NOT NULL;
196+
195197
CREATE TABLE `cloud`.`firewall_rules` (
196198
`id` bigint unsigned NOT NULL auto_increment COMMENT 'id',
197199
`ip_address_id` bigint unsigned NOT NULL COMMENT 'id of the corresponding ip address',

‎utils/src/com/cloud/utils/db/DataStore.java‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)