Search in sources :

Example 21 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareResource method getTargetHyperHost.

private VmwareHypervisorHost getTargetHyperHost(DatacenterMO dcMo, String destIp) throws Exception {
    VmwareManager mgr = dcMo.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    List<ObjectContent> ocs = dcMo.getHostPropertiesOnDatacenterHostFolder(new String[] { "name", "parent" });
    if (ocs != null && ocs.size() > 0) {
        for (ObjectContent oc : ocs) {
            HostMO hostMo = new HostMO(dcMo.getContext(), oc.getObj());
            VmwareHypervisorHostNetworkSummary netSummary = hostMo.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost(hostMo));
            if (destIp.equalsIgnoreCase(netSummary.getHostIp())) {
                return new HostMO(dcMo.getContext(), oc.getObj());
            }
        }
    }
    throw new Exception("Unable to locate dest host by " + destIp);
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareHypervisorHostNetworkSummary(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 22 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareResource method gcAndKillHungWorkerVMs.

private void gcAndKillHungWorkerVMs() {
    try {
        // take the chance to do left-over dummy VM cleanup from previous run
        VmwareContext context = getServiceContext();
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        if (hyperHost.isHyperHostConnected()) {
            mgr.gcLeftOverVMs(context);
            s_logger.info("Scan hung worker VM to recycle");
            int workerKey = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_WORKER);
            int workerTagKey = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG);
            String workerPropName = String.format("value[%d]", workerKey);
            String workerTagPropName = String.format("value[%d]", workerTagKey);
            // GC worker that has been running for too long
            ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "config.template", workerPropName, workerTagPropName });
            if (ocs != null) {
                for (ObjectContent oc : ocs) {
                    List<DynamicProperty> props = oc.getPropSet();
                    if (props != null) {
                        boolean template = false;
                        boolean isWorker = false;
                        String workerTag = null;
                        for (DynamicProperty prop : props) {
                            if (prop.getName().equals("config.template")) {
                                template = (Boolean) prop.getVal();
                            } else if (prop.getName().equals(workerPropName)) {
                                CustomFieldStringValue val = (CustomFieldStringValue) prop.getVal();
                                if (val != null && val.getValue() != null && val.getValue().equalsIgnoreCase("true"))
                                    isWorker = true;
                            } else if (prop.getName().equals(workerTagPropName)) {
                                CustomFieldStringValue val = (CustomFieldStringValue) prop.getVal();
                                workerTag = val.getValue();
                            }
                        }
                        VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
                        if (!template && isWorker) {
                            boolean recycle = false;
                            recycle = mgr.needRecycle(workerTag);
                            if (recycle) {
                                s_logger.info("Recycle pending worker VM: " + vmMo.getName());
                                vmMo.powerOff();
                                vmMo.detachAllDisks();
                                vmMo.destroy();
                            }
                        }
                    }
                }
            }
        } else {
            s_logger.error("Host is no longer connected.");
        }
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
    }
}
Also used : DynamicProperty(com.vmware.vim25.DynamicProperty) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) ObjectContent(com.vmware.vim25.ObjectContent) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue) RemoteException(java.rmi.RemoteException)

Example 23 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareResource method execute.

@Override
public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd));
    }
    try {
        VmwareContext context = getServiceContext();
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        return (PrimaryStorageDownloadAnswer) mgr.getStorageManager().execute(this, cmd);
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "PrimaryStorageDownloadCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        return new PrimaryStorageDownloadAnswer(msg);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) RemoteException(java.rmi.RemoteException)

Example 24 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareStorageProcessor method getControllerFromConfigurationSetting.

private String getControllerFromConfigurationSetting() throws Exception {
    String diskController = null;
    VmwareContext context = null;
    try {
        context = hostService.getServiceContext(null);
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        diskController = mgr.getDataDiskController();
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            hostService.invalidateServiceContext(context);
        }
        String details = "Failed to connect to vCenter due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(details, e);
    }
    return diskController;
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) RemoteException(java.rmi.RemoteException)

Aggregations

VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)24 RemoteException (java.rmi.RemoteException)21 CloudException (com.cloud.exception.CloudException)14 InternalErrorException (com.cloud.exception.InternalErrorException)14 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 IOException (java.io.IOException)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 ConnectException (java.net.ConnectException)14 ConfigurationException (javax.naming.ConfigurationException)14 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)9 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)8 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)7 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)6 Pair (com.cloud.utils.Pair)4 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)3 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)3 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)2 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)2 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)2