Search in sources :

Example 1 with HostSystemConnectionState

use of com.vmware.vim25.HostSystemConnectionState in project coprhd-controller by CoprHD.

the class EsxHostDiscoveryAdapter method getConnectionState.

/**
 * Find the connection state of the hostsystem
 *
 * @param source
 *            - {@link HostSystem} vi sdk MO
 * @return
 */
protected HostSystemConnectionState getConnectionState(HostSystem source) {
    HostRuntimeInfo runtime = source.getRuntime();
    HostSystemConnectionState connectionState = (runtime != null) ? runtime.getConnectionState() : null;
    return connectionState;
}
Also used : HostRuntimeInfo(com.vmware.vim25.HostRuntimeInfo) HostSystemConnectionState(com.vmware.vim25.HostSystemConnectionState)

Example 2 with HostSystemConnectionState

use of com.vmware.vim25.HostSystemConnectionState in project coprhd-controller by CoprHD.

the class EsxHostDiscoveryAdapter method discoverHost.

/**
 * Discover Exs host and its IpIterfaces and Initiators.
 *
 * @param hostSystem
 *            - {@link HostSystem} VI SDK managedObject instance
 * @param targetHost
 *            - {@link Host} being discovered.
 * @param changes
 *            {@link HostStateChange} instance containing host changes
 *            during discovery.
 */
private void discoverHost(HostSystem hostSystem, Host targetHost, HostStateChange changes) {
    // Only attempt to update ip interfaces or initiators for connected
    // hosts
    HostSystemConnectionState connectionState = getConnectionState(hostSystem);
    if (connectionState == HostSystemConnectionState.connected) {
        // discover initiators
        List<Initiator> oldInitiators = new ArrayList<Initiator>();
        List<Initiator> addedInitiators = new ArrayList<Initiator>();
        discoverConnectedHostInitiators(hostSystem, targetHost, oldInitiators, addedInitiators);
        if (!oldInitiators.isEmpty() || !addedInitiators.isEmpty()) {
            Collection<URI> oldInitiatorIds = Lists.newArrayList(Collections2.transform(oldInitiators, CommonTransformerFunctions.fctnDataObjectToID()));
            changes.setOldInitiators(oldInitiatorIds);
            Collection<URI> addedInitiatorIds = Lists.newArrayList(Collections2.transform(addedInitiators, CommonTransformerFunctions.fctnDataObjectToID()));
            changes.setNewInitiators(addedInitiatorIds);
        }
    } else {
        if (connectionState == HostSystemConnectionState.disconnected) {
            throw new IllegalStateException("Host is disconnected");
        } else if (connectionState == HostSystemConnectionState.notResponding) {
            throw new IllegalStateException("Host is not responding");
        } else {
            throw new IllegalStateException("Could not determine host connection state");
        }
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) HostSystemConnectionState(com.vmware.vim25.HostSystemConnectionState) URI(java.net.URI)

Example 3 with HostSystemConnectionState

use of com.vmware.vim25.HostSystemConnectionState in project coprhd-controller by CoprHD.

the class ComputeUtils method validateBootVolumes.

/**
 * Validate that the boot volume for this host is still on the server.
 * This prevents us from deleting a re-purposed volume that was originally
 * a boot volume.
 *
 * @return true if the volumes are valid, or the volumes are not able to be validated, so we can go ahead anyway.
 */
public static boolean validateBootVolumes(Cluster cluster, List<HostRestRep> hostsToValidate) {
    // the references are fixed.
    if (cluster == null || cluster.getInactive()) {
        ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.cluster");
        return false;
    }
    // so return that the boot volume is valid due to lack of technical ability to dig any deeper.
    if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noVcenterDataCenter", cluster.forDisplay());
        return true;
    }
    VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
    // until that's fixed.
    if (dataCenter == null || dataCenter.getInactive() || NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
        ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.datacenter", cluster.forDisplay());
        return false;
    }
    Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
    // until that's fixed.
    if (vcenter == null || vcenter.getInactive()) {
        ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.vcenter", cluster.forDisplay());
        return false;
    }
    VMwareSupport vmware = null;
    try {
        vmware = new VMwareSupport();
        vmware.connect(vcenter.getId());
        for (HostRestRep clusterHost : hostsToValidate) {
            Host host = BlockStorageUtils.getHost(clusterHost.getId());
            // Do not validate a host no longer in our database
            if (host == null || host.getInactive()) {
                ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", "N/A", "host not found or inactive");
                return false;
            }
            // in the vCenter cluster, and therefore we can not perform a deep validation.
            if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
                ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.vcenternotinhost", host.getHostName());
                continue;
            }
            // any update to the host using the hostService automatically adds this association.
            if (!NullColumnValueGetter.isNullURI(host.getVcenterDataCenter()) && host.getType() != null && host.getType().equalsIgnoreCase((Host.HostType.No_OS).name())) {
                ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noOShost", host.getHostName());
                continue;
            }
            // flag it as an issue.
            if (clusterHost.getBootVolume() == null || NullColumnValueGetter.isNullURI(clusterHost.getBootVolume().getId())) {
                ExecutionUtils.currentContext().logWarn("computeutils.removebootvolumes.failure.host", host.getHostName(), "no boot volume associated with host");
                continue;
            }
            BlockObjectRestRep bootVolume = execute(new GetBlockResource(clusterHost.getBootVolume().getId()));
            // Do not validate an old/non-existent boot volume representation
            if (bootVolume == null || bootVolume.getInactive()) {
                ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", host.getHostName(), "boot volume not found or inactive");
                return false;
            }
            HostSystem hostSystem = null;
            try {
                hostSystem = vmware.getHostSystem(dataCenter.getLabel(), clusterHost.getName(), false);
                // we can't perform the validation.
                if (hostSystem == null) {
                    ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
                    continue;
                }
                HostSystemConnectionState connectionState = VMwareUtils.getConnectionState(hostSystem);
                if (connectionState == null || connectionState == HostSystemConnectionState.notResponding || connectionState == HostSystemConnectionState.disconnected) {
                    String exMsg = "Validation of boot volume usage on host %s failed. " + "Validation failed because host is in a disconnected state or not responding state, and therefore cannot be validated. " + "Cannot decommission in current state.  Recommended to either re-connect the host or remove the host from vCenter, " + "run vCenter discovery and address actionable events before attempting decommission of hosts in this cluster.";
                    // will print a boot volume re-purposed error message which is kind of misleading or incorrect reason for the failure.
                    throw new IllegalStateException(String.format(exMsg, host.getHostName()));
                }
            } catch (ExecutionException e) {
                if (e.getCause() instanceof IllegalStateException) {
                    ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
                    continue;
                }
                // If it's anything other than the IllegalStateException, re-throw the base exception
                throw e;
            }
            if (vmware.findScsiDisk(hostSystem, null, bootVolume, false, false) == null) {
                // fail, host can't see its boot volume
                ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.bootvolume", bootVolume.getDeviceLabel(), bootVolume.getWwn());
                return false;
            } else {
                ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validated", host.getHostName(), bootVolume.getDeviceLabel());
            }
        }
    } finally {
        if (vmware != null) {
            vmware.disconnect();
        }
    }
    return true;
}
Also used : GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) Vcenter(com.emc.storageos.db.client.model.Vcenter) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) VMwareSupport(com.emc.sa.service.vmware.VMwareSupport) GetHost(com.emc.sa.service.vipr.tasks.GetHost) DiscoverHost(com.emc.sa.service.vipr.compute.tasks.DiscoverHost) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) Host(com.emc.storageos.db.client.model.Host) GetBlockResource(com.emc.sa.service.vipr.block.tasks.GetBlockResource) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) HostRestRep(com.emc.storageos.model.host.HostRestRep) HostSystem(com.vmware.vim25.mo.HostSystem) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostSystemConnectionState(com.vmware.vim25.HostSystemConnectionState) ExecutionException(com.emc.sa.engine.ExecutionException)

Example 4 with HostSystemConnectionState

use of com.vmware.vim25.HostSystemConnectionState in project coprhd-controller by CoprHD.

the class FindESXHost method executeTask.

@Override
public HostSystem executeTask() throws Exception {
    debug("Executing: %s", getDetail());
    HostSystem host = vcenter.findHostSystem(datacenterName, esxHostName);
    if (host == null) {
        if (verifyHostExists) {
            throw stateException("FindESXHost.illegalState.noHost", datacenterName, esxHostName);
        } else {
            return null;
        }
    }
    if (verifyHostExists) {
        // Check the connection state of this host
        HostSystemConnectionState connectionState = VMwareUtils.getConnectionState(host);
        logInfo("find.esx.host.state", esxHostName, connectionState);
        if (connectionState == null) {
            throw stateException("FindESXHost.illegalState.noState", esxHostName, datacenterName);
        } else if (connectionState == HostSystemConnectionState.notResponding) {
            throw stateException("FindESXHost.illegalState.notResponding", esxHostName);
        } else if (connectionState == HostSystemConnectionState.disconnected) {
            throw stateException("FindESXHost.illegalState.notConnected", esxHostName);
        }
    }
    return host;
}
Also used : HostSystem(com.vmware.vim25.mo.HostSystem) HostSystemConnectionState(com.vmware.vim25.HostSystemConnectionState)

Example 5 with HostSystemConnectionState

use of com.vmware.vim25.HostSystemConnectionState in project coprhd-controller by CoprHD.

the class VcenterApiClient method reconnectHost.

private void reconnectHost(HostSystem hostSystem) throws VcenterSystemException {
    try {
        String hostname = hostSystem.getName();
        HostSystemConnectionState hostSystemConnectionState = hostSystem.getRuntime().getConnectionState();
        if (hostSystemConnectionState == HostSystemConnectionState.disconnected || hostSystemConnectionState == HostSystemConnectionState.notResponding) {
            Integer operationTimeout = Integer.parseInt(propertyInfo.getProperty("vcenter_operation_timeout"));
            _log.info("Host " + hostname + " is in a " + hostSystemConnectionState + "state - Attempt to reconnect");
            // might need to provide conn info, no arg should use
            Task reconnectHostTask = hostSystem.reconnectHost_Task(null);
            // 'defaults' guessing means what it was registered originally
            // with
            // wait
            VcenterTaskMonitor.TaskStatus taskStatus = (new VcenterTaskMonitor(operationTimeout)).monitor(reconnectHostTask);
            // configured
            // timeout
            _log.info("After running reconnect task for host " + hostname + " the task result is " + taskStatus + " and host is in connection state " + hostSystem.getRuntime().getConnectionState());
        }
    } catch (Exception e) {
        _log.error("reconnectHost exception " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : Task(com.vmware.vim25.mo.Task) HostSystemConnectionState(com.vmware.vim25.HostSystemConnectionState) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)

Aggregations

HostSystemConnectionState (com.vmware.vim25.HostSystemConnectionState)8 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)3 HostSystem (com.vmware.vim25.mo.HostSystem)2 ExecutionException (com.emc.sa.engine.ExecutionException)1 GetBlockResource (com.emc.sa.service.vipr.block.tasks.GetBlockResource)1 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)1 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)1 GetHost (com.emc.sa.service.vipr.tasks.GetHost)1 VMwareSupport (com.emc.sa.service.vmware.VMwareSupport)1 GetVcenter (com.emc.sa.service.vmware.tasks.GetVcenter)1 GetVcenterDataCenter (com.emc.sa.service.vmware.tasks.GetVcenterDataCenter)1 Host (com.emc.storageos.db.client.model.Host)1 Initiator (com.emc.storageos.db.client.model.Initiator)1 Vcenter (com.emc.storageos.db.client.model.Vcenter)1 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)1 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)1 HostRestRep (com.emc.storageos.model.host.HostRestRep)1 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)1 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)1 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)1