Skip to content

Commit 894785b

Browse files
Deletion of method endPointSelector.selectHypervisorHost
As discussed on PR 1056, I am removing the method “endPointSelector.selectHypervisorHost” that is not needed anymore
1 parent 5ab82d1 commit 894785b

5 files changed

Lines changed: 28 additions & 134 deletions

File tree

‎engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,5 @@ public interface EndPointSelector {
3535

3636
EndPoint select(Scope scope, Long storeId);
3737

38-
EndPoint selectHypervisorHost(Scope scope);
39-
4038
EndPoint select(DataStore store, String downloadUrl);
4139
}

‎engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java‎

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
import javax.inject.Inject;
3131

32-
import org.apache.log4j.Logger;
33-
import org.springframework.stereotype.Component;
34-
3532
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
3633
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3734
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@ -43,6 +40,8 @@
4340
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
4441
import org.apache.cloudstack.storage.LocalHostEndpoint;
4542
import org.apache.cloudstack.storage.RemoteHostEndPoint;
43+
import org.apache.log4j.Logger;
44+
import org.springframework.stereotype.Component;
4645

4746
import com.cloud.host.Host;
4847
import com.cloud.host.HostVO;
@@ -63,11 +62,10 @@
6362
public class DefaultEndPointSelector implements EndPointSelector {
6463
private static final Logger s_logger = Logger.getLogger(DefaultEndPointSelector.class);
6564
@Inject
66-
HostDao hostDao;
65+
private HostDao hostDao;
6766
private final String findOneHostOnPrimaryStorage =
6867
"select h.id from host h, storage_pool_host_ref s where h.status = 'Up' and h.type = 'Routing' and h.resource_state = 'Enabled' and"
6968
+ " h.id = s.host_id and s.pool_id = ? ";
70-
private String findOneHypervisorHostInScope = "select h.id from host h where h.status = 'Up' and h.hypervisor_type is not null ";
7169

7270
protected boolean moveBetweenPrimaryImage(DataStore srcStore, DataStore destStore) {
7371
DataStoreRole srcRole = srcStore.getRole();
@@ -260,8 +258,9 @@ private List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
260258
public EndPoint select(DataObject object) {
261259
DataStore store = object.getDataStore();
262260
EndPoint ep = select(store);
263-
if (ep != null)
261+
if (ep != null) {
264262
return ep;
263+
}
265264
if (object instanceof TemplateInfo) {
266265
TemplateInfo tmplInfo = (TemplateInfo)object;
267266
if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null && tmplInfo.getTemplateType() == TemplateType.SYSTEM) {
@@ -380,40 +379,4 @@ public List<EndPoint> selectAll(DataStore store) {
380379
}
381380
return endPoints;
382381
}
383-
384-
@Override
385-
public EndPoint selectHypervisorHost(Scope scope) {
386-
StringBuilder sbuilder = new StringBuilder();
387-
sbuilder.append(findOneHypervisorHostInScope);
388-
if (scope.getScopeType() == ScopeType.ZONE) {
389-
sbuilder.append(" and h.data_center_id = ");
390-
sbuilder.append(scope.getScopeId());
391-
} else if (scope.getScopeType() == ScopeType.CLUSTER) {
392-
sbuilder.append(" and h.cluster_id = ");
393-
sbuilder.append(scope.getScopeId());
394-
}
395-
sbuilder.append(" ORDER by rand() limit 1");
396-
397-
String sql = sbuilder.toString();
398-
HostVO host = null;
399-
TransactionLegacy txn = TransactionLegacy.currentTxn();
400-
401-
try (
402-
PreparedStatement pstmt = txn.prepareStatement(sql);
403-
ResultSet rs = pstmt.executeQuery();
404-
) {
405-
while (rs.next()) {
406-
long id = rs.getLong(1);
407-
host = hostDao.findById(id);
408-
}
409-
} catch (SQLException e) {
410-
s_logger.warn("can't find endpoint", e);
411-
}
412-
413-
if (host == null) {
414-
return null;
415-
}
416-
417-
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
418-
}
419382
}

‎plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorGuru.java‎

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,11 @@
1919

2020
import javax.inject.Inject;
2121

22-
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
23-
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
24-
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
25-
import org.apache.cloudstack.storage.command.CopyCommand;
2622
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
2723
import org.apache.log4j.Logger;
2824

2925
import com.cloud.agent.api.Command;
30-
import com.cloud.agent.api.to.DataObjectType;
31-
import com.cloud.agent.api.to.DataStoreTO;
32-
import com.cloud.agent.api.to.DataTO;
33-
import com.cloud.agent.api.to.NfsTO;
3426
import com.cloud.agent.api.to.VirtualMachineTO;
35-
import com.cloud.host.HostVO;
36-
import com.cloud.host.dao.HostDao;
3727
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3828
import com.cloud.hypervisor.HypervisorGuru;
3929
import com.cloud.hypervisor.HypervisorGuruBase;
@@ -45,15 +35,7 @@
4535
public class Ovm3HypervisorGuru extends HypervisorGuruBase implements HypervisorGuru {
4636
private final Logger LOGGER = Logger.getLogger(Ovm3HypervisorGuru.class);
4737
@Inject
48-
GuestOSDao guestOsDao;
49-
@Inject
50-
EndPointSelector endPointSelector;
51-
@Inject
52-
HostDao hostDao;
53-
54-
protected Ovm3HypervisorGuru() {
55-
super();
56-
}
38+
private GuestOSDao guestOsDao;
5739

5840
@Override
5941
public HypervisorType getHypervisorType() {
@@ -78,35 +60,13 @@ public boolean trackVmHostChange() {
7860
return true;
7961
}
8062

81-
/* I dislike the notion of having to place this here, and not being able to just override
82-
*
83-
* (non-Javadoc)
84-
* @see com.cloud.hypervisor.HypervisorGuruBase#getCommandHostDelegation(long, com.cloud.agent.api.Command)
85-
*/
63+
@Override
8664
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
8765
LOGGER.debug("getCommandHostDelegation: " + cmd.getClass());
8866
if (cmd instanceof StorageSubSystemCommand) {
8967
StorageSubSystemCommand c = (StorageSubSystemCommand)cmd;
9068
c.setExecuteInSequence(true);
9169
}
92-
if (cmd instanceof CopyCommand) {
93-
CopyCommand cpyCommand = (CopyCommand)cmd;
94-
DataTO srcData = cpyCommand.getSrcTO();
95-
DataTO destData = cpyCommand.getDestTO();
96-
97-
if (HypervisorType.Ovm3.equals(srcData.getHypervisorType()) && srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
98-
LOGGER.debug("Snapshot to Template: " + cmd);
99-
DataStoreTO srcStore = srcData.getDataStore();
100-
DataStoreTO destStore = destData.getDataStore();
101-
if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
102-
HostVO host = hostDao.findById(hostId);
103-
EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
104-
if (ep != null) {
105-
return new Pair<Boolean, Long>(Boolean.TRUE, Long.valueOf(ep.getId()));
106-
}
107-
}
108-
}
109-
}
11070
return new Pair<Boolean, Long>(Boolean.FALSE, Long.valueOf(hostId));
11171
}
11272
}

‎plugins/hypervisors/xenserver/src/com/cloud/hypervisor/XenServerGuru.java‎

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,19 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
21-
import java.util.Map;
2221

2322
import javax.inject.Inject;
2423

25-
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
26-
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
2724
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
28-
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
25+
import org.apache.cloudstack.framework.config.ConfigKey;
2926
import org.apache.cloudstack.framework.config.Configurable;
3027
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
3128
import org.apache.cloudstack.storage.command.CopyCommand;
3229
import org.apache.cloudstack.storage.command.DettachCommand;
3330
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
3431
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
3532
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
36-
import org.apache.cloudstack.framework.config.ConfigKey;
33+
import org.apache.log4j.Logger;
3734

3835
import com.cloud.agent.api.Command;
3936
import com.cloud.agent.api.to.DataObjectType;
@@ -57,34 +54,27 @@
5754
import com.cloud.vm.VirtualMachine;
5855
import com.cloud.vm.VirtualMachineProfile;
5956
import com.cloud.vm.dao.UserVmDao;
60-
import org.apache.log4j.Logger;
6157

6258
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable {
6359
private final Logger LOGGER = Logger.getLogger(XenServerGuru.class);
6460
@Inject
65-
GuestOSDao _guestOsDao;
66-
@Inject
67-
GuestOSHypervisorDao _guestOsHypervisorDao;
61+
private GuestOSDao _guestOsDao;
6862
@Inject
69-
EndPointSelector endPointSelector;
63+
private GuestOSHypervisorDao _guestOsHypervisorDao;
7064
@Inject
71-
HostDao hostDao;
65+
private HostDao hostDao;
7266
@Inject
73-
VolumeDao _volumeDao;
67+
private VolumeDao _volumeDao;
7468
@Inject
75-
PrimaryDataStoreDao _storagePoolDao;
69+
private PrimaryDataStoreDao _storagePoolDao;
7670
@Inject
77-
VolumeDataFactory _volFactory;
71+
private VolumeDataFactory _volFactory;
7872
@Inject
79-
UserVmDao _userVmDao;
73+
private UserVmDao _userVmDao;
8074

81-
static final ConfigKey<Integer> MaxNumberOfVCPUSPerVM = new ConfigKey<Integer>("Advanced", Integer.class, "xen.vm.vcpu.max", "16",
75+
private static final ConfigKey<Integer> MaxNumberOfVCPUSPerVM = new ConfigKey<Integer>("Advanced", Integer.class, "xen.vm.vcpu.max", "16",
8276
"Maximum number of VCPUs that VM can get in XenServer.", true, ConfigKey.Scope.Cluster);
8377

84-
protected XenServerGuru() {
85-
super();
86-
}
87-
8878
@Override
8979
public HypervisorType getHypervisorType() {
9080
return HypervisorType.XenServer;
@@ -129,11 +119,6 @@ public boolean trackVmHostChange() {
129119
return true;
130120
}
131121

132-
@Override
133-
public Map<String, String> getClusterSettings(long vmId) {
134-
return null;
135-
}
136-
137122
@Override
138123
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
139124
List<Command> commands = new ArrayList<Command>();
@@ -189,15 +174,13 @@ public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
189174
DataStoreTO destStore = destData.getDataStore();
190175
if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
191176
HostVO host = hostDao.findById(hostId);
192-
EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
193-
host = hostDao.findById(ep.getId());
194177
hostDao.loadDetails(host);
195178
String hypervisorVersion = host.getHypervisorVersion();
196179
String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
197180
if (hypervisorVersion != null && !hypervisorVersion.equalsIgnoreCase("6.1.0")) {
198-
if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") &&
199-
!(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
200-
return new Pair<Boolean, Long>(Boolean.TRUE, new Long(ep.getId()));
181+
if (!(hypervisorVersion.equalsIgnoreCase("6.2.0")
182+
&& !(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
183+
return new Pair<Boolean, Long>(Boolean.TRUE, new Long(host.getId()));
201184
}
202185
}
203186
}

‎server/src/com/cloud/hypervisor/HypervisorGuruBase.java‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
import com.cloud.network.dao.NetworkVO;
3434
import com.cloud.offering.ServiceOffering;
3535
import com.cloud.resource.ResourceManager;
36-
import com.cloud.server.ConfigurationServer;
3736
import com.cloud.service.ServiceOfferingDetailsVO;
3837
import com.cloud.service.dao.ServiceOfferingDao;
3938
import com.cloud.service.dao.ServiceOfferingDetailsDao;
40-
import com.cloud.storage.dao.VMTemplateDetailsDao;
4139
import com.cloud.utils.Pair;
4240
import com.cloud.utils.component.AdapterBase;
4341
import com.cloud.vm.NicProfile;
@@ -55,29 +53,21 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
5553
public static final Logger s_logger = Logger.getLogger(HypervisorGuruBase.class);
5654

5755
@Inject
58-
VMTemplateDetailsDao _templateDetailsDao;
56+
private NicDao _nicDao;
5957
@Inject
60-
NicDao _nicDao;
58+
private NetworkDao _networkDao;
6159
@Inject
62-
NetworkDao _networkDao;
60+
private VMInstanceDao _virtualMachineDao;
6361
@Inject
64-
VMInstanceDao _virtualMachineDao;
62+
private UserVmDetailsDao _userVmDetailsDao;
6563
@Inject
66-
UserVmDetailsDao _userVmDetailsDao;
64+
private NicSecondaryIpDao _nicSecIpDao;
6765
@Inject
68-
NicSecondaryIpDao _nicSecIpDao;
66+
private ResourceManager _resourceMgr;
6967
@Inject
70-
ConfigurationServer _configServer;
68+
private ServiceOfferingDetailsDao _serviceOfferingDetailsDao;
7169
@Inject
72-
ResourceManager _resourceMgr;
73-
@Inject
74-
ServiceOfferingDetailsDao _serviceOfferingDetailsDao;
75-
@Inject
76-
ServiceOfferingDao _serviceOfferingDao;
77-
78-
protected HypervisorGuruBase() {
79-
super();
80-
}
70+
private ServiceOfferingDao _serviceOfferingDao;
8171

8272
@Override
8373
public NicTO toNicTO(NicProfile profile) {

0 commit comments

Comments
 (0)