Search in sources :

Example 21 with VcenterSystemException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException in project coprhd-controller by CoprHD.

the class VcenterApiClient method getHostCertificate.

private String getHostCertificate(String hostname, String username, String password) throws VcenterSystemException, VcenterObjectConnectionException {
    try {
        Integer hostOperationTimeout = Integer.parseInt(propertyInfo.getProperty("vcenter_host_operation_timeout"));
        Integer sslTimeout = hostOperationTimeout * 1000;
        Integer retryCount = 1;
        Long startTimeMillis = System.currentTimeMillis();
        Long cutoffTimeMillis = startTimeMillis + sslTimeout;
        VcenterHostCertificateGetter.HostConnectionStatus status = VcenterHostCertificateGetter.getInstance().getConnectionStatus(hostname, 443, "/host/ssl_cert", username, password, 300);
        while ((System.currentTimeMillis() < cutoffTimeMillis) && status == VcenterHostCertificateGetter.HostConnectionStatus.UNREACHABLE) {
            _log.info("Host " + hostname + " is unreachable after attempt " + retryCount + " - Retry SSL cert request");
            // Retry is time based and if each retry executes very quickly (ie milliseconds) then we should
            Thread.sleep(10000);
            // throttle and only retry every 10 seconds
            status = VcenterHostCertificateGetter.getInstance().getConnectionStatus(hostname, 443, "/host/ssl_cert", username, password, 300);
            retryCount++;
        }
        String errorSuggestion = null;
        if (status == VcenterHostCertificateGetter.HostConnectionStatus.UNREACHABLE) {
            errorSuggestion = "Ensure host is powered on and responsive. Can be caused by intermittent or temporary connectivity issue thus retry recommended";
        } else if (status == VcenterHostCertificateGetter.HostConnectionStatus.UNKNOWN) {
            errorSuggestion = "Ensure hostname is correct and DNS resolvable";
        } else if (status == VcenterHostCertificateGetter.HostConnectionStatus.UNAUTHORIZED) {
            errorSuggestion = "Ensure host credentials are correct";
        }
        if (errorSuggestion != null) {
            _log.error("Host " + hostname + " not reachable in state " + status + " - " + errorSuggestion);
            throw new VcenterObjectConnectionException("Host " + hostname + " not reachable in state " + status + " - " + errorSuggestion);
        }
        String thumbprint = null;
        try {
            thumbprint = VcenterHostCertificateGetter.getInstance().getSSLThumbprint(hostname, 443, "/host/ssl_cert", username, password, sslTimeout);
        } catch (Exception e) {
            _log.info("Error getting host " + hostname + " SSL certificate " + e);
            thumbprint = VcenterHostCertificateGetter.getInstance().getSSLThumbprint(hostname, 443, "/host/ssl_cert", username, password, sslTimeout);
        }
        if (thumbprint == null || thumbprint.equals("")) {
            _log.error("Could not retrieve host " + hostname + " SSL certificate");
            throw new VcenterSystemException("Could not retrieve host " + hostname + " SSL certificate");
        }
        return thumbprint;
    } catch (VcenterSystemException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("getHostCertificate exception " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) 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

VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)21 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)21 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)21 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)21 HostSystem (com.vmware.vim25.mo.HostSystem)8 ClusterComputeResource (com.vmware.vim25.mo.ClusterComputeResource)7 Task (com.vmware.vim25.mo.Task)7 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)4 Datacenter (com.vmware.vim25.mo.Datacenter)3 InventoryNavigator (com.vmware.vim25.mo.InventoryNavigator)3 ArrayList (java.util.ArrayList)3 HostScsiDisk (com.vmware.vim25.HostScsiDisk)2 HostStorageDeviceInfo (com.vmware.vim25.HostStorageDeviceInfo)2 ScsiLun (com.vmware.vim25.ScsiLun)2 VmfsDatastoreInfo (com.vmware.vim25.VmfsDatastoreInfo)2 Datastore (com.vmware.vim25.mo.Datastore)2 HostStorageSystem (com.vmware.vim25.mo.HostStorageSystem)2 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)2 ClusterConfigSpecEx (com.vmware.vim25.ClusterConfigSpecEx)1 HostConfigFault (com.vmware.vim25.HostConfigFault)1