Search in sources :

Example 1 with SnowowlServiceException

use of com.b2international.snowowl.core.api.SnowowlServiceException in project snow-owl by b2ihealthcare.

the class RepositoryPlugin method preRun.

@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) {
    if (env.isServer()) {
        LOG.debug("Initializing repository plugin.");
        final MeterRegistry registry = env.service(MeterRegistry.class);
        final IEventBus eventBus = env.service(IEventBus.class);
        // Add event bus based request metrics
        registerRequestMetrics(registry, eventBus);
        final IManagedContainer container = env.container();
        RpcUtil.getInitialServerSession(container).registerServiceLookup(env::service);
        Net4jUtil.prepareContainer(container);
        JVMUtil.prepareContainer(container);
        TCPUtil.prepareContainer(container);
        LifecycleUtil.activate(container);
        final HostAndPort hostAndPort = env.service(RepositoryConfiguration.class).getHostAndPort();
        // open port in server environments
        if (hostAndPort.getPort() > 0) {
            // Starts the TCP transport
            TCPUtil.getAcceptor(container, hostAndPort.toString());
            LOG.info("Listening on {} for connections", hostAndPort);
        }
        // Starts the JVM transport
        JVMUtil.getAcceptor(container, TransportClient.NET_4_J_CONNECTOR_NAME);
        final RepositoryManager repositoryManager = new DefaultRepositoryManager();
        env.services().registerService(RepositoryManager.class, repositoryManager);
        env.services().registerService(RepositoryContextProvider.class, repositoryManager);
        int numberOfWorkers = env.service(RepositoryConfiguration.class).getMaxThreads();
        initializeRequestSupport(env, numberOfWorkers);
        LOG.debug("Initialized repository plugin.");
    } else {
        LOG.debug("Snow Owl application is running in remote mode.");
    }
    if (env.isServer()) {
        try {
            connectSystemUser(env.container());
        } catch (SnowowlServiceException e) {
            throw new SnowowlRuntimeException(e);
        }
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) IManagedContainer(org.eclipse.net4j.util.container.IManagedContainer) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) SnowowlServiceException(com.b2international.snowowl.core.api.SnowowlServiceException) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) IEventBus(com.b2international.snowowl.eventbus.IEventBus) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 2 with SnowowlServiceException

use of com.b2international.snowowl.core.api.SnowowlServiceException in project snow-owl by b2ihealthcare.

the class TransportClient method initConnection.

private synchronized void initConnection() throws SnowowlServiceException {
    if (connector != null) {
        return;
    }
    try {
        if (Strings.isNullOrEmpty(address)) {
            connector = JVMUtil.getConnector(IPluginContainer.INSTANCE, NET_4_J_CONNECTOR_NAME);
        } else {
            TCPUtil.prepareContainer(IPluginContainer.INSTANCE);
            Net4jUtil.prepareContainer(IPluginContainer.INSTANCE);
            connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, getAddress());
            connector.waitForConnection(transportConfiguration.getConnectionTimeout());
            final HeartBeatProtocol watchdog = new HeartBeatProtocol(connector);
            watchdog.start(transportConfiguration.getWatchdogRate(), transportConfiguration.getWatchdogTimeout());
        }
        openCustomProtocols();
    } catch (final ConnectorException e) {
        LOG.error("Could not connect to server, please check your settings.", e);
        throw new SnowowlServiceException("Could not connect to server, please check your settings.", e);
    } catch (final IllegalArgumentException e) {
        LOG.error("Invalid repository URL: " + e.getMessage(), e);
        throw new SnowowlServiceException("Invalid repository URL: " + e.getMessage(), e);
    } catch (final LifecycleException e) {
        LOG.error("Could not connect to server: " + e.getMessage(), e);
        throw new SnowowlServiceException("Could not connect to server: " + e.getMessage(), e);
    } catch (final Throwable e) {
        LOG.error("Could not connect to server.", e);
        throw new SnowowlServiceException("Could not connect to server.", e);
    }
}
Also used : LifecycleException(org.eclipse.net4j.util.lifecycle.LifecycleException) ConnectorException(org.eclipse.net4j.connector.ConnectorException) SnowowlServiceException(com.b2international.snowowl.core.api.SnowowlServiceException) HeartBeatProtocol(org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol)

Example 3 with SnowowlServiceException

use of com.b2international.snowowl.core.api.SnowowlServiceException in project snow-owl by b2ihealthcare.

the class TransportClient method connect.

public User connect(final String username, final String password) throws SnowowlServiceException {
    try {
        this.user = username;
        this.password = password;
        // initialize connectors first
        initConnection();
        // try to log in with the specified username and password using the non-authorized bus instance
        final Token token = UserRequests.prepareLogin().setUsername(username).setPassword(password).buildAsync().execute(bus).getSync();
        // if successfully logged in replace the event bus with an authorized one
        env.services().registerService(IEventBus.class, new AuthorizedEventBus(bus, ImmutableMap.of("Authorization", token.getToken())));
        env.services().registerService(TransportClient.class, this);
        return env.service(AuthorizationHeaderVerifier.class).toUser(token.getToken());
    } catch (UnauthorizedException e) {
        throw new SnowowlServiceException(e.getMessage());
    } catch (final Throwable t) {
        final Throwable rootCause = Throwables.getRootCause(t);
        final String message = Strings.nullToEmpty(StringUtils.getLine(rootCause.getMessage(), "\n", 0)).replace("\r", "");
        LOG.error("Exception caught while connecting to the server.", t);
        // FIXME: "Sentiment analysis" for exception messages
        if (message.startsWith(COULD_NOT_ACTIVATE_PREFIX)) {
            throw new SnowowlServiceException("The server could not be reached. Please verify the connection URL.");
        } else if (message.startsWith(ALREADY_LOGGED_IN_PREFIX)) {
            throw new SnowowlServiceException("Another client with the same user is already connected to the server.");
        } else if (message.startsWith(INCORRECT_USER_NAME_OR_PASSWORD)) {
            throw new SnowowlServiceException(message);
        } else if (message.startsWith(LOGIN_DISABLED)) {
            throw new SnowowlServiceException(message);
        } else if (message.startsWith(LDAP_CONNECTION_REFUSED)) {
            throw new SnowowlServiceException("The LDAP server could not be reached for authentication. Please contact the administrator.");
        } else {
            throw new SnowowlServiceException("An unexpected error occurred while connecting to the server. Please contact the administrator.");
        }
    }
}
Also used : AuthorizationHeaderVerifier(com.b2international.snowowl.core.identity.AuthorizationHeaderVerifier) UnauthorizedException(com.b2international.commons.exceptions.UnauthorizedException) AuthorizedEventBus(com.b2international.snowowl.core.authorization.AuthorizedEventBus) Token(com.b2international.snowowl.core.identity.Token) SnowowlServiceException(com.b2international.snowowl.core.api.SnowowlServiceException)

Aggregations

SnowowlServiceException (com.b2international.snowowl.core.api.SnowowlServiceException)3 UnauthorizedException (com.b2international.commons.exceptions.UnauthorizedException)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 AuthorizedEventBus (com.b2international.snowowl.core.authorization.AuthorizedEventBus)1 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)1 AuthorizationHeaderVerifier (com.b2international.snowowl.core.identity.AuthorizationHeaderVerifier)1 Token (com.b2international.snowowl.core.identity.Token)1 IEventBus (com.b2international.snowowl.eventbus.IEventBus)1 HostAndPort (com.google.common.net.HostAndPort)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 ConnectorException (org.eclipse.net4j.connector.ConnectorException)1 HeartBeatProtocol (org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol)1 IManagedContainer (org.eclipse.net4j.util.container.IManagedContainer)1 LifecycleException (org.eclipse.net4j.util.lifecycle.LifecycleException)1