Search in sources :

Example 1 with PluginManager

use of com.cinchapi.concourse.server.plugin.PluginManager in project concourse by cinchapi.

the class ConcourseServer method init.

/**
 * Initialize this instance. This method MUST always be called after
 * constructing the instance.
 *
 * @param port - the port on which to listen for client connections
 * @param bufferStore - the location to store {@link Buffer} files
 * @param dbStore - the location to store {@link Database} files
 * @throws TTransportException
 */
@Internal
private void init(int port, String bufferStore, String dbStore) throws TTransportException {
    Preconditions.checkState(!bufferStore.equalsIgnoreCase(dbStore), "Cannot store buffer and database files in the same directory. " + "Please check concourse.prefs.");
    Preconditions.checkState(!Strings.isNullOrEmpty(Environments.sanitize(DEFAULT_ENVIRONMENT)), "Cannot initialize " + "Concourse Server with a default environment of " + "'%s'. Please use a default environment name that " + "contains only alphanumeric characters.", DEFAULT_ENVIRONMENT);
    FileSystem.mkdirs(bufferStore);
    FileSystem.mkdirs(dbStore);
    FileSystem.lock(bufferStore);
    FileSystem.lock(dbStore);
    TServerSocket socket = new TServerSocket(port);
    TMultiplexedProcessor processor = new TMultiplexedProcessor();
    TProcessor core = new ConcourseService.Processor<>(this);
    processor.registerProcessor("core", core);
    processor.registerProcessor("calculate", new ConcourseCalculateService.Processor<>(this));
    processor.registerProcessor("navigate", new ConcourseNavigateService.Processor<>(this));
    processor.registerDefault(core);
    Args args = new TThreadPoolServer.Args(socket);
    args.processor(processor);
    args.maxWorkerThreads(NUM_WORKER_THREADS);
    args.executorService(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Client Worker" + " %d").build()));
    // CON-530: Set a lower timeout on the ExecutorService's termination to
    // prevent the server from hanging because of active threads that have
    // not yet been given a task but won't allow shutdown to proceed (i.e.
    // clients from a ConnectionPool).
    args.stopTimeoutVal(2);
    this.server = new TThreadPoolServer(args);
    this.bufferStore = bufferStore;
    this.dbStore = dbStore;
    this.engines = Maps.newConcurrentMap();
    this.users = UserService.create(ACCESS_CREDENTIALS_FILE);
    this.inspector = new Inspector() {

        @Override
        public Role getTokenUserRole(AccessToken token) {
            ByteBuffer username = users.tokens.identify(token);
            return users.getRole(username);
        }

        @Override
        public boolean isValidToken(AccessToken token) {
            return users.tokens.isValid(token);
        }

        @Override
        public boolean isValidTransaction(TransactionToken transaction) {
            return transactions.containsKey(transaction);
        }

        @Override
        public boolean tokenUserHasPermission(AccessToken token, Permission permission, String environment) {
            ByteBuffer username = users.tokens.identify(token);
            return users.can(username, permission, Environments.sanitize(environment));
        }
    };
    this.httpServer = GlobalState.HTTP_PORT > 0 ? HttpServer.create(this, GlobalState.HTTP_PORT) : HttpServer.disabled();
    // load the default engine
    getEngine();
    this.pluginManager = new PluginManager(this, GlobalState.CONCOURSE_HOME + File.separator + "plugins");
    // Setup the management server
    TServerSocket mgmtSocket = new TServerSocket(GlobalState.MANAGEMENT_PORT);
    TSimpleServer.Args mgmtArgs = new TSimpleServer.Args(mgmtSocket);
    mgmtArgs.processor(new ConcourseManagementService.Processor<>(this));
    this.mgmtServer = new TSimpleServer(mgmtArgs);
}
Also used : Args(org.apache.thrift.server.TThreadPoolServer.Args) TProcessor(org.apache.thrift.TProcessor) TMultiplexedProcessor(org.apache.thrift.TMultiplexedProcessor) TransactionToken(com.cinchapi.concourse.thrift.TransactionToken) TMultiplexedProcessor(org.apache.thrift.TMultiplexedProcessor) ByteBuffer(java.nio.ByteBuffer) ConcourseManagementService(com.cinchapi.concourse.server.management.ConcourseManagementService) TServerSocket(org.apache.thrift.transport.TServerSocket) Role(com.cinchapi.concourse.security.Role) PluginManager(com.cinchapi.concourse.server.plugin.PluginManager) ConcourseNavigateService(com.cinchapi.concourse.thrift.ConcourseNavigateService) TProcessor(org.apache.thrift.TProcessor) AccessToken(com.cinchapi.concourse.thrift.AccessToken) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) Permission(com.cinchapi.concourse.security.Permission) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ConcourseCalculateService(com.cinchapi.concourse.thrift.ConcourseCalculateService) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TSimpleServer(org.apache.thrift.server.TSimpleServer) Internal(com.cinchapi.concourse.server.aop.Internal)

Aggregations

Permission (com.cinchapi.concourse.security.Permission)1 Role (com.cinchapi.concourse.security.Role)1 Internal (com.cinchapi.concourse.server.aop.Internal)1 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)1 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)1 VerifyWritePermission (com.cinchapi.concourse.server.aop.VerifyWritePermission)1 ConcourseManagementService (com.cinchapi.concourse.server.management.ConcourseManagementService)1 PluginManager (com.cinchapi.concourse.server.plugin.PluginManager)1 AccessToken (com.cinchapi.concourse.thrift.AccessToken)1 ConcourseCalculateService (com.cinchapi.concourse.thrift.ConcourseCalculateService)1 ConcourseNavigateService (com.cinchapi.concourse.thrift.ConcourseNavigateService)1 TransactionToken (com.cinchapi.concourse.thrift.TransactionToken)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ByteBuffer (java.nio.ByteBuffer)1 TMultiplexedProcessor (org.apache.thrift.TMultiplexedProcessor)1 TProcessor (org.apache.thrift.TProcessor)1 TSimpleServer (org.apache.thrift.server.TSimpleServer)1 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)1 Args (org.apache.thrift.server.TThreadPoolServer.Args)1 TServerSocket (org.apache.thrift.transport.TServerSocket)1