mirror of https://github.com/apache/cloudstack.git
bug 6363:
1. delete local storage when delete host 2. delete host detail when delete host 3. allow one host in maintance mode in a cluster instead of in a pod status 6363: resolved fixed
This commit is contained in:
parent
b5510a9614
commit
e8a5872655
|
|
@ -28,4 +28,6 @@ public interface DetailsDao extends GenericDao<DetailVO, Long> {
|
|||
void persist(long hostId, Map<String, String> details);
|
||||
|
||||
DetailVO findDetail(long hostId, String name);
|
||||
|
||||
void deleteDetails(long hostId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,17 @@ public class DetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements De
|
|||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDetails(long hostId) {
|
||||
SearchCriteria sc = HostSearch.create();
|
||||
sc.setParameters("hostId", hostId);
|
||||
|
||||
List<DetailVO> results = search(sc, null);
|
||||
for (DetailVO result : results) {
|
||||
delete(result.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist(long hostId, Map<String, String> details) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import com.cloud.utils.db.GenericDao;
|
|||
public interface HostDao extends GenericDao<HostVO, Long> {
|
||||
List<HostVO> listBy(Host.Type type, Long clusterId, Long podId, long dcId);
|
||||
|
||||
long countBy(long podId, Status... statuses);
|
||||
long countBy(long clusterId, Status... statuses);
|
||||
|
||||
List<HostVO> listByDataCenter(long dcId);
|
||||
List<HostVO> listByHostPod(long podId);
|
||||
|
|
|
|||
|
|
@ -91,8 +91,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
_vmHostDao = ComponentLocator.inject(VmHostDaoImpl.class);
|
||||
|
||||
MaintenanceCountSearch = createSearchBuilder();
|
||||
MaintenanceCountSearch.and("pod", MaintenanceCountSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||
MaintenanceCountSearch.select(Func.COUNT);
|
||||
MaintenanceCountSearch.and("cluster", MaintenanceCountSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
|
||||
MaintenanceCountSearch.and("status", MaintenanceCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
|
||||
MaintenanceCountSearch.done();
|
||||
|
||||
|
|
@ -203,18 +202,14 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
}
|
||||
|
||||
@Override
|
||||
public long countBy(long podId, Status... statuses) {
|
||||
public long countBy(long clusterId, Status... statuses) {
|
||||
SearchCriteria sc = MaintenanceCountSearch.create();
|
||||
|
||||
sc.setParameters("status", (Object[])statuses);
|
||||
sc.setParameters("pod", podId);
|
||||
sc.setParameters("cluster", clusterId);
|
||||
|
||||
List<Object[]> rs = searchAll(sc, null);
|
||||
if (rs.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (Long)(rs.get(0)[0]);
|
||||
List<HostVO> hosts = listActiveBy(sc);
|
||||
return hosts.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2210,15 +2210,19 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
|
|||
}
|
||||
|
||||
public boolean joinPool(String masterIp, String username, String password) {
|
||||
Connection slaveConn = null;
|
||||
Connection hostConn = null;
|
||||
Connection poolConn = null;
|
||||
Session slaveSession = null;
|
||||
URL slaveUrl = null;
|
||||
Session hostSession = null;
|
||||
URL hostUrl = null;
|
||||
|
||||
try {
|
||||
|
||||
// Connect and find out about the new connection to the new pool.
|
||||
poolConn = _connPool.masterConnect(masterIp, username, password);
|
||||
Set<Pool> pools = Pool.getAll(poolConn);
|
||||
Pool pool = pools.iterator().next();
|
||||
String poolUUID = pool.getUuid(poolConn);
|
||||
|
||||
//check if this host is already in pool
|
||||
Set<Host> hosts = Host.getAll(poolConn);
|
||||
for( Host host : hosts ) {
|
||||
|
|
@ -2227,13 +2231,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
|
|||
}
|
||||
}
|
||||
|
||||
slaveUrl = new URL("http://" + _host.ip);
|
||||
slaveConn = new Connection(slaveUrl, 100);
|
||||
slaveSession = Session.slaveLocalLoginWithPassword(slaveConn, _username, _password);
|
||||
hostUrl = new URL("http://" + _host.ip);
|
||||
hostConn = new Connection(hostUrl, 100);
|
||||
hostSession = Session.loginWithPassword(hostConn, _username, _password, APIVersion.latest().toString());
|
||||
|
||||
// Now join it.
|
||||
|
||||
Pool.join(slaveConn, masterIp, username, password);
|
||||
Pool.join(hostConn, masterIp, username, password);
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Joined the pool at " + masterIp);
|
||||
}
|
||||
|
|
@ -2245,12 +2249,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
|
|||
}
|
||||
|
||||
// check if the master of this host is set correctly.
|
||||
Connection c = new Connection(slaveUrl, 100);
|
||||
for (int i = 0; i < 15; i++) {
|
||||
Connection c = new Connection(hostUrl, 100);
|
||||
int i;
|
||||
for (i = 0 ; i < 15; i++) {
|
||||
|
||||
try {
|
||||
Session.loginWithPassword(c, _username, _password, APIVersion.latest().toString());
|
||||
s_logger.debug("Still waiting for the conversion to the master");
|
||||
s_logger.debug(_host.ip + " is still master, waiting for the conversion to the slave");
|
||||
Session.logout(c);
|
||||
c.dispose();
|
||||
} catch (Types.HostIsSlave e) {
|
||||
|
|
@ -2273,7 +2278,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
|
|||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if( i >= 15 ) {
|
||||
throw new CloudRuntimeException(_host.ip + " didn't change to slave after waiting 30 secondary");
|
||||
}
|
||||
_host.pool = poolUUID;
|
||||
return true;
|
||||
} catch (MalformedURLException e) {
|
||||
throw new CloudRuntimeException("Problem with url " + _host.ip);
|
||||
|
|
@ -2295,9 +2303,9 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
|
|||
}
|
||||
poolConn.dispose();
|
||||
}
|
||||
if(slaveSession != null) {
|
||||
if(hostSession != null) {
|
||||
try {
|
||||
Session.localLogout(slaveConn);
|
||||
Session.logout(hostConn);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
|
@ -6052,7 +6060,19 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
|
|||
private Answer execute(PoolEjectCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
String hostuuid = cmd.getHostuuid();
|
||||
|
||||
try {
|
||||
Map<Host, Host.Record> hostrs = Host.getAllRecords(conn);
|
||||
boolean found = false;
|
||||
for( Host.Record hr : hostrs.values() ) {
|
||||
if( hr.uuid.equals(hostuuid)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if( ! found) {
|
||||
s_logger.debug("host " + hostuuid + " has already been ejected from pool " + _host.pool);
|
||||
return new Answer(cmd);
|
||||
}
|
||||
Host host = Host.getByUuid(conn, hostuuid);
|
||||
Pool.eject(conn, host);
|
||||
return new Answer(cmd);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class StoragePoolVO implements StoragePool {
|
|||
@Column(name="name", updatable=false, nullable=false, length=255)
|
||||
private String name = null;
|
||||
|
||||
@Column(name="uuid", updatable=false, nullable=false, length=255)
|
||||
@Column(name="uuid", length=255)
|
||||
private String uuid = null;
|
||||
|
||||
@Column(name="pool_type", updatable=false, nullable=false, length=32)
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long> imp
|
|||
sc.setParameters("datacenterId", datacenterId);
|
||||
sc.setParameters("podId", podId);
|
||||
|
||||
return findOneBy(sc);
|
||||
return findOneActiveBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -517,39 +517,43 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
|
|||
if (host.getType() == Type.Routing && host.getHypervisorType() == Hypervisor.Type.XenServer ) {
|
||||
if (host.getClusterId() != null) {
|
||||
List<HostVO> hosts = _hostDao.listBy(Type.Routing, host.getClusterId(), host.getPodId(), host.getDataCenterId());
|
||||
boolean success = false;
|
||||
for( HostVO thost: hosts ) {
|
||||
long thostId = thost.getId();
|
||||
if( thostId == hostId ) continue;
|
||||
|
||||
PoolEjectCommand eject = new PoolEjectCommand(host.getGuid());
|
||||
Answer answer = easySend(thostId, eject);
|
||||
if( answer == null || !answer.getResult()) {
|
||||
if( answer != null && answer.getResult()) {
|
||||
s_logger.debug("Eject Host: " + hostId + " from " + thostId + " Succeed");
|
||||
success = true;
|
||||
break;
|
||||
|
||||
} else {
|
||||
s_logger.debug("Eject Host: " + hostId + " from " + thostId + " failed due to " + (answer != null ? answer.getDetails() : "no answer"));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if( !success ){
|
||||
throw new CloudRuntimeException("Unable to delete host " + hostId + " due to unable to eject it from pool");
|
||||
}
|
||||
}
|
||||
}
|
||||
txn.start();
|
||||
|
||||
|
||||
_dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
|
||||
AgentAttache attache = _agents.get(hostId);
|
||||
handleDisconnect(attache, Status.Event.Remove, false);
|
||||
|
||||
/*Disconnected agent needs special handling here*/
|
||||
host.setGuid(null);
|
||||
host.setClusterId(null);
|
||||
_hostDao.update(host.getId(), host);
|
||||
|
||||
//delete host details
|
||||
_hostDetailsDao.deleteDetails(hostId);
|
||||
host.setGuid(null);
|
||||
host.setClusterId(null);
|
||||
_hostDao.update(host.getId(), host);
|
||||
_hostDao.remove(hostId);
|
||||
|
||||
//delete the associated primary storage from db
|
||||
ComponentLocator locator = ComponentLocator.getLocator("management-server");
|
||||
_storagePoolHostDao = locator.getDao(StoragePoolHostDao.class);
|
||||
if (_storagePoolHostDao == null) {
|
||||
throw new ConfigurationException("Unable to get storage pool host dao: " + StoragePoolHostDao.class);
|
||||
}
|
||||
//1. Get the pool_ids from the host ref table
|
||||
ArrayList<Long> pool_ids = _storagePoolHostDao.getPoolIds(hostId);
|
||||
|
||||
|
|
@ -557,8 +561,14 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
|
|||
_storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
|
||||
|
||||
//3.For pool ids you got, delete entries in pool table where type='FileSystem' || 'LVM'
|
||||
if(!pool_ids.isEmpty()) {
|
||||
_storagePoolDao.deleteStoragePoolRecords(pool_ids);
|
||||
for( Long poolId : pool_ids) {
|
||||
StoragePoolVO storagePool = _storagePoolDao.findById(poolId);
|
||||
if( storagePool.isLocal()) {
|
||||
storagePool.setUuid(null);
|
||||
storagePool.setClusterId(null);
|
||||
_storagePoolDao.update(poolId, storagePool);
|
||||
_storagePoolDao.remove(poolId);
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -102,14 +102,38 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
|
|||
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password) throws DiscoveryException {
|
||||
Map<CitrixResourceBase, Map<String, String>> resources = new HashMap<CitrixResourceBase, Map<String, String>>();
|
||||
Connection conn = null;
|
||||
Connection slaveConn = null;
|
||||
if (!url.getScheme().equals("http")) {
|
||||
String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
|
||||
s_logger.debug(msg);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String cluster = null;
|
||||
if (clusterId == null) {
|
||||
String msg = "must specify cluster Id when add host";
|
||||
s_logger.debug(msg);
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
cluster = Long.toString(clusterId);
|
||||
}
|
||||
|
||||
String pod;
|
||||
if (podId == null) {
|
||||
String msg = "must specify pod Id when add host";
|
||||
s_logger.debug(msg);
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
pod = Long.toString(podId);
|
||||
}
|
||||
|
||||
try {
|
||||
String poolUuid = null;
|
||||
List<HostVO> eHosts = _hostDao.listByCluster(clusterId);
|
||||
if( eHosts.size() > 0 ) {
|
||||
HostVO eHost = eHosts.get(0);
|
||||
_hostDao.loadDetails(eHost);
|
||||
poolUuid = eHost.getDetail("pool");
|
||||
}
|
||||
|
||||
String hostname = url.getHost();
|
||||
InetAddress ia = InetAddress.getByName(hostname);
|
||||
String addr = ia.getHostAddress();
|
||||
|
|
@ -121,26 +145,14 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
|
|||
s_logger.debug(msg);
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
String pod;
|
||||
if (podId == null) {
|
||||
Map<Pool, Pool.Record> pools = Pool.getAllRecords(conn);
|
||||
assert pools.size() == 1 : "Pools are not one....where on earth have i been? " + pools.size();
|
||||
|
||||
pod = pools.values().iterator().next().uuid;
|
||||
} else {
|
||||
pod = Long.toString(podId);
|
||||
if( poolUuid == null ) {
|
||||
Set<Pool> pools = Pool.getAll(conn);
|
||||
Pool pool = pools.iterator().next();
|
||||
Pool.Record pr = pool.getRecord(conn);
|
||||
poolUuid = pr.uuid;
|
||||
}
|
||||
String cluster = null;
|
||||
if (clusterId != null) {
|
||||
cluster = Long.toString(clusterId);
|
||||
}
|
||||
Set<Pool> pools = Pool.getAll(conn);
|
||||
Pool pool = pools.iterator().next();
|
||||
Pool.Record pr = pool.getRecord(conn);
|
||||
String poolUuid = pr.uuid;
|
||||
|
||||
Map<Host, Host.Record> hosts = Host.getAllRecords(conn);
|
||||
Host master = pr.master;
|
||||
|
||||
if (_checkHvm) {
|
||||
for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
|
||||
|
|
@ -192,6 +204,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
|
|||
params.put("zone", Long.toString(dcId));
|
||||
params.put("guid", record.uuid);
|
||||
params.put("pod", pod);
|
||||
|
||||
params.put("cluster", cluster);
|
||||
if (_increase != null) {
|
||||
params.put(Config.XenPreallocatedLunSizeRange.name(), _increase);
|
||||
|
|
@ -393,6 +406,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
|
|||
throw new DiscoveryException("Unable to join the pool");
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -671,7 +671,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID.");
|
||||
}
|
||||
|
||||
if (_hostDao.countBy(host.getPodId(), Status.PrepareForMaintenance, Status.ErrorInMaintenance, Status.Maintenance) > 0) {
|
||||
if (_hostDao.countBy(host.getClusterId(), Status.PrepareForMaintenance, Status.ErrorInMaintenance, Status.Maintenance) > 0) {
|
||||
throw new InvalidParameterValueException("There are other servers in maintenance mode.");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -834,7 +834,7 @@ CREATE TABLE `cloud`.`load_balancer` (
|
|||
CREATE TABLE `cloud`.`storage_pool` (
|
||||
`id` bigint unsigned UNIQUE NOT NULL,
|
||||
`name` varchar(255) COMMENT 'should be NOT NULL',
|
||||
`uuid` varchar(255) UNIQUE NOT NULL,
|
||||
`uuid` varchar(255) UNIQUE,
|
||||
`pool_type` varchar(32) NOT NULL,
|
||||
`port` int unsigned NOT NULL,
|
||||
`data_center_id` bigint unsigned NOT NULL,
|
||||
|
|
|
|||
Loading…
Reference in New Issue