org.springframework.shell.Bootstrap Java Examples

The following examples show how to use org.springframework.shell.Bootstrap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectAccumulo_wrongCredentials() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the wrong password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("asjifo[ijwa".toCharArray());

    // Execute the command
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the command failed.
    assertFalse( connectResult.isSuccess() );
}
 
Example #2
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectAccumulo() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Execute the connect command.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the connection was successful.
    assertTrue( connectResult.isSuccess() );
}
 
Example #3
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectToInstance_instanceDoesNotExist() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Try to connect to a non-existing instance.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance doesNotExist";
    final CommandResult result = shell.executeCommand(cmd);
    assertFalse( result.isSuccess() );
}
 
Example #4
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void disconnect() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Disconnect from it.
    final CommandResult disconnectResult = shell.executeCommand( RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD );
    assertTrue( disconnectResult.isSuccess() );
}
 
Example #5
Source File: LensInterpreter.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
private LensClient createAndSetLensClient(Bootstrap bs) {
  LensClient lensClient;
  try {
    lensClient = new LensClient(lensClientConfig);
    
    for (String beanName : bs.getApplicationContext().getBeanDefinitionNames()) {
      if (bs.getApplicationContext().getBean(beanName) instanceof BaseLensCommand) {
        ((BaseLensCommand) bs.getApplicationContext().getBean(beanName))
          .setClient(lensClient);
      }
    }
  } catch (Exception e) {
    LOGGER.error("unable to create lens client", e);
    throw e;
  }
  return lensClient;
}
 
Example #6
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_connectedToAccumulo() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of Accumulo using the following parameters:\n" +
            "    Username: root\n" +
            "    Instance Name: " + cluster.getInstanceName() + "\n" +
            "    Zookeepers: " + cluster.getZooKeepers();
    assertEquals(expected, msg);
}
 
Example #7
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_connectedToMongo_auths() throws IOException {
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort() + " " +
                    "--username bob";
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of MongoDB using the following parameters:\n" +
            "    Hostname: " + super.getMongoHostname() + "\n" +
            "    Port: " + super.getMongoPort() + "\n" +
            "    Username: bob\n";
    assertEquals(expected, msg);
}
 
Example #8
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void connectToInstance_noAuths() throws IOException {
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final ApplicationContext context = bootstrap.getApplicationContext();
    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    CommandResult result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean( SharedShellState.class );
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
 
Example #9
Source File: LensInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private JLineShell getJLineShell(Bootstrap bs) {
  if (bs instanceof LensBootstrap) {
    return ((LensBootstrap) bs).getLensJLineShellComponent();
  } else {
    return bs.getJLineShellComponent();
  }
}
 
Example #10
Source File: BaseShellTest.java    From Decision with Apache License 2.0 5 votes vote down vote up
public void init() {
    Bootstrap bootstrap = new Bootstrap(null,
            new String[]{"classpath*:/META-INF/spring/spring-shell-plugin-test.xml"});
    shell = bootstrap.getJLineShellComponent();
    applicationContext = bootstrap.getApplicationContext();
    ssaw = applicationContext.getBean(StratioStreamingApiWrapper.class);

    IStratioStreamingAPI stratioStreamingAPI = applicationContext.getBean(IStratioStreamingAPI.class);
    Mockito.when(stratioStreamingAPI.isInit()).thenReturn(true);
}
 
Example #11
Source File: ContextCommandsTest.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
public void exists() throws Exception {
    Bootstrap bootstrap = new Bootstrap();

    JLineShellComponent shell = bootstrap.getJLineShellComponent();

    CommandResult cr = shell.executeCommand("exists /analytics");
    assertEquals(true, cr.isSuccess());
}
 
Example #12
Source File: RyaShellMongoITBase.java    From rya with Apache License 2.0 4 votes vote down vote up
@Before
public void startShell() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException {
    // Bootstrap the shell with the test bean configuration.
    bootstrap = new Bootstrap(new String[]{}, new String[]{"file:src/test/resources/RyaShellTest-context.xml"});
    shell = bootstrap.getJLineShellComponent();
}
 
Example #13
Source File: RyaShellMongoITBase.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * @return The bootstrap that was used to initialize the Shell that will be tested.
 */
public Bootstrap getTestBootstrap() {
    return bootstrap;
}
 
Example #14
Source File: Main.java    From Decision with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Bootstrap.main(args);
}
 
Example #15
Source File: Main.java    From tutorials with MIT License 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Bootstrap.main(args);
}
 
Example #16
Source File: Application.java    From hazelcast-jet-demos with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("hazelcast.logging.type", "slf4j");
    Bootstrap.main(args);
}
 
Example #17
Source File: SimpleCLIIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@BeforeClass
public static void startUp() throws InterruptedException {
    final Bootstrap bootstrap = new Bootstrap();
    shell = bootstrap.getJLineShellComponent();
}
 
Example #18
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void connectToInstance() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean( SharedShellState.class );
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
 
Example #19
Source File: AccumuloRyaCommandsIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void loadsAndQueryData() throws Exception {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Load a statements file into the instance.
    cmd = RyaCommands.LOAD_DATA_CMD + " --file src/test/resources/test-statements.nt";
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Query for all of the statements that were loaded.
    final SparqlPrompt sparqlPrompt = context.getBean(SparqlPrompt.class);
    when(sparqlPrompt.getSparql()).thenReturn(Optional.of("select * where { ?s ?p ?o .}"));

    cmd = RyaCommands.SPARQL_QUERY_CMD;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );
}
 
Example #20
Source File: RyaShellAccumuloITBase.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * @return The bootstrap that was used to initialize the Shell that will be tested.
 */
public Bootstrap getTestBootstrap() {
    return bootstrap;
}
 
Example #21
Source File: RyaShellAccumuloITBase.java    From rya with Apache License 2.0 4 votes vote down vote up
@Before
public void startShell() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException {
    // Bootstrap the shell with the test bean configuration.
    bootstrap = new Bootstrap(new String[]{}, new String[]{"file:src/test/resources/RyaShellTest-context.xml"});
    shell = bootstrap.getJLineShellComponent();
}
 
Example #22
Source File: LensInterpreter.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public int getProgress(InterpreterContext context) {
  if (paraToQH.containsKey(context.getParagraphId())) {
    LOGGER.info("number of items for which progress can be reported :" + paraToQH.size());
    LOGGER.info("number of open lensclient :" + clientMap.size());
    Bootstrap bs = createBootstrap();
    JLineShell shell = getJLineShell(bs);
    LensClient lensClient = null;
    String qh = paraToQH.get(context.getParagraphId()).getQueryHandle();
    try {
      LOGGER.info("fetch query status for : (" + context.getParagraphId() + ") :" + qh);
      lensClient = createAndSetLensClient(bs);
      clientMap.put(lensClient, true);
      CommandResult res = shell.executeCommand("query status " + qh);
      LOGGER.info(context.getParagraphId() + " --> " + res.getResult().toString());
      //change to debug
      Pattern pattern = Pattern.compile(".*(Progress : (\\d\\.\\d)).*");
      Matcher matcher = pattern.matcher(res.getResult().toString().replaceAll("\\n", " "));
      if (matcher.find(2)) {
        Double d = Double.parseDouble(matcher.group(2)) * 100;
        if (d.intValue() == 100) {
          paraToQH.remove(context.getParagraphId());
        }
        return d.intValue();
      } else {
        return 1;
      }
    } catch (Exception e) {
      LOGGER.error("unable to get progress for (" + context.getParagraphId() + ") :" + qh, e);
      paraToQH.remove(context.getParagraphId());
      return 0;
    } finally {
      if (lensClient != null) {
        closeLensClient(lensClient);
        clientMap.remove(lensClient);
      }
      if (shell != null) {
        closeShell(shell);
      }
    }
  }
  return 0;
}
 
Example #23
Source File: LensInterpreter.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public InterpreterResult interpret(String input, InterpreterContext context) {
  if (input == null || input.length() == 0) {
    return new InterpreterResult(Code.ERROR, "no command submitted");
  }
  String st = input.replaceAll("\\n", " ");
  LOGGER.info("LensInterpreter command: " + st);
  
  Bootstrap bs = createBootstrap();
  JLineShell  shell = getJLineShell(bs);
  CommandResult res;
  LensClient lensClient = null;
  String qh = null;
  
  if (st.trim().startsWith("help")) {
    return handleHelp(shell, st);
  }
  
  try {
    lensClient = createAndSetLensClient(bs);
    clientMap.put(lensClient, true);
    
    String lensCommand = modifyQueryStatement(st);
    
    LOGGER.info("executing command : " + lensCommand);
    res = shell.executeCommand(lensCommand);
    
    if (!lensCommand.equals(st) && res != null 
        && res.getResult() != null 
        && res.getResult().toString().trim().matches("[a-z0-9-]+")) {
      // setup query progress tracking
      qh = res.getResult().toString();
      paraToQH.put(context.getParagraphId(), new ExecutionDetail(qh, lensClient, shell));
      String getResultsCmd = "query results --async false " + qh;
      LOGGER.info("executing query results command : " + context.getParagraphId() + " : "
              + getResultsCmd);
      res = shell.executeCommand(getResultsCmd); 
      paraToQH.remove(context.getParagraphId());
    }
  } catch (Exception ex) {
    LOGGER.error("error in interpret", ex);
    return new InterpreterResult(Code.ERROR, ex.getMessage());
  } finally {
    if (shell != null) {
      closeShell(shell);
    }
    if (lensClient != null) {
      closeLensClient(lensClient);
      clientMap.remove(lensClient);
    }
    if (qh != null) {
      paraToQH.remove(context.getParagraphId());
    }
  }
  return new InterpreterResult(Code.SUCCESS, formatResult(st, res));
}
 
Example #24
Source File: LensInterpreter.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
private Bootstrap createBootstrap() {
  return new LensBootstrap();
}
 
Example #25
Source File: AbstractShellIntegrationTest.java    From hudi with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void startup() {
  Bootstrap bootstrap = new Bootstrap();
  shell = bootstrap.getJLineShellComponent();
}
 
Example #26
Source File: Main.java    From hudi with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
  System.out.println("Main called");
  new HoodieSplashScreen();
  Bootstrap.main(args);
}
 
Example #27
Source File: Main.java    From pdf-smart-crop with MIT License 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Bootstrap.main(args);
}
 
Example #28
Source File: Application.java    From spring-statemachine-learning with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Bootstrap.main(args);
}