From 6de28bb1a40ce094fbd18fcf4df3386765a2ce38 Mon Sep 17 00:00:00 2001 From: Anthony Xu Date: Wed, 26 Mar 2014 14:18:17 -0700 Subject: [PATCH] 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 --- .../com/cloud/agent/api/PoolEjectCommand.java | 44 --------------- .../vmware/resource/VmwareResource.java | 10 ---- .../xen/discoverer/XcpServerDiscoverer.java | 29 ---------- .../xen/resource/CitrixResourceBase.java | 55 ------------------- 4 files changed, 138 deletions(-) delete mode 100644 core/src/com/cloud/agent/api/PoolEjectCommand.java diff --git a/core/src/com/cloud/agent/api/PoolEjectCommand.java b/core/src/com/cloud/agent/api/PoolEjectCommand.java deleted file mode 100644 index fa6b6517971..00000000000 --- a/core/src/com/cloud/agent/api/PoolEjectCommand.java +++ /dev/null @@ -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; - } - -} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 4e46c524047..f84d6824386 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -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) { diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index bd0f55c60de..9852edac11d 100755 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -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 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); } diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index d3fdb193bc0..a57b606bce2 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -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 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 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);