Search in sources :

Example 1 with ConnectionException

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);
    }
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) ConnectionException(com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException)

Example 2 with ConnectionException

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);
        }
    });
}
Also used : OperationContext(com.vmware.xenon.common.OperationContext) ConnectionException(com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException) ConnectionException(com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException)

Example 3 with ConnectionException

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);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ConnectionException(com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException)

Aggregations

ConnectionException (com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException)3 BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)1 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)1 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)1 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)1 Operation (com.vmware.xenon.common.Operation)1 OperationContext (com.vmware.xenon.common.OperationContext)1 ServiceErrorResponse (com.vmware.xenon.common.ServiceErrorResponse)1 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)1 URI (java.net.URI)1