Search in sources :

Example 1 with CcApplicationContext

use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.

the class QueryTranslatorTest method test.

@Test
public void test() throws Exception {
    List<Statement> statements = new ArrayList<>();
    SessionOutput mockSessionOutput = mock(SessionOutput.class);
    RunStatement mockRunStatement = mock(RunStatement.class);
    // Mocks AppContextInfo.
    CcApplicationContext mockAsterixAppContextInfo = mock(CcApplicationContext.class);
    ExternalProperties mockAsterixExternalProperties = mock(ExternalProperties.class);
    when(mockAsterixAppContextInfo.getExternalProperties()).thenReturn(mockAsterixExternalProperties);
    when(mockAsterixExternalProperties.getAPIServerPort()).thenReturn(19002);
    // Mocks AsterixClusterProperties.
    Cluster mockCluster = mock(Cluster.class);
    MasterNode mockMasterNode = mock(MasterNode.class);
    ClusterProperties mockClusterProperties = mock(ClusterProperties.class);
    setFinalStaticField(ClusterProperties.class.getDeclaredField("INSTANCE"), mockClusterProperties);
    when(mockClusterProperties.getCluster()).thenReturn(mockCluster);
    when(mockCluster.getMasterNode()).thenReturn(mockMasterNode);
    when(mockMasterNode.getClientIp()).thenReturn("127.0.0.1");
    IStatementExecutor aqlTranslator = new DefaultStatementExecutorFactory().create(mockAsterixAppContextInfo, statements, mockSessionOutput, new AqlCompilationProvider(), new StorageComponentProvider());
    List<String> parameters = new ArrayList<>();
    parameters.add("examples/pregelix-example-jar-with-dependencies.jar");
    parameters.add("org.apache.pregelix.example.PageRankVertex");
    parameters.add("-ip 10.0.2.15 -port 3199");
    when(mockRunStatement.getParameters()).thenReturn(parameters);
    // Test a customer command without "-cust-prop".
    List<String> cmds = (List<String>) PA.invokeMethod(aqlTranslator, "constructPregelixCommand(org.apache.asterix.lang.common.statement.RunStatement," + "String,String,String,String)", mockRunStatement, "fromDataverse", "fromDataset", "toDataverse", "toDataset");
    List<String> expectedCmds = Arrays.asList(new String[] { "bin/pregelix", "examples/pregelix-example-jar-with-dependencies.jar", "org.apache.pregelix.example.PageRankVertex", "-ip", "10.0.2.15", "-port", "3199", "-cust-prop", "pregelix.asterixdb.url=http://127.0.0.1:19002,pregelix.asterixdb.source=true,pregelix.asterixdb.sink=true,pregelix.asterixdb.input.dataverse=fromDataverse,pregelix.asterixdb.input.dataset=fromDataset,pregelix.asterixdb.output.dataverse=toDataverse,pregelix.asterixdb.output.dataset=toDataset,pregelix.asterixdb.output.cleanup=false,pregelix.asterixdb.input.converterclass=org.apache.pregelix.example.converter.VLongIdInputVertexConverter,pregelix.asterixdb.output.converterclass=org.apache.pregelix.example.converter.VLongIdOutputVertexConverter" });
    Assert.assertEquals(cmds, expectedCmds);
    parameters.remove(parameters.size() - 1);
    parameters.add("-ip 10.0.2.15 -port 3199 -cust-prop " + "pregelix.asterixdb.input.converterclass=org.apache.pregelix.example.converter.TestInputVertexConverter," + "pregelix.asterixdb.output.converterclass=org.apache.pregelix.example.converter.TestOutputVertexConverter");
    // Test a customer command with "-cust-prop".
    cmds = (List<String>) PA.invokeMethod(aqlTranslator, "constructPregelixCommand(org.apache.asterix.lang.common.statement.RunStatement," + "String,String,String,String)", mockRunStatement, "fromDataverse", "fromDataset", "toDataverse", "toDataset");
    expectedCmds = Arrays.asList(new String[] { "bin/pregelix", "examples/pregelix-example-jar-with-dependencies.jar", "org.apache.pregelix.example.PageRankVertex", "-ip", "10.0.2.15", "-port", "3199", "-cust-prop", "pregelix.asterixdb.url=http://127.0.0.1:19002,pregelix.asterixdb.source=true,pregelix.asterixdb.sink=true,pregelix.asterixdb.input.dataverse=fromDataverse,pregelix.asterixdb.input.dataset=fromDataset,pregelix.asterixdb.output.dataverse=toDataverse,pregelix.asterixdb.output.dataset=toDataset,pregelix.asterixdb.output.cleanup=false,pregelix.asterixdb.input.converterclass=org.apache.pregelix.example.converter.TestInputVertexConverter,pregelix.asterixdb.output.converterclass=org.apache.pregelix.example.converter.TestOutputVertexConverter" });
    Assert.assertEquals(cmds, expectedCmds);
}
Also used : RunStatement(org.apache.asterix.lang.common.statement.RunStatement) MasterNode(org.apache.asterix.event.schema.cluster.MasterNode) AqlCompilationProvider(org.apache.asterix.compiler.provider.AqlCompilationProvider) RunStatement(org.apache.asterix.lang.common.statement.RunStatement) Statement(org.apache.asterix.lang.common.base.Statement) ArrayList(java.util.ArrayList) ExternalProperties(org.apache.asterix.common.config.ExternalProperties) Cluster(org.apache.asterix.event.schema.cluster.Cluster) StorageComponentProvider(org.apache.asterix.file.StorageComponentProvider) IStatementExecutor(org.apache.asterix.translator.IStatementExecutor) CcApplicationContext(org.apache.asterix.runtime.utils.CcApplicationContext) SessionOutput(org.apache.asterix.translator.SessionOutput) DefaultStatementExecutorFactory(org.apache.asterix.app.translator.DefaultStatementExecutorFactory) ClusterProperties(org.apache.asterix.common.config.ClusterProperties) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with CcApplicationContext

use of org.apache.asterix.runtime.utils.CcApplicationContext 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 3 with CcApplicationContext

use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.

the class ClusterApiServlet method getClusterStateJSON.

protected ObjectNode getClusterStateJSON(IServletRequest request, String pathToNode) {
    ObjectNode json = ClusterStateManager.INSTANCE.getClusterStateDescription();
    CcApplicationContext appConfig = (CcApplicationContext) ctx.get(ASTERIX_APP_CONTEXT_INFO_ATTR);
    json.putPOJO("config", ConfigUtils.getSectionOptionsForJSON(appConfig.getServiceContext().getAppConfig(), Section.COMMON, getConfigSelector()));
    ArrayNode ncs = (ArrayNode) json.get("ncs");
    final StringBuilder requestURL = new StringBuilder("http://");
    requestURL.append(request.getHeader(HttpHeaderNames.HOST));
    requestURL.append(request.getHttpRequest().uri());
    if (requestURL.charAt(requestURL.length() - 1) != '/') {
        requestURL.append('/');
    }
    requestURL.append(pathToNode);
    String clusterURL = canonicalize(requestURL);
    String adminURL = canonicalize(clusterURL + "../");
    String nodeURL = clusterURL + "node/";
    for (int i = 0; i < ncs.size(); i++) {
        ObjectNode nc = (ObjectNode) ncs.get(i);
        nc.put(CONFIG_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/config");
        nc.put(STATS_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/stats");
        nc.put(THREAD_DUMP_URI_KEY, nodeURL + nc.get(NODE_ID_KEY).asText() + "/threaddump");
    }
    ObjectNode cc;
    if (json.has("cc")) {
        cc = (ObjectNode) json.get("cc");
    } else {
        cc = om.createObjectNode();
        json.set("cc", cc);
    }
    cc.put(CONFIG_URI_KEY, clusterURL + "cc/config");
    cc.put(STATS_URI_KEY, clusterURL + "cc/stats");
    cc.put(THREAD_DUMP_URI_KEY, clusterURL + "cc/threaddump");
    json.put(SHUTDOWN_URI_KEY, adminURL + "shutdown");
    json.put(FULL_SHUTDOWN_URI_KEY, adminURL + "shutdown?all=true");
    json.put(VERSION_URI_KEY, adminURL + "version");
    json.put(DIAGNOSTICS_URI_KEY, adminURL + "diagnostics");
    return json;
}
Also used : CcApplicationContext(org.apache.asterix.runtime.utils.CcApplicationContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with CcApplicationContext

use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.

the class VersionApiServletTest method testGet.

@Test
public void testGet() throws Exception {
    // Configures a test version api servlet.
    VersionApiServlet servlet = new VersionApiServlet(new ConcurrentHashMap<>(), new String[] { "/" });
    Map<String, String> propMap = new HashMap<>();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintWriter outputWriter = new PrintWriter(outputStream);
    // Creates mocks.
    CcApplicationContext mockCtx = mock(CcApplicationContext.class);
    IServletRequest mockRequest = mock(IServletRequest.class);
    IHyracksClientConnection mockHcc = mock(IHyracksClientConnection.class);
    IServletResponse mockResponse = mock(IServletResponse.class);
    BuildProperties mockProperties = mock(BuildProperties.class);
    FullHttpRequest mockHttpRequest = mock(FullHttpRequest.class);
    // Put stuff in let map
    servlet.ctx().put(HYRACKS_CONNECTION_ATTR, mockHcc);
    servlet.ctx().put(ASTERIX_APP_CONTEXT_INFO_ATTR, mockCtx);
    // Sets up mock returns.
    when(mockResponse.writer()).thenReturn(outputWriter);
    when(mockRequest.getHttpRequest()).thenReturn(mockHttpRequest);
    when(mockHttpRequest.method()).thenReturn(HttpMethod.GET);
    when(mockCtx.getBuildProperties()).thenReturn(mockProperties);
    when(mockProperties.getAllProps()).thenReturn(propMap);
    propMap.put("git.build.user.email", "foo@bar.baz");
    propMap.put("git.build.host", "fulliautomatix");
    propMap.put("git.dirty", "true");
    propMap.put("git.remote.origin.url", "git@github.com:apache/incubator-asterixdb.git");
    propMap.put("git.closest.tag.name", "asterix-0.8.7-incubating");
    propMap.put("git.commit.id.describe-short", "asterix-0.8.7-incubating-19-dirty");
    propMap.put("git.commit.user.email", "foo@bar.baz");
    propMap.put("git.commit.time", "21.10.2015 @ 23:36:41 PDT");
    propMap.put("git.commit.message.full", "ASTERIXDB-1045: fix log file reading during recovery\n\nChange-Id: Ic83ee1dd2d7ba88180c25f4ec6c7aa8d0a5a7162\nReviewed-on: https://asterix-gerrit.ics.uci.edu/465\nTested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>");
    propMap.put("git.build.version", "0.8.8-SNAPSHOT");
    propMap.put("git.commit.message.short", "ASTERIXDB-1045: fix log file reading during recovery");
    propMap.put("git.commit.id.abbrev", "e1dad19");
    propMap.put("git.branch", "foo/bar");
    propMap.put("git.build.user.name", "Asterix");
    propMap.put("git.closest.tag.commit.count", "19");
    propMap.put("git.commit.id.describe", "asterix-0.8.7-incubating-19-ge1dad19-dirty");
    propMap.put("git.commit.id", "e1dad1984640517366a7e73e323c9de27b0676f7");
    propMap.put("git.tags", "");
    propMap.put("git.build.time", "22.10.2015 @ 17:11:07 PDT");
    propMap.put("git.commit.user.name", "Obelix");
    // Calls VersionAPIServlet.formResponseObject.
    servlet.handle(mockRequest, mockResponse);
    // Constructs the actual response.
    ObjectMapper om = new ObjectMapper();
    ObjectNode actualResponse = (ObjectNode) om.readTree(outputStream.toByteArray());
    ObjectNode expectedResponse = om.createObjectNode();
    for (Map.Entry<String, String> e : propMap.entrySet()) {
        expectedResponse.put(e.getKey(), e.getValue());
    }
    // Checks the response contains all the expected keys.
    Assert.assertEquals(actualResponse.toString(), expectedResponse.toString());
}
Also used : IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VersionApiServlet(org.apache.asterix.api.http.server.VersionApiServlet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IServletRequest(org.apache.hyracks.http.api.IServletRequest) BuildProperties(org.apache.asterix.common.config.BuildProperties) CcApplicationContext(org.apache.asterix.runtime.utils.CcApplicationContext) IServletResponse(org.apache.hyracks.http.api.IServletResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) SqlppExecutionTest(org.apache.asterix.test.runtime.SqlppExecutionTest)

Example 5 with CcApplicationContext

use of org.apache.asterix.runtime.utils.CcApplicationContext in project asterixdb by apache.

the class TestNodeController method getPrimaryResourceFactory.

public IResourceFactory getPrimaryResourceFactory(IHyracksTaskContext ctx, PrimaryIndexInfo primaryIndexInfo, IStorageComponentProvider storageComponentProvider, Dataset dataset) throws AlgebricksException {
    Dataverse dataverse = new Dataverse(dataset.getDataverseName(), NonTaggedDataFormat.class.getName(), MetadataUtil.PENDING_NO_OP);
    Index index = primaryIndexInfo.getIndex();
    CcApplicationContext appCtx = (CcApplicationContext) ExecutionTestUtil.integrationUtil.cc.getApplicationContext();
    MetadataProvider mdProvider = new MetadataProvider(appCtx, dataverse, storageComponentProvider);
    try {
        return dataset.getResourceFactory(mdProvider, index, primaryIndexInfo.recordType, primaryIndexInfo.metaType, primaryIndexInfo.mergePolicyFactory, primaryIndexInfo.mergePolicyProperties);
    } finally {
        mdProvider.getLocks().unlock();
    }
}
Also used : CcApplicationContext(org.apache.asterix.runtime.utils.CcApplicationContext) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) Index(org.apache.asterix.metadata.entities.Index) NonTaggedDataFormat(org.apache.asterix.runtime.formats.NonTaggedDataFormat) Dataverse(org.apache.asterix.metadata.entities.Dataverse)

Aggregations

CcApplicationContext (org.apache.asterix.runtime.utils.CcApplicationContext)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 StorageComponentProvider (org.apache.asterix.file.StorageComponentProvider)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ActiveLifecycleListener (org.apache.asterix.active.ActiveLifecycleListener)1 StatementExecutorContext (org.apache.asterix.api.http.ctx.StatementExecutorContext)1 VersionApiServlet (org.apache.asterix.api.http.server.VersionApiServlet)1 CCExtensionManager (org.apache.asterix.app.cc.CCExtensionManager)1 ResourceIdManager (org.apache.asterix.app.cc.ResourceIdManager)1 DefaultStatementExecutorFactory (org.apache.asterix.app.translator.DefaultStatementExecutorFactory)1