You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2018/03/27 10:46:28 UTC
[cloudstack] branch master updated: [CLOUDSTACK-10307] Remove
unused things from HostDaoImpl (#2438)
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/master by this push:
new 0afcec6 [CLOUDSTACK-10307] Remove unused things from HostDaoImpl (#2438)
0afcec6 is described below
commit 0afcec60f41458cfa2f8bd5bb595c8d51caab1ce
Author: Rafael Weingärtner <ra...@gmail.com>
AuthorDate: Tue Mar 27 07:46:25 2018 -0300
[CLOUDSTACK-10307] Remove unused things from HostDaoImpl (#2438)
* Remove unused code from CloudZonesStartupProcessor
* Removed unused @Component annotation from HostDaoImpl And unused method
---
.../src/main/java/com/cloud/host/dao/HostDao.java | 2 -
.../main/java/com/cloud/host/dao/HostDaoImpl.java | 12 -
.../hypervisor/CloudZonesStartupProcessor.java | 327 +--------------------
3 files changed, 6 insertions(+), 335 deletions(-)
diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
index 71c9cd2..2de3fcd 100644
--- a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
+++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
@@ -61,8 +61,6 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag);
- long countRoutingHostsByDataCenter(long dcId);
-
List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId);
boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo);
diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
index 5af099d..6eec7ba 100644
--- a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
@@ -32,7 +32,6 @@ import javax.inject.Inject;
import javax.persistence.TableGenerator;
import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
import com.cloud.agent.api.VgpuTypesInfo;
import com.cloud.cluster.agentlb.HostTransferMapVO;
@@ -70,7 +69,6 @@ import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.UpdateBuilder;
import com.cloud.utils.exception.CloudRuntimeException;
-@Component
@DB
@TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1)
public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao {
@@ -919,16 +917,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return s_seqFetcher.getNextSequence(Long.class, tg, hostId);
}
- /*TODO: this is used by mycloud, check if it needs resource state Enabled */
- @Override
- public long countRoutingHostsByDataCenter(long dcId) {
- SearchCriteria<Long> sc = CountRoutingByDc.create();
- sc.setParameters("dc", dcId);
- sc.setParameters("type", Host.Type.Routing);
- sc.setParameters("status", Status.Up.toString());
- return customSearch(sc, null).get(0);
- }
-
@Override
public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
// lock target row from beginning to avoid lock-promotion caused deadlock
diff --git a/server/src/main/java/com/cloud/hypervisor/CloudZonesStartupProcessor.java b/server/src/main/java/com/cloud/hypervisor/CloudZonesStartupProcessor.java
index 2aa9b04..8d674a5 100644
--- a/server/src/main/java/com/cloud/hypervisor/CloudZonesStartupProcessor.java
+++ b/server/src/main/java/com/cloud/hypervisor/CloudZonesStartupProcessor.java
@@ -25,33 +25,20 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
-import org.apache.cloudstack.api.ResourceDetail;
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-
import com.cloud.agent.AgentManager;
import com.cloud.agent.StartupCommandProcessor;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.manager.authn.AgentAuthnException;
-import com.cloud.configuration.ConfigurationManager;
-import com.cloud.configuration.ZoneConfig;
-import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
-import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.dc.dao.DataCenterDetailsDao;
import com.cloud.dc.dao.HostPodDao;
-import com.cloud.exception.ConnectionException;
-import com.cloud.host.DetailVO;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
-import com.cloud.host.dao.HostDetailsDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.component.AdapterBase;
-import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.MacAddress;
import com.cloud.utils.net.NetUtils;
@@ -63,26 +50,13 @@ import com.cloud.utils.net.NetUtils;
public class CloudZonesStartupProcessor extends AdapterBase implements StartupCommandProcessor {
private static final Logger s_logger = Logger.getLogger(CloudZonesStartupProcessor.class);
@Inject
- ClusterDao _clusterDao = null;
- @Inject
- ConfigurationDao _configDao = null;
- @Inject
- DataCenterDao _zoneDao = null;
- @Inject
- HostDao _hostDao = null;
- @Inject
- private HostDetailsDao hostDetailsDao;
+ private DataCenterDao _zoneDao = null;
@Inject
- HostPodDao _podDao = null;
+ private HostPodDao _podDao = null;
@Inject
- DataCenterDetailsDao _zoneDetailsDao = null;
+ private AgentManager _agentManager = null;
- @Inject
- AgentManager _agentManager = null;
- @Inject
- ConfigurationManager _configurationManager = null;
-
- long _nodeId = -1;
+ private long _nodeId = -1;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@@ -96,252 +70,9 @@ public class CloudZonesStartupProcessor extends AdapterBase implements StartupCo
}
@Override
- public boolean processInitialConnect(StartupCommand[] cmd) throws ConnectionException {
+ public boolean processInitialConnect(StartupCommand[] cmd) {
StartupCommand startup = cmd[0];
- if (startup instanceof StartupRoutingCommand) {
- return processHostStartup((StartupRoutingCommand)startup);
- } else if (startup instanceof StartupStorageCommand) {
- return processStorageStartup((StartupStorageCommand)startup);
- }
-
- return false;
- }
-
- protected boolean processHostStartup(StartupRoutingCommand startup) throws ConnectionException {
- /*
- boolean found = false;
- Type type = Host.Type.Routing;
- final Map<String, String> hostDetails = startup.getHostDetails();
- HostVO server = _hostDao.findByGuid(startup.getGuid());
- if (server == null) {
- server = _hostDao.findByGuid(startup.getGuidWithoutResource());
- }
- if (server != null && server.getRemoved() == null) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Found the host " + server.getId() + " by guid: "
- + startup.getGuid());
- }
- found = true;
-
- } else {
- server = new HostVO(startup.getGuid());
- }
- server.setDetails(hostDetails);
-
- try {
- updateComputeHost(server, startup, type);
- } catch (AgentAuthnException e) {
- throw new ConnectionException(true, "Failed to authorize host, invalid configuration", e);
- }
- if (!found) {
- server.setHostAllocationState(Host.HostAllocationState.Enabled);
- server = _hostDao.persist(server);
- } else {
- if (!_hostDao.connect(server, _nodeId)) {
- throw new CloudRuntimeException(
- "Agent cannot connect because the current state is "
- + server.getStatus().toString());
- }
- s_logger.info("Old " + server.getType().toString()
- + " host reconnected w/ id =" + server.getId());
- }
- */
- return true;
-
- }
-
- protected void updateComputeHost(final HostVO host, final StartupCommand startup, final Host.Type type) throws AgentAuthnException {
-
- String zoneToken = startup.getDataCenter();
- if (zoneToken == null) {
- s_logger.warn("No Zone Token passed in, cannot not find zone for the agent");
- throw new AgentAuthnException("No Zone Token passed in, cannot not find zone for agent");
- }
-
- DataCenterVO zone = _zoneDao.findByToken(zoneToken);
- if (zone == null) {
- zone = _zoneDao.findByName(zoneToken);
- if (zone == null) {
- try {
- long zoneId = Long.parseLong(zoneToken);
- zone = _zoneDao.findById(zoneId);
- if (zone == null) {
- throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
- }
- } catch (NumberFormatException nfe) {
- throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
- }
- }
- }
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Successfully loaded the DataCenter from the zone token passed in ");
- }
-
- long zoneId = zone.getId();
- ResourceDetail maxHostsInZone = _zoneDetailsDao.findDetail(zoneId, ZoneConfig.MaxHosts.key());
- if (maxHostsInZone != null) {
- long maxHosts = Long.parseLong(maxHostsInZone.getValue());
- long currentCountOfHosts = _hostDao.countRoutingHostsByDataCenter(zoneId);
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Number of hosts in Zone:" + currentCountOfHosts + ", max hosts limit: " + maxHosts);
- }
- if (currentCountOfHosts >= maxHosts) {
- throw new AgentAuthnException("Number of running Routing hosts in the Zone:" + zone.getName() + " is already at the max limit:" + maxHosts +
- ", cannot start one more host");
- }
- }
-
- HostPodVO pod = null;
-
- if (startup.getPrivateIpAddress() == null) {
- s_logger.warn("No private IP address passed in for the agent, cannot not find pod for agent");
- throw new AgentAuthnException("No private IP address passed in for the agent, cannot not find pod for agent");
- }
-
- if (startup.getPrivateNetmask() == null) {
- s_logger.warn("No netmask passed in for the agent, cannot not find pod for agent");
- throw new AgentAuthnException("No netmask passed in for the agent, cannot not find pod for agent");
- }
-
- if (host.getPodId() != null) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Pod is already created for this agent, looks like agent is reconnecting...");
- }
- pod = _podDao.findById(host.getPodId());
- if (!checkCIDR(type, pod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
- pod = null;
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Subnet of Pod does not match the subnet of the agent, not using this Pod: " + host.getPodId());
- }
- } else {
- updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
- }
- }
-
- if (pod == null) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Trying to detect the Pod to use from the agent's ip address and netmask passed in ");
- }
-
- //deduce pod
- boolean podFound = false;
- List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
- for (HostPodVO hostPod : podsInZone) {
- if (checkCIDR(type, hostPod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
- pod = hostPod;
-
- //found the default POD having the same subnet.
- updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
- podFound = true;
- break;
- }
- }
-
- if (!podFound) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Creating a new Pod since no default Pod found that matches the agent's ip address and netmask passed in ");
- }
-
- if (startup.getGatewayIpAddress() == null) {
- s_logger.warn("No Gateway IP address passed in for the agent, cannot create a new pod for the agent");
- throw new AgentAuthnException("No Gateway IP address passed in for the agent, cannot create a new pod for the agent");
- }
- //auto-create a new pod, since pod matching the agent's ip is not found
- String podName = "POD-" + (podsInZone.size() + 1);
- try {
- String gateway = startup.getGatewayIpAddress();
- String cidr = NetUtils.getCidrFromGatewayAndNetmask(gateway, startup.getPrivateNetmask());
- String[] cidrPair = cidr.split("\\/");
- String cidrAddress = cidrPair[0];
- long cidrSize = Long.parseLong(cidrPair[1]);
- String startIp = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize);
- String endIp = NetUtils.getIpRangeEndIpFromCidr(cidrAddress, cidrSize);
- pod = _configurationManager.createPod(-1, podName, zoneId, gateway, cidr, startIp, endIp, null, true);
- } catch (Exception e) {
- // no longer tolerate exception during the cluster creation phase
- throw new CloudRuntimeException("Unable to create new Pod " + podName + " in Zone: " + zoneId, e);
- }
-
- }
- }
- final StartupRoutingCommand scc = (StartupRoutingCommand)startup;
-
- ClusterVO cluster = null;
- if (host.getClusterId() != null) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Cluster is already created for this agent, looks like agent is reconnecting...");
- }
- cluster = _clusterDao.findById(host.getClusterId());
- }
- if (cluster == null) {
- //auto-create cluster - assume one host per cluster
- String clusterName = "Cluster-" + startup.getPrivateIpAddress();
- ClusterVO existingCluster = _clusterDao.findBy(clusterName, pod.getId());
- if (existingCluster != null) {
- cluster = existingCluster;
- } else {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Creating a new Cluster for this agent with name: " + clusterName + " in Pod: " + pod.getId() + ", in Zone:" + zoneId);
- }
-
- cluster = new ClusterVO(zoneId, pod.getId(), clusterName);
- cluster.setHypervisorType(scc.getHypervisorType().toString());
- try {
- cluster = _clusterDao.persist(cluster);
- } catch (Exception e) {
- // no longer tolerate exception during the cluster creation phase
- throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + pod.getId() + " and data center " + zoneId, e);
- }
- }
- }
-
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Detected Zone: " + zoneId + ", Pod: " + pod.getId() + ", Cluster:" + cluster.getId());
- }
- host.setDataCenterId(zone.getId());
- host.setPodId(pod.getId());
- host.setClusterId(cluster.getId());
- host.setPrivateIpAddress(startup.getPrivateIpAddress());
- host.setPrivateNetmask(startup.getPrivateNetmask());
- host.setPrivateMacAddress(startup.getPrivateMacAddress());
- host.setPublicIpAddress(startup.getPublicIpAddress());
- host.setPublicMacAddress(startup.getPublicMacAddress());
- host.setPublicNetmask(startup.getPublicNetmask());
- host.setStorageIpAddress(startup.getStorageIpAddress());
- host.setStorageMacAddress(startup.getStorageMacAddress());
- host.setStorageNetmask(startup.getStorageNetmask());
- host.setVersion(startup.getVersion());
- host.setName(startup.getName());
- host.setType(type);
- host.setStorageUrl(startup.getIqn());
- host.setLastPinged(System.currentTimeMillis() >> 10);
- host.setCaps(scc.getCapabilities());
- host.setCpus(scc.getCpus());
- host.setTotalMemory(scc.getMemory());
- host.setSpeed(scc.getSpeed());
- HypervisorType hyType = scc.getHypervisorType();
- host.setHypervisorType(hyType);
- host.setHypervisorVersion(scc.getHypervisorVersion());
-
- updateHostDetails(host, scc);
- }
-
- private void updateHostDetails(HostVO host, StartupRoutingCommand startupRoutingCmd) {
- final String name = "supportsResign";
- final String value = String.valueOf(startupRoutingCmd.getSupportsClonedVolumes());
-
- DetailVO hostDetail = hostDetailsDao.findDetail(host.getId(), name);
-
- if (hostDetail != null) {
- hostDetail.setValue(value);
-
- hostDetailsDao.update(hostDetail.getId(), hostDetail);
- }
- else {
- hostDetail = new DetailVO(host.getId(), name, value);
-
- hostDetailsDao.persist(hostDetail);
- }
+ return startup instanceof StartupRoutingCommand || startup instanceof StartupStorageCommand;
}
private boolean checkCIDR(Host.Type type, HostPodVO pod, String serverPrivateIP, String serverPrivateNetmask) {
@@ -378,52 +109,6 @@ public class CloudZonesStartupProcessor extends AdapterBase implements StartupCo
}
}
- protected boolean processStorageStartup(StartupStorageCommand startup) throws ConnectionException {
- /*
- if (startup.getResourceType() != Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE) {
- return false;
- }
- boolean found = false;
- Type type = Host.Type.LocalSecondaryStorage;
- final Map<String, String> hostDetails = startup.getHostDetails();
- HostVO server = _hostDao.findByGuid(startup.getGuid());
- if (server == null) {
- server = _hostDao.findByGuid(startup.getGuidWithoutResource());
- }
- if (server != null && server.getRemoved() == null) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Found the host " + server.getId() + " by guid: "
- + startup.getGuid());
- }
- found = true;
-
- } else {
- server = new HostVO(startup.getGuid());
- }
- server.setDetails(hostDetails);
-
- try {
- updateSecondaryHost(server, startup, type);
- } catch (AgentAuthnException e) {
- throw new ConnectionException(true, "Failed to authorize host, invalid configuration", e);
- }
- if (!found) {
- server.setHostAllocationState(Host.HostAllocationState.Enabled);
- server = _hostDao.persist(server);
- } else {
- if (!_hostDao.connect(server, _nodeId)) {
- throw new CloudRuntimeException(
- "Agent cannot connect because the current state is "
- + server.getStatus().toString());
- }
- s_logger.info("Old " + server.getType().toString()
- + " host reconnected w/ id =" + server.getId());
- }
- */
- return true;
-
- }
-
protected void updateSecondaryHost(final HostVO host, final StartupStorageCommand startup, final Host.Type type) throws AgentAuthnException {
String zoneToken = startup.getDataCenter();
--
To stop receiving notification emails like this one, please contact
dahn@apache.org.