Repository: cloudstack Updated Branches: refs/heads/master ad6ac9bb1 -> 0c6758f91
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java new file mode 100644 index 0000000..5374e8e --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java @@ -0,0 +1,50 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen56; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.CheckOnHostAnswer; +import com.cloud.agent.api.CheckOnHostCommand; +import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; + +@ResourceWrapper(handles = CheckOnHostCommand.class) +public final class XenServer56CheckOnHostCommandWrapper extends CommandWrapper<CheckOnHostCommand, Answer, XenServer56Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer56CheckOnHostCommandWrapper.class); + + @Override + public Answer execute(final CheckOnHostCommand command, final XenServer56Resource xenServer56) { + final Boolean alive = xenServer56.checkHeartbeat(command.getHost().getGuid()); + String msg = ""; + if (alive == null) { + msg = " cannot determine "; + } else if ( alive == true) { + msg = "Heart beat is still going"; + } else { + msg = "Heart beat is gone so dead."; + } + s_logger.debug(msg); + return new CheckOnHostAnswer(command, alive, msg); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java new file mode 100644 index 0000000..f877a86 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java @@ -0,0 +1,73 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen56; + +import java.util.Set; + +import org.apache.log4j.Logger; +import org.apache.xmlrpc.XmlRpcException; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.FenceAnswer; +import com.cloud.agent.api.FenceCommand; +import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Types.XenAPIException; +import com.xensource.xenapi.VM; + +@ResourceWrapper(handles = FenceCommand.class) +public final class XenServer56FenceCommandWrapper extends CommandWrapper<FenceCommand, Answer, XenServer56Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer56FenceCommandWrapper.class); + + @Override + public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) { + final Connection conn = xenServer56.getConnection(); + try { + final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid()); + if (alive == null) { + s_logger.debug("Failed to check heartbeat, so unable to fence"); + return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence"); + } + if (alive) { + s_logger.debug("Heart beat is still going so unable to fence"); + return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence"); + } + final Set<VM> vms = VM.getByNameLabel(conn, command.getVmName()); + for (final VM vm : vms) { + s_logger.info("Fence command for VM " + command.getVmName()); + vm.powerStateReset(conn); + vm.destroy(conn); + } + return new FenceAnswer(command); + } catch (final XmlRpcException e) { + s_logger.warn("Unable to fence", e); + return new FenceAnswer(command, false, e.getMessage()); + } catch (final XenAPIException e) { + s_logger.warn("Unable to fence", e); + return new FenceAnswer(command, false, e.getMessage()); + } catch (final Exception e) { + s_logger.warn("Unable to fence", e); + return new FenceAnswer(command, false, e.getMessage()); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java new file mode 100644 index 0000000..ad414a4 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java @@ -0,0 +1,104 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen56; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.NetworkUsageAnswer; +import com.cloud.agent.api.NetworkUsageCommand; +import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.ExecutionResult; +import com.xensource.xenapi.Connection; + +@ResourceWrapper(handles = NetworkUsageCommand.class) +public final class XenServer56NetworkUsageCommandWrapper extends CommandWrapper<NetworkUsageCommand, Answer, XenServer56Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer56NetworkUsageCommandWrapper.class); + + @Override + public Answer execute(final NetworkUsageCommand command, final XenServer56Resource xenServer56) { + if (command.isForVpc()) { + return executeNetworkUsage(command, xenServer56); + } + try { + final Connection conn = xenServer56.getConnection(); + if (command.getOption() != null && command.getOption().equals("create")) { + final String result = xenServer56.networkUsage(conn, command.getPrivateIP(), "create", null); + final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L); + return answer; + } + final long[] stats = xenServer56.getNetworkStats(conn, command.getPrivateIP()); + final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]); + return answer; + } catch (final Exception ex) { + s_logger.warn("Failed to get network usage stats due to ", ex); + return new NetworkUsageAnswer(command, ex); + } + } + + protected NetworkUsageAnswer executeNetworkUsage(final NetworkUsageCommand command, final XenServer56Resource xenServer56) { + try { + final String option = command.getOption(); + final String publicIp = command.getGatewayIP(); + + String args = " -l " + publicIp + " "; + if (option.equals("get")) { + args += "-g"; + } else if (option.equals("create")) { + args += "-c"; + final String vpcCIDR = command.getVpcCIDR(); + args += " -v " + vpcCIDR; + } else if (option.equals("reset")) { + args += "-r"; + } else if (option.equals("vpn")) { + args += "-n"; + } else if (option.equals("remove")) { + args += "-d"; + } else { + return new NetworkUsageAnswer(command, "success", 0L, 0L); + } + + final ExecutionResult result = xenServer56.executeInVR(command.getPrivateIP(), "vpc_netusage.sh", args); + final String detail = result.getDetails(); + if (!result.isSuccess()) { + throw new Exception(" vpc network usage plugin call failed "); + } + if (option.equals("get") || option.equals("vpn")) { + final long[] stats = new long[2]; + if (detail != null) { + final String[] splitResult = detail.split(":"); + int i = 0; + while (i < splitResult.length - 1) { + stats[0] += Long.parseLong(splitResult[i++]); + stats[1] += Long.parseLong(splitResult[i++]); + } + return new NetworkUsageAnswer(command, "success", stats[0], stats[1]); + } + } + return new NetworkUsageAnswer(command, "success", 0L, 0L); + } catch (final Exception ex) { + s_logger.warn("Failed to get network usage stats due to ", ex); + return new NetworkUsageAnswer(command, ex); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java new file mode 100644 index 0000000..a03c36b --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java @@ -0,0 +1,94 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen56p1; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.apache.xmlrpc.XmlRpcException; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.FenceAnswer; +import com.cloud.agent.api.FenceCommand; +import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Types.XenAPIException; +import com.xensource.xenapi.VBD; +import com.xensource.xenapi.VDI; +import com.xensource.xenapi.VM; + +@ResourceWrapper(handles = FenceCommand.class) +public final class XenServer56FP1FenceCommandWrapper extends CommandWrapper<FenceCommand, Answer, XenServer56Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer56FP1FenceCommandWrapper.class); + + @Override + public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) { + final Connection conn = xenServer56.getConnection(); + try { + final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid()); + if ( alive == null ) { + s_logger.debug("Failed to check heartbeat, so unable to fence"); + return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence"); + } + if ( alive ) { + s_logger.debug("Heart beat is still going so unable to fence"); + return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence"); + } + final Set<VM> vms = VM.getByNameLabel(conn, command.getVmName()); + for (final VM vm : vms) { + final Set<VDI> vdis = new HashSet<VDI>(); + final Set<VBD> vbds = vm.getVBDs(conn); + for (final VBD vbd : vbds) { + final VDI vdi = vbd.getVDI(conn); + if (!xenServer56.isRefNull(vdi)) { + vdis.add(vdi); + } + } + s_logger.info("Fence command for VM " + command.getVmName()); + vm.powerStateReset(conn); + vm.destroy(conn); + for (final VDI vdi : vdis) { + final Map<String, String> smConfig = vdi.getSmConfig(conn); + for (final String key : smConfig.keySet()) { + if (key.startsWith("host_")) { + vdi.removeFromSmConfig(conn, key); + break; + } + } + } + } + return new FenceAnswer(command); + } catch (final XmlRpcException e) { + s_logger.warn("Unable to fence", e); + return new FenceAnswer(command, false, e.getMessage()); + } catch (final XenAPIException e) { + s_logger.warn("Unable to fence", e); + return new FenceAnswer(command, false, e.getMessage()); + } catch (final Exception e) { + s_logger.warn("Unable to fence", e); + return new FenceAnswer(command, false, e.getMessage()); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java new file mode 100644 index 0000000..72208ea --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java @@ -0,0 +1,73 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen610; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.storage.MigrateVolumeAnswer; +import com.cloud.agent.api.storage.MigrateVolumeCommand; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.SR; +import com.xensource.xenapi.Task; +import com.xensource.xenapi.Types; +import com.xensource.xenapi.VDI; + +@ResourceWrapper(handles = MigrateVolumeCommand.class) +public final class XenServer610MigrateVolumeCommandWrapper extends CommandWrapper<MigrateVolumeCommand, Answer, XenServer610Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer610MigrateVolumeCommandWrapper.class); + + @Override + public Answer execute(final MigrateVolumeCommand command, final XenServer610Resource xenServer610Resource) { + final Connection connection = xenServer610Resource.getConnection(); + final String volumeUUID = command.getVolumePath(); + final StorageFilerTO poolTO = command.getPool(); + + try { + final String uuid = poolTO.getUuid(); + final SR destinationPool = xenServer610Resource.getStorageRepository(connection, uuid); + final VDI srcVolume = xenServer610Resource.getVDIbyUuid(connection, volumeUUID); + final Map<String, String> other = new HashMap<String, String>(); + other.put("live", "true"); + + // Live migrate the vdi across pool. + final Task task = srcVolume.poolMigrateAsync(connection, destinationPool, other); + final long timeout = xenServer610Resource.getMigrateWait() * 1000L; + xenServer610Resource.waitForTask(connection, task, 1000, timeout); + xenServer610Resource.checkForSuccess(connection, task); + + final VDI dvdi = Types.toVDI(task, connection); + + return new MigrateVolumeAnswer(command, true, null, dvdi.getUuid(connection)); + } catch (final Exception e) { + final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString(); + s_logger.error(msg, e); + return new MigrateVolumeAnswer(command, false, msg, null); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java new file mode 100644 index 0000000..b5c175a --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java @@ -0,0 +1,139 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen610; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.MigrateWithStorageAnswer; +import com.cloud.agent.api.MigrateWithStorageCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.agent.api.to.VolumeTO; +import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; +import com.cloud.hypervisor.xenserver.resource.XsHost; +import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork; +import com.cloud.network.Networks.TrafficType; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.exception.CloudRuntimeException; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Host; +import com.xensource.xenapi.Network; +import com.xensource.xenapi.SR; +import com.xensource.xenapi.Task; +import com.xensource.xenapi.Types; +import com.xensource.xenapi.VDI; +import com.xensource.xenapi.VIF; +import com.xensource.xenapi.VM; + +@ResourceWrapper(handles = MigrateWithStorageCommand.class) +public final class XenServer610MigrateWithStorageCommandWrapper extends CommandWrapper<MigrateWithStorageCommand, Answer, XenServer610Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageCommandWrapper.class); + + @Override + public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) { + final Connection connection = xenServer610Resource.getConnection(); + final VirtualMachineTO vmSpec = command.getVirtualMachine(); + final Map<VolumeTO, StorageFilerTO> volumeToFiler = command.getVolumeToFiler(); + final String vmName = vmSpec.getName(); + Task task = null; + + final XsHost xsHost = xenServer610Resource.getHost(); + final String uuid = xsHost.getUuid(); + try { + xenServer610Resource.prepareISO(connection, vmName); + + // Get the list of networks and recreate VLAN, if required. + for (final NicTO nicTo : vmSpec.getNics()) { + xenServer610Resource.getNetwork(connection, nicTo); + } + + final Map<String, String> other = new HashMap<String, String>(); + other.put("live", "true"); + + final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null); + final Network networkForSm = nativeNetworkForTraffic.getNetwork(); + + // Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map. + final Map<VIF, Network> vifMap = new HashMap<VIF, Network>(); + final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>(); + for (final Map.Entry<VolumeTO, StorageFilerTO> entry : volumeToFiler.entrySet()) { + final VolumeTO volume = entry.getKey(); + final StorageFilerTO sotrageFiler = entry.getValue(); + vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, sotrageFiler.getUuid())); + } + + // Get the vm to migrate. + final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName()); + final VM vmToMigrate = vms.iterator().next(); + + // Check migration with storage is possible. + final Host host = Host.getByUuid(connection, uuid); + final Map<String, String> token = host.migrateReceive(connection, networkForSm, other); + task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other); + try { + // poll every 1 seconds + final long timeout = xenServer610Resource.getMigrateWait() * 1000L; + xenServer610Resource.waitForTask(connection, task, 1000, timeout); + xenServer610Resource.checkForSuccess(connection, task); + } catch (final Types.HandleInvalid e) { + s_logger.error("Error while checking if vm " + vmName + " can be migrated to the destination host " + host, e); + throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated to the " + "destination host " + host, e); + } + + // Migrate now. + task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other); + try { + // poll every 1 seconds. + final long timeout = xenServer610Resource.getMigrateWait() * 1000L; + xenServer610Resource.waitForTask(connection, task, 1000, timeout); + xenServer610Resource.checkForSuccess(connection, task); + } catch (final Types.HandleInvalid e) { + s_logger.error("Error while migrating vm " + vmName + " to the destination host " + host, e); + throw new CloudRuntimeException("Error while migrating vm " + vmName + " to the destination host " + host, e); + } + + // Volume paths would have changed. Return that information. + final List<VolumeObjectTO> volumeToList = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, vmToMigrate, vmSpec.getDisks()); + vmToMigrate.setAffinity(connection, host); + return new MigrateWithStorageAnswer(command, volumeToList); + } catch (final Exception e) { + s_logger.warn("Catch Exception " + e.getClass().getName() + ". Storage motion failed due to " + e.toString(), e); + return new MigrateWithStorageAnswer(command, e); + } finally { + if (task != null) { + try { + task.destroy(connection); + } catch (final Exception e) { + s_logger.debug("Unable to destroy task " + task.toString() + " on host " + uuid + " due to " + e.toString()); + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java new file mode 100644 index 0000000..a28a3b3 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java @@ -0,0 +1,83 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen610; + +import java.util.List; +import java.util.Set; + +import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.MigrateWithStorageCompleteAnswer; +import com.cloud.agent.api.MigrateWithStorageCompleteCommand; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; +import com.cloud.hypervisor.xenserver.resource.XsHost; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.exception.CloudRuntimeException; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Host; +import com.xensource.xenapi.VM; + +@ResourceWrapper(handles = MigrateWithStorageCompleteCommand.class) +public final class XenServer610MigrateWithStorageCompleteCommandWrapper extends CommandWrapper<MigrateWithStorageCompleteCommand, Answer, XenServer610Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageCompleteCommandWrapper.class); + + @Override + public Answer execute(final MigrateWithStorageCompleteCommand command, final XenServer610Resource xenServer610Resource) { + final Connection connection = xenServer610Resource.getConnection(); + final VirtualMachineTO vmSpec = command.getVirtualMachine(); + + final String name = vmSpec.getName(); + try { + final XsHost xsHost = xenServer610Resource.getHost(); + final String uuid = xsHost.getUuid(); + + final Set<VM> vms = VM.getByNameLabel(connection, name); + // Check if VMs can be found by label. + if (vms == null) { + throw new CloudRuntimeException("Couldn't find VMs by label " + name + " on the destination host."); + } + final VM migratedVm = vms.iterator().next(); + + // Check the vm is present on the new host. + if (migratedVm == null) { + throw new CloudRuntimeException("Couldn't find the migrated vm " + name + " on the destination host."); + } + + final Host host = Host.getByUuid(connection, uuid); + migratedVm.setAffinity(connection, host); + + // Volume paths would have changed. Return that information. + final List<VolumeObjectTO> volumeToSet = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, migratedVm, vmSpec.getDisks()); + + return new MigrateWithStorageCompleteAnswer(command, volumeToSet); + } catch (final CloudRuntimeException e) { + s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); + return new MigrateWithStorageCompleteAnswer(command, e); + } catch (final Exception e) { + s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); + return new MigrateWithStorageCompleteAnswer(command, e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java new file mode 100644 index 0000000..68814ef --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java @@ -0,0 +1,93 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen610; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.MigrateWithStorageReceiveAnswer; +import com.cloud.agent.api.MigrateWithStorageReceiveCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.agent.api.to.VolumeTO; +import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; +import com.cloud.hypervisor.xenserver.resource.XsHost; +import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork; +import com.cloud.network.Networks.TrafficType; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.exception.CloudRuntimeException; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Host; +import com.xensource.xenapi.Network; +import com.xensource.xenapi.SR; + +@ResourceWrapper(handles = MigrateWithStorageReceiveCommand.class) +public final class XenServer610MigrateWithStorageReceiveCommandWrapper extends CommandWrapper<MigrateWithStorageReceiveCommand, Answer, XenServer610Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageReceiveCommandWrapper.class); + + @Override + public Answer execute(final MigrateWithStorageReceiveCommand command, final XenServer610Resource xenServer610Resource) { + final Connection connection = xenServer610Resource.getConnection(); + final VirtualMachineTO vmSpec = command.getVirtualMachine(); + final Map<VolumeTO, StorageFilerTO> volumeToFiler = command.getVolumeToFiler(); + + try { + // Get a map of all the SRs to which the vdis will be migrated. + final Map<VolumeTO, Object> volumeToSr = new HashMap<VolumeTO, Object>(); + for (final Map.Entry<VolumeTO, StorageFilerTO> entry : volumeToFiler.entrySet()) { + final StorageFilerTO storageFiler = entry.getValue(); + final SR sr = xenServer610Resource.getStorageRepository(connection, storageFiler.getUuid()); + volumeToSr.put(entry.getKey(), sr); + } + + // Get the list of networks to which the vifs will attach. + final Map<NicTO, Object> nicToNetwork = new HashMap<NicTO, Object>(); + for (final NicTO nicTo : vmSpec.getNics()) { + final Network network = xenServer610Resource.getNetwork(connection, nicTo); + nicToNetwork.put(nicTo, network); + } + + final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null); + final Network network = nativeNetworkForTraffic.getNetwork(); + final XsHost xsHost = xenServer610Resource.getHost(); + final String uuid = xsHost.getUuid(); + + final Map<String, String> other = new HashMap<String, String>(); + other.put("live", "true"); + + final Host host = Host.getByUuid(connection, uuid); + final Map<String, String> token = host.migrateReceive(connection, network, other); + + return new MigrateWithStorageReceiveAnswer(command, volumeToSr, nicToNetwork, token); + } catch (final CloudRuntimeException e) { + s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); + return new MigrateWithStorageReceiveAnswer(command, e); + } catch (final Exception e) { + s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); + return new MigrateWithStorageReceiveAnswer(command, e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java new file mode 100644 index 0000000..6d4afde --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java @@ -0,0 +1,145 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen610; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.MigrateWithStorageSendAnswer; +import com.cloud.agent.api.MigrateWithStorageSendCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.agent.api.to.VolumeTO; +import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.exception.CloudRuntimeException; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Network; +import com.xensource.xenapi.SR; +import com.xensource.xenapi.Task; +import com.xensource.xenapi.Types; +import com.xensource.xenapi.VDI; +import com.xensource.xenapi.VIF; +import com.xensource.xenapi.VM; + +@ResourceWrapper(handles = MigrateWithStorageSendCommand.class) +public final class XenServer610MigrateWithStorageSendCommandWrapper extends CommandWrapper<MigrateWithStorageSendCommand, Answer, XenServer610Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageSendCommandWrapper.class); + + @Override + public Answer execute(final MigrateWithStorageSendCommand command, final XenServer610Resource xenServer610Resource) { + final Connection connection = xenServer610Resource.getConnection(); + + final VirtualMachineTO vmSpec = command.getVirtualMachine(); + final Map<VolumeTO, Object> volumeToSr = command.getVolumeToSr(); + final Map<NicTO, Object> nicToNetwork = command.getNicToNetwork(); + final Map<String, String> token = command.getToken(); + final String vmName = vmSpec.getName(); + + Task task = null; + try { + + final Map<String, String> other = new HashMap<String, String>(); + other.put("live", "true"); + + // Create the vdi map which tells what volumes of the vm need to go + // on which sr on the destination. + final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>(); + for (final Map.Entry<VolumeTO, Object> entry : volumeToSr.entrySet()) { + final Object srObj = entry.getValue(); + if (srObj instanceof SR) { + final SR sr = (SR) srObj; + final VolumeTO volume = entry.getKey(); + final VDI vdi = xenServer610Resource.getVDIbyUuid(connection, volume.getPath()); + vdiMap.put(vdi, sr); + } else { + throw new CloudRuntimeException("The object " + srObj + " passed is not of type SR."); + } + } + + final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName()); + VM vmToMigrate = null; + if (vms != null) { + vmToMigrate = vms.iterator().next(); + } + + // Create the vif map. + final Map<VIF, Network> vifMap = new HashMap<VIF, Network>(); + for (final Map.Entry<NicTO, Object> entry : nicToNetwork.entrySet()) { + final Object networkObj = entry.getValue(); + if (networkObj instanceof Network) { + final Network network = (Network) networkObj; + final NicTO nic = entry.getKey(); + final VIF vif = xenServer610Resource.getVifByMac(connection, vmToMigrate, nic.getMac()); + vifMap.put(vif, network); + } else { + throw new CloudRuntimeException("The object " + networkObj + " passed is not of type Network."); + } + } + + // Check migration with storage is possible. + task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other); + try { + // poll every 1 seconds. + final long timeout = xenServer610Resource.getMigrateWait() * 1000L; + xenServer610Resource.waitForTask(connection, task, 1000, timeout); + xenServer610Resource.checkForSuccess(connection, task); + } catch (final Types.HandleInvalid e) { + s_logger.error("Error while checking if vm " + vmName + " can be migrated.", e); + throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated.", e); + } + + // Migrate now. + task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other); + try { + // poll every 1 seconds. + final long timeout = xenServer610Resource.getMigrateWait() * 1000L; + xenServer610Resource.waitForTask(connection, task, 1000, timeout); + xenServer610Resource.checkForSuccess(connection, task); + } catch (final Types.HandleInvalid e) { + s_logger.error("Error while migrating vm " + vmName, e); + throw new CloudRuntimeException("Error while migrating vm " + vmName, e); + } + + final Set<VolumeTO> volumeToSet = null; + return new MigrateWithStorageSendAnswer(command, volumeToSet); + } catch (final CloudRuntimeException e) { + s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); + return new MigrateWithStorageSendAnswer(command, e); + } catch (final Exception e) { + s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); + return new MigrateWithStorageSendAnswer(command, e); + } finally { + if (task != null) { + try { + task.destroy(connection); + } catch (final Exception e) { + s_logger.debug("Unable to destroy task " + task.toString() + " on host " + xenServer610Resource.getHost().getUuid() + " due to " + e.toString()); + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java new file mode 100644 index 0000000..c054db8 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java @@ -0,0 +1,53 @@ +// +// 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.hypervisor.xenserver.resource.wrapper.xen620sp1; + +import java.util.HashMap; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.GetGPUStatsAnswer; +import com.cloud.agent.api.GetGPUStatsCommand; +import com.cloud.agent.api.VgpuTypesInfo; +import com.cloud.hypervisor.xenserver.resource.XenServer620SP1Resource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.xensource.xenapi.Connection; + +@ResourceWrapper(handles = GetGPUStatsCommand.class) +public final class XenServer620SP1GetGPUStatsCommandWrapper extends CommandWrapper<GetGPUStatsCommand, Answer, XenServer620SP1Resource> { + + private static final Logger s_logger = Logger.getLogger(XenServer620SP1GetGPUStatsCommandWrapper.class); + + @Override + public Answer execute(final GetGPUStatsCommand command, final XenServer620SP1Resource xenServer620SP1Resource) { + final Connection conn = xenServer620SP1Resource.getConnection(); + HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>(); + try { + groupDetails = xenServer620SP1Resource.getGPUGroupDetails(conn); + } catch (final Exception e) { + final String msg = "Unable to get GPU stats" + e.toString(); + s_logger.warn(msg, e); + return new GetGPUStatsAnswer(command, false, msg); + } + return new GetGPUStatsAnswer(command, groupDetails); + } +} \ No newline at end of file
