Search in sources :

Example 1 with WebManager

use of org.apache.hyracks.http.server.WebManager in project asterixdb by apache.

the class CCApplication method start.

@Override
public void start(IServiceContext serviceCtx, String[] args) throws Exception {
    if (args.length > 0) {
        throw new IllegalArgumentException("Unrecognized argument(s): " + Arrays.toString(args));
    }
    final ClusterControllerService controllerService = (ClusterControllerService) serviceCtx.getControllerService();
    this.ccServiceCtx = (ICCServiceContext) serviceCtx;
    ccServiceCtx.setMessageBroker(new CCMessageBroker(controllerService));
    configureLoggingLevel(ccServiceCtx.getAppConfig().getLoggingLevel(ExternalProperties.Option.LOG_LEVEL));
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Starting Asterix cluster controller");
    }
    ccServiceCtx.setThreadFactory(new AsterixThreadFactory(ccServiceCtx.getThreadFactory(), new LifeCycleComponentManager()));
    ILibraryManager libraryManager = new ExternalLibraryManager();
    ResourceIdManager resourceIdManager = new ResourceIdManager();
    IReplicationStrategy repStrategy = ClusterProperties.INSTANCE.getReplicationStrategy();
    IFaultToleranceStrategy ftStrategy = FaultToleranceStrategyFactory.create(ClusterProperties.INSTANCE.getCluster(), repStrategy, ccServiceCtx);
    ExternalLibraryUtils.setUpExternaLibraries(libraryManager, false);
    componentProvider = new StorageComponentProvider();
    GlobalRecoveryManager.instantiate(ccServiceCtx, getHcc(), componentProvider);
    statementExecutorCtx = new StatementExecutorContext();
    appCtx = new CcApplicationContext(ccServiceCtx, getHcc(), libraryManager, resourceIdManager, () -> MetadataManager.INSTANCE, GlobalRecoveryManager.instance(), ftStrategy, new ActiveLifecycleListener(), componentProvider);
    ClusterStateManager.INSTANCE.setCcAppCtx(appCtx);
    ccExtensionManager = new CCExtensionManager(getExtensions());
    appCtx.setExtensionManager(ccExtensionManager);
    final CCConfig ccConfig = controllerService.getCCConfig();
    if (System.getProperty("java.rmi.server.hostname") == null) {
        System.setProperty("java.rmi.server.hostname", ccConfig.getClusterListenAddress());
    }
    MetadataProperties metadataProperties = appCtx.getMetadataProperties();
    setAsterixStateProxy(AsterixStateProxy.registerRemoteObject(metadataProperties.getMetadataCallbackPort()));
    ccServiceCtx.setDistributedState(proxy);
    MetadataManager.initialize(proxy, metadataProperties);
    ccServiceCtx.addJobLifecycleListener(appCtx.getActiveLifecycleListener());
    // create event loop groups
    webManager = new WebManager();
    configureServers();
    webManager.start();
    ClusterManagerProvider.getClusterManager().registerSubscriber(GlobalRecoveryManager.instance());
    ccServiceCtx.addClusterLifecycleListener(new ClusterLifecycleListener(appCtx));
    jobCapacityController = new JobCapacityController(controllerService.getResourceManager());
}
Also used : IStatementExecutorContext(org.apache.asterix.translator.IStatementExecutorContext) StatementExecutorContext(org.apache.asterix.api.http.ctx.StatementExecutorContext) ILibraryManager(org.apache.asterix.common.library.ILibraryManager) CCMessageBroker(org.apache.asterix.messaging.CCMessageBroker) IStorageComponentProvider(org.apache.asterix.common.context.IStorageComponentProvider) StorageComponentProvider(org.apache.asterix.file.StorageComponentProvider) MetadataProperties(org.apache.asterix.common.config.MetadataProperties) AsterixThreadFactory(org.apache.asterix.common.api.AsterixThreadFactory) IFaultToleranceStrategy(org.apache.asterix.common.replication.IFaultToleranceStrategy) ResourceIdManager(org.apache.asterix.app.cc.ResourceIdManager) CCExtensionManager(org.apache.asterix.app.cc.CCExtensionManager) CcApplicationContext(org.apache.asterix.runtime.utils.CcApplicationContext) ActiveLifecycleListener(org.apache.asterix.active.ActiveLifecycleListener) WebManager(org.apache.hyracks.http.server.WebManager) IJobCapacityController(org.apache.hyracks.api.job.resource.IJobCapacityController) JobCapacityController(org.apache.asterix.runtime.job.resource.JobCapacityController) CCConfig(org.apache.hyracks.control.common.controllers.CCConfig) IReplicationStrategy(org.apache.asterix.common.replication.IReplicationStrategy) LifeCycleComponentManager(org.apache.hyracks.api.lifecycle.LifeCycleComponentManager) ExternalLibraryManager(org.apache.asterix.external.library.ExternalLibraryManager) ClusterControllerService(org.apache.hyracks.control.cc.ClusterControllerService)

Example 2 with WebManager

use of org.apache.hyracks.http.server.WebManager in project asterixdb by apache.

the class NCApplication method start.

@Override
public void start(IServiceContext serviceCtx, String[] args) throws Exception {
    if (args.length > 0) {
        throw new IllegalArgumentException("Unrecognized argument(s): " + Arrays.toString(args));
    }
    this.ncServiceCtx = (INCServiceContext) serviceCtx;
    ncServiceCtx.setThreadFactory(new AsterixThreadFactory(ncServiceCtx.getThreadFactory(), ncServiceCtx.getLifeCycleComponentManager()));
    nodeId = this.ncServiceCtx.getNodeId();
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Starting Asterix node controller: " + nodeId);
    }
    configureLoggingLevel(ncServiceCtx.getAppConfig().getLoggingLevel(ExternalProperties.Option.LOG_LEVEL));
    final NodeControllerService controllerService = (NodeControllerService) ncServiceCtx.getControllerService();
    if (System.getProperty("java.rmi.server.hostname") == null) {
        System.setProperty("java.rmi.server.hostname", (controllerService).getConfiguration().getClusterPublicAddress());
    }
    runtimeContext = new NCAppRuntimeContext(this.ncServiceCtx, getExtensions());
    MetadataProperties metadataProperties = runtimeContext.getMetadataProperties();
    if (!metadataProperties.getNodeNames().contains(this.ncServiceCtx.getNodeId())) {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Substitute node joining : " + this.ncServiceCtx.getNodeId());
        }
        updateOnNodeJoin();
    }
    runtimeContext.initialize(runtimeContext.getNodeProperties().isInitialRun());
    MessagingProperties messagingProperties = runtimeContext.getMessagingProperties();
    IMessageBroker messageBroker = new NCMessageBroker(controllerService, messagingProperties);
    this.ncServiceCtx.setMessageBroker(messageBroker);
    MessagingChannelInterfaceFactory interfaceFactory = new MessagingChannelInterfaceFactory((NCMessageBroker) messageBroker, messagingProperties);
    this.ncServiceCtx.setMessagingChannelInterfaceFactory(interfaceFactory);
    IRecoveryManager recoveryMgr = runtimeContext.getTransactionSubsystem().getRecoveryManager();
    systemState = recoveryMgr.getSystemState();
    if (systemState == SystemState.PERMANENT_DATA_LOSS) {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("System state: " + SystemState.PERMANENT_DATA_LOSS);
            LOGGER.info("Node ID: " + nodeId);
            LOGGER.info("Stores: " + PrintUtil.toString(metadataProperties.getStores()));
            LOGGER.info("Root Metadata Store: " + metadataProperties.getStores().get(nodeId)[0]);
        }
        PersistentLocalResourceRepository localResourceRepository = (PersistentLocalResourceRepository) runtimeContext.getLocalResourceRepository();
        localResourceRepository.initializeNewUniverse(ClusterProperties.INSTANCE.getStorageDirectoryName());
    }
    webManager = new WebManager();
    performLocalCleanUp();
}
Also used : NodeControllerService(org.apache.hyracks.control.nc.NodeControllerService) PersistentLocalResourceRepository(org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository) MessagingChannelInterfaceFactory(org.apache.asterix.messaging.MessagingChannelInterfaceFactory) WebManager(org.apache.hyracks.http.server.WebManager) NCAppRuntimeContext(org.apache.asterix.app.nc.NCAppRuntimeContext) IMessageBroker(org.apache.hyracks.api.messages.IMessageBroker) MetadataProperties(org.apache.asterix.common.config.MetadataProperties) NCMessageBroker(org.apache.asterix.messaging.NCMessageBroker) AsterixThreadFactory(org.apache.asterix.common.api.AsterixThreadFactory) MessagingProperties(org.apache.asterix.common.config.MessagingProperties) IRecoveryManager(org.apache.asterix.common.transactions.IRecoveryManager)

Example 3 with WebManager

use of org.apache.hyracks.http.server.WebManager in project asterixdb by apache.

the class HttpServerTest method testOverloadingServer.

@Test
public void testOverloadingServer() throws Exception {
    WebManager webMgr = new WebManager();
    HttpServer server = new HttpServer(webMgr.getBosses(), webMgr.getWorkers(), PORT, NUM_EXECUTOR_THREADS, SERVER_QUEUE_SIZE);
    SlowServlet servlet = new SlowServlet(server.ctx(), new String[] { PATH });
    server.addServlet(servlet);
    webMgr.add(server);
    webMgr.start();
    try {
        request(NUM_OF_REQUESTS);
        for (Thread thread : THREADS) {
            thread.join();
        }
        Assert.assertEquals(32, SUCCESS_COUNT.get());
        Assert.assertEquals(16, UNAVAILABLE_COUNT.get());
        Assert.assertEquals(0, OTHER_COUNT.get());
    } finally {
        webMgr.stop();
    }
}
Also used : SlowServlet(org.apache.hyracks.http.servlet.SlowServlet) WebManager(org.apache.hyracks.http.server.WebManager) HttpServer(org.apache.hyracks.http.server.HttpServer) Test(org.junit.Test)

Example 4 with WebManager

use of org.apache.hyracks.http.server.WebManager in project asterixdb by apache.

the class HttpServerTest method testMalformedString.

@Test
public void testMalformedString() throws Exception {
    WebManager webMgr = new WebManager();
    HttpServer server = new HttpServer(webMgr.getBosses(), webMgr.getWorkers(), PORT, NUM_EXECUTOR_THREADS, SERVER_QUEUE_SIZE);
    SlowServlet servlet = new SlowServlet(server.ctx(), new String[] { PATH });
    server.addServlet(servlet);
    webMgr.add(server);
    webMgr.start();
    try {
        StringBuilder response = new StringBuilder();
        try (Socket s = new Socket(InetAddress.getLocalHost(), PORT)) {
            PrintWriter pw = new PrintWriter(s.getOutputStream());
            pw.println("GET /?handle=%7B%22handle%22%3A%5B0%2C%200%5D%7 HTTP/1.1");
            pw.println("Host: 127.0.0.1");
            pw.println();
            pw.flush();
            BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                response.append(line).append('\n');
            }
            br.close();
        }
        String output = response.toString();
        Assert.assertTrue(output.contains(HttpResponseStatus.BAD_REQUEST.toString()));
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        webMgr.stop();
    }
}
Also used : SlowServlet(org.apache.hyracks.http.servlet.SlowServlet) WebManager(org.apache.hyracks.http.server.WebManager) InputStreamReader(java.io.InputStreamReader) HttpServer(org.apache.hyracks.http.server.HttpServer) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) URISyntaxException(java.net.URISyntaxException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

WebManager (org.apache.hyracks.http.server.WebManager)4 AsterixThreadFactory (org.apache.asterix.common.api.AsterixThreadFactory)2 MetadataProperties (org.apache.asterix.common.config.MetadataProperties)2 HttpServer (org.apache.hyracks.http.server.HttpServer)2 SlowServlet (org.apache.hyracks.http.servlet.SlowServlet)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Socket (java.net.Socket)1 URISyntaxException (java.net.URISyntaxException)1 ActiveLifecycleListener (org.apache.asterix.active.ActiveLifecycleListener)1 StatementExecutorContext (org.apache.asterix.api.http.ctx.StatementExecutorContext)1 CCExtensionManager (org.apache.asterix.app.cc.CCExtensionManager)1 ResourceIdManager (org.apache.asterix.app.cc.ResourceIdManager)1 NCAppRuntimeContext (org.apache.asterix.app.nc.NCAppRuntimeContext)1 MessagingProperties (org.apache.asterix.common.config.MessagingProperties)1 IStorageComponentProvider (org.apache.asterix.common.context.IStorageComponentProvider)1 ILibraryManager (org.apache.asterix.common.library.ILibraryManager)1 IFaultToleranceStrategy (org.apache.asterix.common.replication.IFaultToleranceStrategy)1