Search in sources :

Example 1 with ExternalProperties

use of org.apache.asterix.common.config.ExternalProperties 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 ExternalProperties

use of org.apache.asterix.common.config.ExternalProperties in project asterixdb by apache.

the class QueryWebInterfaceServlet method post.

@Override
protected void post(IServletRequest request, IServletResponse response) throws IOException {
    HttpUtil.setContentType(response, HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
    ExternalProperties externalProperties = appCtx.getExternalProperties();
    response.setStatus(HttpResponseStatus.OK);
    ObjectMapper om = new ObjectMapper();
    ObjectNode obj = om.createObjectNode();
    try {
        PrintWriter out = response.writer();
        obj.put("api_port", String.valueOf(externalProperties.getAPIServerPort()));
        out.println(obj.toString());
        return;
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failure writing response", e);
    }
    try {
        response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failure setting response status", e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ExternalProperties(org.apache.asterix.common.config.ExternalProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 3 with ExternalProperties

use of org.apache.asterix.common.config.ExternalProperties in project asterixdb by apache.

the class QueryTranslator method constructPregelixCommand.

// Constructs a Pregelix command line.
protected List<String> constructPregelixCommand(RunStatement pregelixStmt, String fromDataverseName, String fromDatasetName, String toDataverseName, String toDatasetName) {
    // Constructs AsterixDB parameters, e.g., URL, source dataset and sink dataset.
    ExternalProperties externalProperties = appCtx.getExternalProperties();
    String clientIP = ClusterProperties.INSTANCE.getCluster().getMasterNode().getClientIp();
    StringBuilder asterixdbParameterBuilder = new StringBuilder();
    asterixdbParameterBuilder.append("pregelix.asterixdb.url=" + "http://" + clientIP + ":" + externalProperties.getAPIServerPort() + ",");
    asterixdbParameterBuilder.append("pregelix.asterixdb.source=true,");
    asterixdbParameterBuilder.append("pregelix.asterixdb.sink=true,");
    asterixdbParameterBuilder.append("pregelix.asterixdb.input.dataverse=" + fromDataverseName + ",");
    asterixdbParameterBuilder.append("pregelix.asterixdb.input.dataset=" + fromDatasetName + ",");
    asterixdbParameterBuilder.append("pregelix.asterixdb.output.dataverse=" + toDataverseName + ",");
    asterixdbParameterBuilder.append("pregelix.asterixdb.output.dataset=" + toDatasetName + ",");
    asterixdbParameterBuilder.append("pregelix.asterixdb.output.cleanup=false,");
    // construct command
    List<String> cmds = new ArrayList<>();
    cmds.add("bin/pregelix");
    // jar
    cmds.add(pregelixStmt.getParameters().get(0));
    // class
    cmds.add(pregelixStmt.getParameters().get(1));
    String customizedPregelixProperty = "-cust-prop";
    String inputConverterClassKey = "pregelix.asterixdb.input.converterclass";
    String inputConverterClassValue = "=org.apache.pregelix.example.converter.VLongIdInputVertexConverter,";
    String outputConverterClassKey = "pregelix.asterixdb.output.converterclass";
    String outputConverterClassValue = "=org.apache.pregelix.example.converter.VLongIdOutputVertexConverter,";
    boolean custPropAdded = false;
    boolean meetCustProp = false;
    // User parameters.
    for (String s : pregelixStmt.getParameters().get(2).split(" ")) {
        if (meetCustProp) {
            if (!s.contains(inputConverterClassKey)) {
                asterixdbParameterBuilder.append(inputConverterClassKey + inputConverterClassValue);
            }
            if (!s.contains(outputConverterClassKey)) {
                asterixdbParameterBuilder.append(outputConverterClassKey + outputConverterClassValue);
            }
            cmds.add(asterixdbParameterBuilder.toString() + s);
            meetCustProp = false;
            custPropAdded = true;
            continue;
        }
        cmds.add(s);
        if (s.equals(customizedPregelixProperty)) {
            meetCustProp = true;
        }
    }
    if (!custPropAdded) {
        cmds.add(customizedPregelixProperty);
        // Appends default converter classes to asterixdbParameterBuilder.
        asterixdbParameterBuilder.append(inputConverterClassKey + inputConverterClassValue);
        asterixdbParameterBuilder.append(outputConverterClassKey + outputConverterClassValue);
        // Remove the last comma.
        asterixdbParameterBuilder.delete(asterixdbParameterBuilder.length() - 1, asterixdbParameterBuilder.length());
        cmds.add(asterixdbParameterBuilder.toString());
    }
    return cmds;
}
Also used : ExternalProperties(org.apache.asterix.common.config.ExternalProperties) ArrayList(java.util.ArrayList)

Example 4 with ExternalProperties

use of org.apache.asterix.common.config.ExternalProperties in project asterixdb by apache.

the class ClusterManager method addNode.

@Override
public void addNode(ICcApplicationContext appCtx, Node node) throws AsterixException {
    try {
        Cluster cluster = ClusterProperties.INSTANCE.getCluster();
        List<Pattern> pattern = new ArrayList<>();
        String asterixInstanceName = appCtx.getMetadataProperties().getInstanceName();
        Patterns prepareNode = PatternCreator.INSTANCE.createPrepareNodePattern(asterixInstanceName, ClusterProperties.INSTANCE.getCluster(), node);
        cluster.getNode().add(node);
        client.submit(prepareNode);
        ExternalProperties externalProps = appCtx.getExternalProperties();
        AsterixEventServiceUtil.poulateClusterEnvironmentProperties(cluster, externalProps.getCCJavaParams(), externalProps.getNCJavaParams());
        pattern.clear();
        String ccHost = cluster.getMasterNode().getClusterIp();
        String hostId = node.getId();
        String nodeControllerId = asterixInstanceName + "_" + node.getId();
        String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
        Pattern startNC = PatternCreator.INSTANCE.createNCStartPattern(ccHost, hostId, nodeControllerId, iodevices, false);
        pattern.add(startNC);
        Patterns startNCPattern = new Patterns(pattern);
        client.submit(startNCPattern);
        removeNode(cluster.getSubstituteNodes().getNode(), node);
        AsterixInstance instance = lookupService.getAsterixInstance(cluster.getInstanceName());
        instance.getCluster().getNode().add(node);
        removeNode(instance.getCluster().getSubstituteNodes().getNode(), node);
        lookupService.updateAsterixInstance(instance);
    } catch (Exception e) {
        throw new AsterixException(e);
    }
}
Also used : Pattern(org.apache.asterix.event.schema.pattern.Pattern) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ArrayList(java.util.ArrayList) ExternalProperties(org.apache.asterix.common.config.ExternalProperties) Cluster(org.apache.asterix.event.schema.cluster.Cluster) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns) AsterixException(org.apache.asterix.common.exceptions.AsterixException)

Aggregations

ExternalProperties (org.apache.asterix.common.config.ExternalProperties)4 ArrayList (java.util.ArrayList)3 Cluster (org.apache.asterix.event.schema.cluster.Cluster)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 List (java.util.List)1 DefaultStatementExecutorFactory (org.apache.asterix.app.translator.DefaultStatementExecutorFactory)1 ClusterProperties (org.apache.asterix.common.config.ClusterProperties)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 AqlCompilationProvider (org.apache.asterix.compiler.provider.AqlCompilationProvider)1 AsterixInstance (org.apache.asterix.event.model.AsterixInstance)1 MasterNode (org.apache.asterix.event.schema.cluster.MasterNode)1 Pattern (org.apache.asterix.event.schema.pattern.Pattern)1 Patterns (org.apache.asterix.event.schema.pattern.Patterns)1 StorageComponentProvider (org.apache.asterix.file.StorageComponentProvider)1 Statement (org.apache.asterix.lang.common.base.Statement)1 RunStatement (org.apache.asterix.lang.common.statement.RunStatement)1 CcApplicationContext (org.apache.asterix.runtime.utils.CcApplicationContext)1