Skip to content

Commit 42986f4

Browse files
author
Alex Huang
committed
removed service offering from storageallocator
1 parent e6c2f7f commit 42986f4

14 files changed

Lines changed: 146 additions & 66 deletions

‎build/build-cloud.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
</path>
141141

142142
<path id="thirdparty.classpath">
143-
<filelist files="${thirdparty.classpath}" />
143+
<!--filelist files="${thirdparty.classpath}" /-->
144144
<fileset dir="${thirdparty.dir}" erroronmissingdir="false">
145145
<include name="*.jar" />
146146
</fileset>

‎build/build-common.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<javac srcdir="@{top.dir}/src" debug="${debug}" debuglevel="${debuglevel}" deprecation="${deprecation}" destdir="${classes.dir}/@{jar.name}" source="${source.compat.version}" target="${target.compat.version}" includeantruntime="false" compiler="javac1.6">
4949
<!-- compilerarg line="-processor com.cloud.annotation.LocalProcessor -processorpath ${base.dir}/tools/src -Xlint:all"/ -->
5050
<!-- compilerarg line="-processor com.cloud.utils.LocalProcessor -processorpath ${base.dir}/utils/src -Xlint:all"/ -->
51-
<compilerarg line="-Xlint:all"/>
51+
<compilerarg line="-Xlint:-path"/>
5252
<classpath refid="@{classpath}" />
5353
<exclude-files/>
5454
</javac>

‎core/src/com/cloud/storage/StorageManager.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
import com.cloud.agent.api.Answer;
2626
import com.cloud.agent.api.Command;
27+
import com.cloud.agent.api.to.VolumeTO;
2728
import com.cloud.dc.DataCenterVO;
2829
import com.cloud.dc.HostPodVO;
30+
import com.cloud.deploy.DeployDestination;
2931
import com.cloud.exception.InternalErrorException;
3032
import com.cloud.exception.ResourceAllocationException;
3133
import com.cloud.exception.ResourceInUseException;
@@ -41,6 +43,7 @@
4143
import com.cloud.utils.exception.ExecutionException;
4244
import com.cloud.vm.DiskProfile;
4345
import com.cloud.vm.VMInstanceVO;
46+
import com.cloud.vm.VirtualMachineProfile;
4447

4548
public interface StorageManager extends Manager {
4649

@@ -314,4 +317,6 @@ public long createUserVM(Account account, VMInstanceVO vm,
314317
Long findHostIdForStoragePool(StoragePoolVO pool);
315318
void createCapacityEntry(StoragePoolVO storagePool, long allocated);
316319

320+
321+
VolumeTO[] prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException;
317322
}

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ private boolean hasPreviousSession(ConsoleProxyVO proxy, VMInstanceVO vm) {
516516
@Override
517517
public ConsoleProxyVO startProxy(long proxyVmId, long startEventId) {
518518
try {
519-
return start(proxyVmId, startEventId);
519+
return start2(proxyVmId, startEventId);
520520
} catch (StorageUnavailableException e) {
521521
s_logger.warn("Exception while trying to start console proxy", e);
522522
return null;
@@ -852,7 +852,7 @@ public ConsoleProxyVO startNewConsoleProxy(long dataCenterId) {
852852
if (s_logger.isDebugEnabled())
853853
s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
854854

855-
Map<String, Object> context = createProxyInstance(dataCenterId);
855+
Map<String, Object> context = createProxyInstance2(dataCenterId);
856856

857857
long proxyVmId = (Long) context.get("proxyVmId");
858858
if (proxyVmId == 0) {
@@ -892,7 +892,7 @@ public ConsoleProxyVO startNew(long dataCenterId) {
892892
if (s_logger.isDebugEnabled())
893893
s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
894894

895-
Map<String, Object> context = createProxyInstance(dataCenterId);
895+
Map<String, Object> context = createProxyInstance2(dataCenterId);
896896

897897
long proxyVmId = (Long) context.get("proxyVmId");
898898
if (proxyVmId == 0) {
@@ -1417,7 +1417,7 @@ private void checkPendingProxyVMs() {
14171417
try {
14181418
if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
14191419
try {
1420-
readyProxy = start(readyProxy.getId(), 0);
1420+
readyProxy = start2(readyProxy.getId(), 0);
14211421
} finally {
14221422
proxyLock.unlock();
14231423
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public interface NetworkManager extends Manager {
228228

229229
List<NicProfile> allocate(VirtualMachineProfile vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException;
230230

231-
List<NicTO> prepare(VirtualMachineProfile profile, DeployDestination dest) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException;
231+
NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException;
232232

233233
<K extends VMInstanceVO> void create(K vm);
234234

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,12 +2478,12 @@ protected NicTO toNicTO(NicVO nic, NetworkConfigurationVO config) {
24782478
}
24792479

24802480
@Override
2481-
public List<NicTO> prepare(VirtualMachineProfile vmProfile, DeployDestination dest) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException {
2481+
public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException {
24822482
List<NicVO> nics = _nicDao.listBy(vmProfile.getId());
2483-
List<NicTO> nicTos = new ArrayList<NicTO>(nics.size());
2483+
NicTO[] nicTos = new NicTO[nics.size()];
2484+
int i = 0;
24842485
for (NicVO nic : nics) {
24852486
NetworkConfigurationVO config = _networkProfileDao.findById(nic.getNetworkConfigurationId());
2486-
24872487
if (nic.getReservationStrategy() == ReservationStrategy.Start) {
24882488
NetworkGuru concierge = _networkGurus.get(config.getGuruName());
24892489
nic.setState(Resource.State.Reserving);
@@ -2510,7 +2510,7 @@ public List<NicTO> prepare(VirtualMachineProfile vmProfile, DeployDestination de
25102510
}
25112511
}
25122512

2513-
nicTos.add(toNicTO(nic, config));
2513+
nicTos[i++] = toNicTO(nic, config);
25142514

25152515
}
25162516
return nicTos;

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Formatter;
2727
import java.util.HashMap;
2828
import java.util.HashSet;
29+
import java.util.Iterator;
2930
import java.util.List;
3031
import java.util.Map;
3132
import java.util.Set;
@@ -74,6 +75,7 @@
7475
import com.cloud.dc.HostPodVO;
7576
import com.cloud.dc.dao.DataCenterDao;
7677
import com.cloud.dc.dao.HostPodDao;
78+
import com.cloud.deploy.DeployDestination;
7779
import com.cloud.event.EventState;
7880
import com.cloud.event.EventTypes;
7981
import com.cloud.event.EventVO;
@@ -145,6 +147,7 @@
145147
import com.cloud.vm.UserVmVO;
146148
import com.cloud.vm.VMInstanceVO;
147149
import com.cloud.vm.VirtualMachine;
150+
import com.cloud.vm.VirtualMachineProfile;
148151
import com.cloud.vm.dao.ConsoleProxyDao;
149152
import com.cloud.vm.dao.UserVmDao;
150153
import com.cloud.vm.dao.VMInstanceDao;
@@ -170,7 +173,9 @@ public class StorageManagerImpl implements StorageManager {
170173
@Inject protected ConsoleProxyDao _consoleProxyDao;
171174
@Inject protected DetailsDao _detailsDao;
172175
@Inject protected SnapshotDao _snapshotDao;
176+
@Inject(adapter=StoragePoolAllocator.class)
173177
protected Adapters<StoragePoolAllocator> _storagePoolAllocators;
178+
@Inject(adapter=StoragePoolDiscoverer.class)
174179
protected Adapters<StoragePoolDiscoverer> _discoverers;
175180
@Inject protected StoragePoolHostDao _storagePoolHostDao;
176181
@Inject protected AlertManager _alertMgr;
@@ -267,6 +272,87 @@ public VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, D
267272
return vols.get(0);
268273
}
269274

275+
@Override
276+
public VolumeTO[] prepare(VirtualMachineProfile vm, DeployDestination dest) {
277+
List<VolumeVO> vols = _volsDao.findCreatedByInstance(vm.getId());
278+
List<VolumeVO> recreateVols = new ArrayList<VolumeVO>(vols.size());
279+
Host host = dest.getHost();
280+
281+
VolumeTO[] disks = new VolumeTO[vols.size()];
282+
int i = 0;
283+
Iterator<VolumeVO> it = vols.iterator();
284+
while (it.hasNext()) {
285+
VolumeVO vol = it.next();
286+
if (vol.isRecreatable()) {
287+
it.remove();
288+
//if we have a system vm
289+
//get the storage pool
290+
//if pool is in maintenance
291+
//add to recreate vols, and continue
292+
if(vm.getType().equals(VirtualMachine.Type.ConsoleProxy) || vm.getType().equals(VirtualMachine.Type.DomainRouter) || vm.getType().equals(VirtualMachine.Type.SecondaryStorageVm))
293+
{
294+
StoragePoolVO sp = _storagePoolDao.findById(vol.getPoolId());
295+
296+
if(sp!=null && sp.getStatus().equals(Status.PrepareForMaintenance))
297+
{
298+
recreateVols.add(vol);
299+
continue;
300+
}
301+
}
302+
303+
StoragePoolHostVO ph = _storagePoolHostDao.findByPoolHost(vol.getPoolId(), host.getId());
304+
if (ph == null) {
305+
if (s_logger.isDebugEnabled()) {
306+
s_logger.debug("Must recreate " + vol + " since " + vol.getPoolId() + " has is not hooked up with host " + host.getId());
307+
}
308+
recreateVols.add(vol);
309+
}
310+
}
311+
}
312+
313+
for (VolumeVO vol : recreateVols) {
314+
VolumeVO create = allocateDuplicateVolume(vol);
315+
vols.add(vol);
316+
}
317+
318+
/*
319+
create.setDiskOfferingId(vol.getDiskOfferingId());
320+
create.setDeviceId(vol.getDeviceId());
321+
create = _volsDao.persist(create);
322+
VMTemplateVO template = _templateDao.findById(create.getTemplateId());
323+
DataCenterVO dc = _dcDao.findById(create.getDataCenterId());
324+
HostPodVO pod = _podDao.findById(host.getPodId());
325+
DiskOfferingVO diskOffering = null;
326+
diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId());
327+
ServiceOfferingVO offering;
328+
if (vm instanceof UserVmVO) {
329+
offering = _offeringDao.findById(((UserVmVO)vm).getServiceOfferingId());
330+
} else {
331+
offering = _offeringDao.findById(vol.getDiskOfferingId());
332+
}
333+
VolumeVO created = createVolume(create, vm, template, dc, pod, host.getClusterId(), offering, diskOffering, new ArrayList<StoragePoolVO>(),0);
334+
if (created == null) {
335+
break;
336+
}
337+
createds.add(created);
338+
339+
for (VolumeVO vol : recreateVols) {
340+
_volsDao.remove(vol.getId());
341+
}
342+
disks[i++] = null;
343+
}
344+
*/
345+
return disks;
346+
}
347+
348+
VolumeVO allocateDuplicateVolume(VolumeVO oldVol) {
349+
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize());
350+
newVol.setTemplateId(oldVol.getTemplateId());
351+
newVol.setDeviceId(oldVol.getDeviceId());
352+
newVol.setInstanceId(oldVol.getInstanceId());
353+
return _volsDao.persist(newVol);
354+
}
355+
270356

271357
@Override
272358
public List<VolumeVO> prepare(VMInstanceVO vm, HostVO host) {
@@ -392,7 +478,7 @@ protected StoragePoolVO findStoragePool(DiskProfile dskCh, final DataCenterVO dc
392478
Enumeration<StoragePoolAllocator> en = _storagePoolAllocators.enumeration();
393479
while (en.hasMoreElements()) {
394480
final StoragePoolAllocator allocator = en.nextElement();
395-
final StoragePool pool = allocator.allocateToPool(dskCh, offering, dc, pod, clusterId, vm, template, avoid);
481+
final StoragePool pool = allocator.allocateToPool(dskCh, dc, pod, clusterId, vm, template, avoid);
396482
if (pool != null) {
397483
return (StoragePoolVO) pool;
398484
}
@@ -1056,13 +1142,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
10561142
return false;
10571143
}
10581144

1059-
_storagePoolAllocators = locator.getAdapters(StoragePoolAllocator.class);
1060-
if (!_storagePoolAllocators.isSet()) {
1061-
throw new ConfigurationException("Unable to get any storage pool allocators.");
1062-
}
1063-
1064-
_discoverers = locator.getAdapters(StoragePoolDiscoverer.class);
1065-
10661145
Map<String, String> configs = configDao.getConfiguration("management-server", params);
10671146

10681147

‎server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import org.apache.log4j.Logger;
2929

3030
import com.cloud.configuration.dao.ConfigurationDao;
31+
import com.cloud.deploy.DeployDestination;
3132
import com.cloud.host.Host;
3233
import com.cloud.host.HostVO;
33-
import com.cloud.offering.ServiceOffering;
3434
import com.cloud.server.StatsCollector;
3535
import com.cloud.storage.Storage.StoragePoolType;
3636
import com.cloud.storage.StorageManager;
@@ -42,6 +42,7 @@
4242
import com.cloud.storage.VMTemplateStorageResourceAssoc;
4343
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
4444
import com.cloud.storage.VMTemplateVO;
45+
import com.cloud.storage.Volume;
4546
import com.cloud.storage.Volume.VolumeType;
4647
import com.cloud.storage.dao.StoragePoolDao;
4748
import com.cloud.storage.dao.StoragePoolHostDao;
@@ -58,6 +59,7 @@
5859
import com.cloud.vm.DiskProfile;
5960
import com.cloud.vm.VMInstanceVO;
6061
import com.cloud.vm.VirtualMachine;
62+
import com.cloud.vm.VirtualMachineProfile;
6163

6264
public abstract class AbstractStoragePoolAllocator extends AdapterBase implements StoragePoolAllocator {
6365
private static final Logger s_logger = Logger.getLogger(FirstFitStoragePoolAllocator.class);
@@ -100,7 +102,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
100102
return true;
101103
}
102104

103-
abstract boolean allocatorIsCorrectType(DiskProfile dskCh, VMInstanceVO vm, ServiceOffering offering);
105+
abstract boolean allocatorIsCorrectType(DiskProfile dskCh, VMInstanceVO vm);
104106

105107
protected boolean templateAvailable(long templateId, long poolId) {
106108
VMTemplateStorageResourceAssoc thvo = _templatePoolDao.findByPoolTemplate(poolId, templateId);
@@ -114,26 +116,16 @@ protected boolean templateAvailable(long templateId, long poolId) {
114116
}
115117
}
116118

117-
protected boolean localStorageAllocationNeeded(DiskProfile dskCh, VMInstanceVO vm, ServiceOffering offering) {
118-
if (vm == null) {
119-
// We are finding a pool for a volume, so we need a shared storage allocator
120-
return false;
121-
} else if (vm.getType() == VirtualMachine.Type.User) {
122-
// We are finding a pool for a UserVM, so check the service offering to see if we should use local storage
123-
return offering.getUseLocalStorage();
124-
} else {
125-
// We are finding a pool for a DomR or ConsoleProxy, so check the configuration table to see if we should use local storage
126-
String configValue = _configDao.getValue("system.vm.use.local.storage");
127-
return Boolean.parseBoolean(configValue);
128-
}
119+
protected boolean localStorageAllocationNeeded(DiskProfile dskCh, VMInstanceVO vm) {
120+
return dskCh.useLocalStorage();
129121
}
130122

131-
protected boolean poolIsCorrectType(DiskProfile dskCh, StoragePool pool, VMInstanceVO vm, ServiceOffering offering) {
132-
boolean localStorageAllocationNeeded = localStorageAllocationNeeded(dskCh, vm, offering);
123+
protected boolean poolIsCorrectType(DiskProfile dskCh, StoragePool pool, VMInstanceVO vm) {
124+
boolean localStorageAllocationNeeded = localStorageAllocationNeeded(dskCh, vm);
133125
return ((!localStorageAllocationNeeded && pool.getPoolType().isShared()) || (localStorageAllocationNeeded && !pool.getPoolType().isShared()));
134126
}
135127

136-
protected boolean checkPool(Set<? extends StoragePool> avoid, StoragePoolVO pool, DiskProfile dskCh, VMTemplateVO template, List<VMTemplateStoragePoolVO> templatesInPool, ServiceOffering offering,
128+
protected boolean checkPool(Set<? extends StoragePool> avoid, StoragePoolVO pool, DiskProfile dskCh, VMTemplateVO template, List<VMTemplateStoragePoolVO> templatesInPool,
137129
VMInstanceVO vm, StatsCollector sc) {
138130
if (avoid.contains(pool)) {
139131
return false;
@@ -144,7 +136,7 @@ protected boolean checkPool(Set<? extends StoragePool> avoid, StoragePoolVO pool
144136

145137

146138
// Check that the pool type is correct
147-
if (!poolIsCorrectType(dskCh, pool, vm, offering)) {
139+
if (!poolIsCorrectType(dskCh, pool, vm)) {
148140
return false;
149141
}
150142

@@ -235,4 +227,10 @@ protected boolean checkPool(Set<? extends StoragePool> avoid, StoragePoolVO pool
235227
public String chooseStorageIp(VirtualMachine vm, Host host, Host storage) {
236228
return storage.getStorageIpAddress();
237229
}
230+
231+
@Override
232+
public StoragePool allocateTo(DiskProfile dskCh, VirtualMachineProfile vm, DeployDestination dest, List<Volume> disks, Set<StoragePool> avoids) {
233+
234+
return null;
235+
}
238236
}

‎server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import com.cloud.dc.DataCenterVO;
2929
import com.cloud.dc.HostPodVO;
30-
import com.cloud.offering.ServiceOffering;
3130
import com.cloud.server.StatsCollector;
3231
import com.cloud.storage.StoragePool;
3332
import com.cloud.storage.StoragePoolVO;
@@ -40,15 +39,15 @@ public class FirstFitStoragePoolAllocator extends AbstractStoragePoolAllocator {
4039
private static final Logger s_logger = Logger.getLogger(FirstFitStoragePoolAllocator.class);
4140

4241
@Override
43-
public boolean allocatorIsCorrectType(DiskProfile dskCh, VMInstanceVO vm, ServiceOffering offering) {
44-
return !localStorageAllocationNeeded(dskCh, vm, offering);
42+
public boolean allocatorIsCorrectType(DiskProfile dskCh, VMInstanceVO vm) {
43+
return !localStorageAllocationNeeded(dskCh, vm);
4544
}
4645

4746
@Override
48-
public StoragePool allocateToPool(DiskProfile dskCh, ServiceOffering offering, DataCenterVO dc, HostPodVO pod, Long clusterId,
47+
public StoragePool allocateToPool(DiskProfile dskCh, DataCenterVO dc, HostPodVO pod, Long clusterId,
4948
VMInstanceVO vm, VMTemplateVO template, Set<? extends StoragePool> avoid) {
5049
// Check that the allocator type is correct
51-
if (!allocatorIsCorrectType(dskCh, vm, offering)) {
50+
if (!allocatorIsCorrectType(dskCh, vm)) {
5251
return null;
5352
}
5453

@@ -65,7 +64,7 @@ public StoragePool allocateToPool(DiskProfile dskCh, ServiceOffering offering, D
6564
Collections.shuffle(pools);
6665

6766
for (StoragePoolVO pool: pools) {
68-
if (checkPool(avoid, pool, dskCh, template, null, offering, vm, sc)) {
67+
if (checkPool(avoid, pool, dskCh, template, null, vm, sc)) {
6968
return pool;
7069
}
7170
}

0 commit comments

Comments
 (0)