Search in sources :

Example 1 with RunStatement

use of org.apache.asterix.lang.common.statement.RunStatement 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 RunStatement

use of org.apache.asterix.lang.common.statement.RunStatement in project asterixdb by apache.

the class QueryTranslator method handlePregelixStatement.

protected void handlePregelixStatement(MetadataProvider metadataProvider, Statement stmt, IHyracksClientConnection hcc) throws Exception {
    RunStatement pregelixStmt = (RunStatement) stmt;
    boolean bActiveTxn = true;
    String dataverseNameFrom = getActiveDataverse(pregelixStmt.getDataverseNameFrom());
    String dataverseNameTo = getActiveDataverse(pregelixStmt.getDataverseNameTo());
    String datasetNameFrom = pregelixStmt.getDatasetNameFrom().getValue();
    String datasetNameTo = pregelixStmt.getDatasetNameTo().getValue();
    String fullyQualifiedDatasetNameTo = DatasetUtil.isFullyQualifiedName(datasetNameTo) ? datasetNameTo : dataverseNameTo + '.' + datasetNameTo;
    MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
    metadataProvider.setMetadataTxnContext(mdTxnCtx);
    MetadataLockManager.INSTANCE.insertDeleteUpsertBegin(metadataProvider.getLocks(), fullyQualifiedDatasetNameTo);
    try {
        prepareRunExternalRuntime(metadataProvider, hcc, pregelixStmt, dataverseNameFrom, dataverseNameTo, datasetNameFrom, datasetNameTo, mdTxnCtx);
        String pregelixHomeKey = "PREGELIX_HOME";
        // Finds PREGELIX_HOME in system environment variables.
        String pregelixHome = System.getenv(pregelixHomeKey);
        // Finds PREGELIX_HOME in Java properties.
        if (pregelixHome == null) {
            pregelixHome = System.getProperty(pregelixHomeKey);
        }
        // Finds PREGELIX_HOME in AsterixDB configuration.
        if (pregelixHome == null) {
            // Since there is a default value for PREGELIX_HOME in CompilerProperties,
            // pregelixHome can never be null.
            pregelixHome = appCtx.getCompilerProperties().getPregelixHome();
        }
        // Constructs the pregelix command line.
        List<String> cmd = constructPregelixCommand(pregelixStmt, dataverseNameFrom, datasetNameFrom, dataverseNameTo, datasetNameTo);
        ProcessBuilder pb = new ProcessBuilder(cmd);
        pb.directory(new File(pregelixHome));
        pb.redirectErrorStream(true);
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
        bActiveTxn = false;
        // Executes the Pregelix command.
        int resultState = executeExternalShellProgram(pb);
        // Checks the return state of the external Pregelix command.
        if (resultState != 0) {
            throw new AlgebricksException("Something went wrong executing your Pregelix Job. Perhaps the Pregelix cluster " + "needs to be restarted. " + "Check the following things: Are the datatypes of Asterix and Pregelix matching? " + "Is the server configuration correct (node names, buffer sizes, framesize)? " + "Check the logfiles for more details.");
        }
    } catch (Exception e) {
        if (bActiveTxn) {
            abort(e, e, mdTxnCtx);
        }
        throw e;
    } finally {
        metadataProvider.getLocks().unlock();
    }
}
Also used : RunStatement(org.apache.asterix.lang.common.statement.RunStatement) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) ExternalFile(org.apache.asterix.external.indexing.ExternalFile) File(java.io.File) DatasetNodegroupCardinalityHint(org.apache.asterix.metadata.dataset.hints.DatasetHints.DatasetNodegroupCardinalityHint) AlgebricksAbsolutePartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException)

Aggregations

RunStatement (org.apache.asterix.lang.common.statement.RunStatement)2 File (java.io.File)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DefaultStatementExecutorFactory (org.apache.asterix.app.translator.DefaultStatementExecutorFactory)1 ClusterProperties (org.apache.asterix.common.config.ClusterProperties)1 ExternalProperties (org.apache.asterix.common.config.ExternalProperties)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 AqlCompilationProvider (org.apache.asterix.compiler.provider.AqlCompilationProvider)1 Cluster (org.apache.asterix.event.schema.cluster.Cluster)1 MasterNode (org.apache.asterix.event.schema.cluster.MasterNode)1 ExternalFile (org.apache.asterix.external.indexing.ExternalFile)1 StorageComponentProvider (org.apache.asterix.file.StorageComponentProvider)1 Statement (org.apache.asterix.lang.common.base.Statement)1 MetadataException (org.apache.asterix.metadata.MetadataException)1 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)1