in XenServer, host eject may fail due to diffent reasons, it's hard for CS to handle all failure.

in CS, removing a host means CS will not manage the host, admin needs to eject the host from XS pool outside of CS
This commit is contained in:
Anthony Xu 2014-03-26 14:18:17 -07:00
parent 6d103e62fe
commit 6de28bb1a4
4 changed files with 0 additions and 138 deletions

View File

@ -1,44 +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.api;
public class PoolEjectCommand extends Command {
private String hostuuid;
public String getHostuuid() {
return hostuuid;
}
public void setHostuuid(String hostuuid) {
this.hostuuid = hostuuid;
}
public PoolEjectCommand() {
super();
}
public PoolEjectCommand(String hostuuid) {
super();
setHostuuid(hostuuid);
}
@Override
public boolean executeInSequence() {
return true;
}
}

View File

@ -162,7 +162,6 @@ import com.cloud.agent.api.PingRoutingCommand;
import com.cloud.agent.api.PingTestCommand;
import com.cloud.agent.api.PlugNicAnswer;
import com.cloud.agent.api.PlugNicCommand;
import com.cloud.agent.api.PoolEjectCommand;
import com.cloud.agent.api.PrepareForMigrationAnswer;
import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.PvlanSetupCommand;
@ -465,8 +464,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
answer = execute((CheckOnHostCommand)cmd);
} else if (clz == ModifySshKeysCommand.class) {
answer = execute((ModifySshKeysCommand)cmd);
} else if (clz == PoolEjectCommand.class) {
answer = execute((PoolEjectCommand)cmd);
} else if (clz == NetworkUsageCommand.class) {
answer = execute((NetworkUsageCommand)cmd);
} else if (clz == StartCommand.class) {
@ -4161,13 +4158,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return new Answer(cmd);
}
protected Answer execute(PoolEjectCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource PoolEjectCommand: " + _gson.toJson(cmd));
}
return new Answer(cmd, false, "PoolEjectCommand is not available for vmware");
}
@Override
public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) {

View File

@ -40,7 +40,6 @@ import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.PoolEjectCommand;
import com.cloud.agent.api.SetupAnswer;
import com.cloud.agent.api.SetupCommand;
import com.cloud.agent.api.StartupCommand;
@ -730,34 +729,6 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
}
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
if (host.getClusterId() != null) {
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(com.cloud.host.Host.Type.Routing, host.getClusterId(), host.getPodId(), host.getDataCenterId());
boolean success = true;
for (HostVO thost : hosts) {
if (thost.getId() == host.getId()) {
continue;
}
long thostId = thost.getId();
PoolEjectCommand eject = new PoolEjectCommand(host.getGuid());
Answer answer = _agentMgr.easySend(thostId, eject);
if (answer != null && answer.getResult()) {
s_logger.debug("Eject Host: " + host.getId() + " from " + thostId + " Succeed");
success = true;
break;
} else {
success = false;
s_logger.warn("Eject Host: " + host.getId() + " from " + thostId + " failed due to " + (answer != null ? answer.getDetails() : "no answer"));
}
}
if (!success) {
String msg =
"Unable to eject host " + host.getGuid() + " due to there is no host up in this cluster, please execute xe pool-eject host-uuid=" + host.getGuid() +
"in this host " + host.getPrivateIpAddress();
s_logger.warn(msg);
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Unable to eject host " + host.getGuid(), msg);
}
}
return new DeleteHostAnswer(true);
}

View File

@ -87,7 +87,6 @@ import com.cloud.agent.api.PingRoutingWithOvsCommand;
import com.cloud.agent.api.PingTestCommand;
import com.cloud.agent.api.PlugNicAnswer;
import com.cloud.agent.api.PlugNicCommand;
import com.cloud.agent.api.PoolEjectCommand;
import com.cloud.agent.api.PrepareForMigrationAnswer;
import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.PvlanSetupCommand;
@ -499,8 +498,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return execute((CheckOnHostCommand)cmd);
} else if (clazz == ModifySshKeysCommand.class) {
return execute((ModifySshKeysCommand)cmd);
} else if (clazz == PoolEjectCommand.class) {
return execute((PoolEjectCommand)cmd);
} else if (clazz == StartCommand.class) {
return execute((StartCommand)cmd);
} else if (clazz == CheckSshCommand.class) {
@ -7055,58 +7052,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
_agentControl = agentControl;
}
protected Answer execute(PoolEjectCommand cmd) {
Connection conn = getConnection();
String hostuuid = cmd.getHostuuid();
try {
Host host = Host.getByUuid(conn, hostuuid);
if (isRefNull(host)) {
s_logger.debug("host " + hostuuid + " has already been ejected from pool " + _host.pool);
return new Answer(cmd);
}
// remove all tags cloud stack add before eject
Host.Record hr = host.getRecord(conn);
Iterator<String> it = hr.tags.iterator();
while (it.hasNext()) {
String tag = it.next();
if (tag.contains("cloud")) {
it.remove();
}
}
host.setTags(conn, hr.tags);
Pool pool = Pool.getByUuid(conn, _host.pool);
Pool.Record poolr = pool.getRecord(conn);
Host.Record hostr = poolr.master.getRecord(conn);
if (_host.uuid.equals(hostr.uuid)) {
Map<Host, Host.Record> hostMap = Host.getAllRecords(conn);
if (hostMap.size() > 1) {
String msg = "This host is XS master, please designate a new XS master throught XenCenter before you delete this host from CS";
s_logger.debug(msg);
return new Answer(cmd, false, msg);
}
}
// eject from pool
try {
Pool.eject(conn, host);
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException e) {
}
} catch (XenAPIException e) {
String msg = "Unable to eject host " + _host.uuid + " due to " + e.toString();
s_logger.warn(msg);
host.destroy(conn);
}
return new Answer(cmd);
} catch (Exception e) {
String msg = "Exception Unable to destroy host " + _host.uuid + " in xenserver database due to " + e.toString();
s_logger.warn(msg, e);
return new Answer(cmd, false, msg);
}
}
private Answer execute(CleanupNetworkRulesCmd cmd) {
if (!_canBridgeFirewall) {
return new Answer(cmd, true, null);