Separate agentmanager from server code. Moved out ssvm. Remove methods that shouldn't be used

This commit is contained in:
Alex Huang 2013-07-29 11:43:53 -07:00
parent f0f55226de
commit 46e644e134
10 changed files with 23 additions and 293 deletions

View File

@ -58,7 +58,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager {
private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class);
private Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>();
private final Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>();
@Inject
HostDao hostDao;
@Inject
@ -222,12 +222,6 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
}
@Override
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException {
// TODO Auto-generated method stub
return false;
}
@Override
public Answer sendTo(Long dcId, HypervisorType type, Command cmd) {
// TODO Auto-generated method stub
@ -253,12 +247,6 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
return false;
}
@Override
public AgentAttache findAttache(long hostId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void disconnectWithoutInvestigation(long hostId, Event event) {
// TODO Auto-generated method stub
@ -284,15 +272,9 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
}
@Override
public Answer sendToSSVM(Long dcId, Command cmd) {
public boolean isAgentAttached(long hostId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void disconnectWithInvestigation(long hostId, Event event) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -16,8 +16,6 @@
// under the License.
package com.cloud.agent;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
@ -28,7 +26,6 @@ import com.cloud.exception.ConnectionException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.Status.Event;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.resource.ServerResource;
import com.cloud.utils.component.Manager;
@ -133,8 +130,6 @@ public interface AgentManager extends Manager {
*/
void unregisterForHostEvents(int id);
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException;
Answer sendTo(Long dcId, HypervisorType type, Command cmd);
@ -145,7 +140,7 @@ public interface AgentManager extends Manager {
public boolean agentStatusTransitTo(HostVO host, Status.Event e, long msId);
public AgentAttache findAttache(long hostId);
boolean isAgentAttached(long hostId);
void disconnectWithoutInvestigation(long hostId, Status.Event event);
@ -154,7 +149,4 @@ public interface AgentManager extends Manager {
public void pullAgentOutMaintenance(long hostId);
boolean reconnect(long hostId);
Answer sendToSSVM(Long dcId, final Command cmd);
void disconnectWithInvestigation(final long hostId, final Status.Event event);
}

View File

@ -329,7 +329,7 @@ public abstract class AgentAttache {
public boolean equals(Object obj) {
try {
AgentAttache that = (AgentAttache) obj;
return this._id == that._id;
return _id == that._id;
} catch (ClassCastException e) {
assert false : "Who's sending an " + obj.getClass().getSimpleName() + " to AgentAttache.equals()? ";
return false;
@ -485,12 +485,6 @@ public abstract class AgentAttache {
*/
public abstract void send(Request req) throws AgentUnavailableException;
/**
* Update password.
* @param new/changed password.
*/
public abstract void updatePassword(Command new_password);
/**
* Process disconnect.
* @param state state of the agent.

View File

@ -123,8 +123,6 @@ import com.cloud.utils.nio.Task;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.VMInstanceDao;
import edu.emory.mathcs.backport.java.util.Collections;
/**
* Implementation of the Agent Manager. This class controls the connection to the agents.
*
@ -372,7 +370,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
}
@Override
public AgentAttache findAttache(long hostId) {
AgentAttache attache = null;
synchronized (_agents) {
@ -381,29 +378,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
return attache;
}
private void sendToSSVM(final long dcId, final Command cmd, final Listener listener) throws AgentUnavailableException {
List<HostVO> ssAHosts = _ssvmMgr.listUpAndConnectingSecondaryStorageVmHost(dcId);
if (ssAHosts == null || ssAHosts.isEmpty() ) {
throw new AgentUnavailableException("No ssvm host found", -1);
}
Collections.shuffle(ssAHosts);
HostVO ssAhost = ssAHosts.get(0);
send(ssAhost.getId(), new Commands(cmd), listener);
}
@Override
public Answer sendToSSVM(final Long dcId, final Command cmd) {
List<HostVO> ssAHosts = _ssvmMgr.listUpAndConnectingSecondaryStorageVmHost(dcId);
if (ssAHosts == null || ssAHosts.isEmpty() ) {
return new Answer(cmd, false, "can not find secondary storage VM agent for data center " + dcId);
}
Collections.shuffle(ssAHosts);
HostVO ssAhost = ssAHosts.get(0);
return easySend(ssAhost.getId(), cmd);
}
@Override
public Answer sendTo(Long dcId, HypervisorType type, Command cmd) {
List<ClusterVO> clusters = _clusterDao.listByDcHyType(dcId, type.toString());
@ -1044,7 +1018,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
return true;
}
@Override
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException {
if (event == Event.AgentDisconnected) {
if (s_logger.isDebugEnabled()) {
@ -1062,6 +1035,11 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
return false;
}
@Override
public boolean isAgentAttached(long hostId) {
return findAttache(hostId) != null;
}
protected AgentAttache createAttacheForConnect(HostVO host, Link link) throws ConnectionException {
s_logger.debug("create ConnectedAgentAttache for " + host.getId());
AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), link, host.isInMaintenanceStates());
@ -1462,7 +1440,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
}
@Override
public void disconnectWithInvestigation(final long hostId, final Status.Event event) {
disconnectInternal(hostId, event, true);
}

View File

@ -26,8 +26,6 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
@ -35,7 +33,6 @@ import com.cloud.agent.api.Command;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.alert.AlertManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.ClusterDao;
@ -48,10 +45,9 @@ import com.cloud.host.Status.Event;
import com.cloud.host.dao.HostDao;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceState;
import com.cloud.utils.db.ConnectionConcierge;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.time.InaccurateClock;
import com.cloud.vm.VMInstanceVO;
@ -64,17 +60,18 @@ public class AgentMonitor extends Thread implements AgentMonitorService {
private long _pingTimeout = 120; // Default set to 120 seconds
@Inject private HostDao _hostDao;
private boolean _stop;
@Inject private AgentManager _agentMgr;
@Inject
private AgentManagerImpl _agentMgr;
@Inject private VMInstanceDao _vmDao;
@Inject private DataCenterDao _dcDao = null;
@Inject private HostPodDao _podDao = null;
@Inject private final DataCenterDao _dcDao = null;
@Inject private final HostPodDao _podDao = null;
@Inject private AlertManager _alertMgr;
private long _msId;
@Inject ClusterDao _clusterDao;
@Inject ResourceManager _resourceMgr;
// private ConnectionConcierge _concierge;
private Map<Long, Long> _pingMap;
private final Map<Long, Long> _pingMap;
public AgentMonitor() {
_pingMap = new ConcurrentHashMap<Long, Long>(10007);
@ -87,6 +84,7 @@ public class AgentMonitor extends Thread implements AgentMonitorService {
* agent or host id.
* @return null if the agent is not kept here. true if behind; false if not.
*/
@Override
public Boolean isAgentBehindOnPing(long agentId) {
Long pingTime = _pingMap.get(agentId);
if (pingTime == null) {
@ -95,10 +93,12 @@ public class AgentMonitor extends Thread implements AgentMonitorService {
return pingTime < (InaccurateClock.getTimeInSeconds() - _pingTimeout);
}
@Override
public Long getAgentPingTime(long agentId) {
return _pingMap.get(agentId);
}
@Override
public void pingBy(long agentId) {
_pingMap.put(agentId, InaccurateClock.getTimeInSeconds());
}
@ -168,6 +168,7 @@ public class AgentMonitor extends Thread implements AgentMonitorService {
s_logger.info("Agent Monitor is leaving the building!");
}
@Override
public void signalStop() {
_stop = true;
interrupt();

View File

@ -20,8 +20,6 @@ import java.nio.channels.ClosedChannelException;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Command;
import com.cloud.agent.transport.Request;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.host.Status;
@ -72,7 +70,7 @@ public class ConnectedAgentAttache extends AgentAttache {
public boolean equals(Object obj) {
try {
ConnectedAgentAttache that = (ConnectedAgentAttache) obj;
return super.equals(obj) && this._link == that._link && this._link != null;
return super.equals(obj) && _link == that._link && _link != null;
} catch (ClassCastException e) {
assert false : "Who's sending an " + obj.getClass().getSimpleName() + " to " + this.getClass().getSimpleName() + ".equals()? ";
return false;
@ -94,8 +92,4 @@ public class ConnectedAgentAttache extends AgentAttache {
}
}
@Override
public void updatePassword(Command newPassword) {
throw new IllegalStateException("Should not have come here ");
}
}

View File

@ -212,9 +212,4 @@ public class DirectAgentAttache extends AgentAttache {
}
}
@Override
public void updatePassword(Command new_password) {
_resource.executeRequest(new_password);
}
}

View File

@ -16,8 +16,6 @@
// under the License.
package com.cloud.agent.manager;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Command;
import com.cloud.agent.transport.Request;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.host.Status;
@ -47,10 +45,4 @@ public class DummyAttache extends AgentAttache {
}
@Override
public void updatePassword(Command newPassword) {
throw new IllegalStateException("Should not have come here ");
}
}

View File

@ -819,13 +819,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (!isForced && host.getResourceState() != ResourceState.Maintenance) {
throw new CloudRuntimeException("Host " + host.getUuid() + " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
}
/*
* TODO: check current agent status and updateAgentStatus to removed. If
* it was already removed, that means someone is deleting host
* concurrently, return. And consider the situation of CloudStack
* shutdown during delete. A global lock?
*/
AgentAttache attache = _agentMgr.findAttache(hostId);
// Get storage pool host mappings here because they can be removed as a
// part of handleDisconnect later
// TODO: find out the bad boy, what's a buggy logic!
@ -2204,8 +2197,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
private boolean doUpdateHostPassword(long hostId) {
AgentAttache attache = _agentMgr.findAttache(hostId);
if (attache == null) {
if (_agentMgr.isAgentAttached(hostId)) {
return false;
}
@ -2214,7 +2206,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
nv = _hostDetailsDao.findDetail(hostId, ApiConstants.PASSWORD);
String password = nv.getValue();
UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password);
attache.updatePassword(cmd);
_agentMgr.easySend(hostId, cmd);
return true;
}

View File

@ -1,189 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent;
import java.util.Map;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.springframework.stereotype.Component;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.manager.AgentAttache;
import com.cloud.agent.manager.Commands;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostVO;
import com.cloud.host.Status.Event;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.resource.ServerResource;
import com.cloud.utils.component.ManagerBase;
@Component
@Local(value = { AgentManager.class })
public class MockAgentManagerImpl extends ManagerBase implements AgentManager {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public Answer easySend(Long hostId, Command cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException {
// TODO Auto-generated method stub
return null;
}
@Override
public Answer[] send(Long hostId, Commands cmds) throws AgentUnavailableException, OperationTimedoutException {
// TODO Auto-generated method stub
return null;
}
@Override
public Answer[] send(Long hostId, Commands cmds, int timeout) throws AgentUnavailableException, OperationTimedoutException {
// TODO Auto-generated method stub
return null;
}
@Override
public long send(Long hostId, Commands cmds, Listener listener) throws AgentUnavailableException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int registerForHostEvents(Listener listener, boolean connections, boolean commands, boolean priority) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int registerForInitialConnects(StartupCommandProcessor creator, boolean priority) {
// TODO Auto-generated method stub
return 0;
}
@Override
public void unregisterForHostEvents(int id) {
// TODO Auto-generated method stub
}
@Override
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean reconnect(long hostId) {
// TODO Auto-generated method stub
return false;
}
@Override
public Answer sendTo(Long dcId, HypervisorType type, Command cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
// TODO Auto-generated method stub
return false;
}
@Override
public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean agentStatusTransitTo(HostVO host, Event e, long msId) {
// TODO Auto-generated method stub
return false;
}
@Override
public AgentAttache findAttache(long hostId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void pullAgentToMaintenance(long hostId) {
// TODO Auto-generated method stub
}
@Override
public void disconnectWithoutInvestigation(long hostId, Event event) {
// TODO Auto-generated method stub
}
@Override
public void pullAgentOutMaintenance(long hostId) {
// TODO Auto-generated method stub
}
@Override
public Answer sendToSSVM(Long dcId, Command cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public void disconnectWithInvestigation(long hostId, Event event) {
// TODO Auto-generated method stub
}
}