use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException in project photon-model by vmware.
the class VSphereEndpointAdapterService method doValidate.
private void doValidate(AuthCredentialsServiceState credentials, BiConsumer<ServiceErrorResponse, Throwable> callback, URI adapterManagementUri, String id) {
BasicConnection connection = createConnection(adapterManagementUri, credentials);
try {
// login and session creation
connection.connect();
if (id != null && !id.isEmpty()) {
// if a datacenter is configured also validate moref is OK
new GetMoRef(connection).entityProp(VimUtils.convertStringToMoRef(id), VimNames.PROPERTY_NAME);
}
callback.accept(null, null);
} catch (RuntimeFaultFaultMsg | InvalidPropertyFaultMsg | IllegalArgumentException e) {
ServiceErrorResponse r = Utils.toServiceErrorResponse(e);
r.statusCode = STATUS_CODE_BAD_REQUEST;
r.message = String.format("Error looking for datacenter for id '%s'", id);
callback.accept(r, e);
} catch (ConnectionException e) {
String msg = String.format("Cannot establish connection to %s", adapterManagementUri);
logWarning(msg);
callback.accept(null, e);
} finally {
closeQuietly(connection);
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException in project photon-model by vmware.
the class VSphereIOThreadPool method executeCallback.
private void executeCallback(BasicConnection connection, ConnectionCallback callback) {
OperationContext opContext = OperationContext.getOperationContext();
this.executorService.submit(() -> {
OperationContext.restoreOperationContext(opContext);
try {
// login and session creation
connection.connect();
} catch (ConnectionException e) {
callback.doInConnection(null, e);
return;
}
try {
callback.doInConnection(connection, null);
} catch (Exception e) {
logger.log(Level.SEVERE, "Uncaught exception in vSphere IO Pool: " + Utils.toString(e));
} finally {
closeQuietly(connection);
}
});
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException in project photon-model by vmware.
the class VSphereIOThreadPool method submit.
/**
* @see {@link #execute(URI, AuthCredentialsServiceState, ConnectionCallback)}
*
* @param sender
* @param adapterReference
* @param authLink
* where to look for the credentials
* @param callback
*/
public void submit(Service sender, URI adapterReference, String authLink, ConnectionCallback callback) {
URI authUri = createInventoryUri(this.host, authLink);
Operation op = Operation.createGet(authUri).setCompletion((o, e) -> {
if (e != null) {
ConnectionException failure = new ConnectionException("Cannot retrieve credentials from " + authLink, e);
callback.doInConnection(null, failure);
return;
}
AuthCredentialsServiceState auth = o.getBody(AuthCredentialsServiceState.class);
execute(adapterReference, auth, callback);
});
sender.sendRequest(op);
}
Aggregations