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());
}
}
Aggregations