cloudstack-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CLOUDSTACK-10307) Remove unused things from HostDaoImpl
Date Tue, 27 Mar 2018 10:47:00 GMT

    [ https://issues.apache.org/jira/browse/CLOUDSTACK-10307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16415407#comment-16415407
] 

ASF GitHub Bot commented on CLOUDSTACK-10307:
---------------------------------------------

DaanHoogland closed pull request #2438: [CLOUDSTACK-10307] Remove unused things from HostDaoImpl
URL: https://github.com/apache/cloudstack/pull/2438
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 9e967e34efd..95b0f70e70e 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
@@ -62,8 +62,6 @@
 
     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 c1403d08609..be2418a0cc7 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
@@ -33,7 +33,6 @@
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.commons.lang3.StringUtils;
 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.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 {
@@ -920,16 +918,6 @@ public long getNextSequence(long hostId) {
         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 2aa9b04b2ae..8d674a5f9a8 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 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 @@
 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 boolean configure(String name, Map<String, Object> params)
throws Configu
     }
 
     @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 @@ private void updatePodNetmaskIfNeeded(HostPodVO pod, String agentNetmask)
{
         }
     }
 
-    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();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Remove unused things from HostDaoImpl
> -------------------------------------
>
>                 Key: CLOUDSTACK-10307
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10307
>             Project: CloudStack
>          Issue Type: Improvement
>      Security Level: Public(Anyone can view this level - this is the default.) 
>            Reporter: Rafael Weingärtner
>            Assignee: Rafael Weingärtner
>            Priority: Minor
>
> Remove unnecessary annotation of HostDaoImpl. While removing this annotation I noticed
that one of the methods were not necessary. While removing it, I found some code in CloudZonesStartupProcessor
that was also not used, and removed it.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message