This closes #32 CLI changes
This commit is contained in:
commit
9eb4521242
|
@ -20,7 +20,6 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
|
||||
import io.airlift.airline.Cli;
|
||||
import io.airlift.airline.ParseArgumentsUnexpectedException;
|
||||
import org.apache.activemq.artemis.cli.commands.Action;
|
||||
import org.apache.activemq.artemis.cli.commands.ActionContext;
|
||||
import org.apache.activemq.artemis.cli.commands.Create;
|
||||
|
@ -37,7 +36,7 @@ import org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter;
|
|||
|
||||
public class Artemis
|
||||
{
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
String instance = System.getProperty("artemis.instance");
|
||||
|
@ -47,19 +46,18 @@ public class Artemis
|
|||
.withDefaultCommand(HelpAction.class);
|
||||
|
||||
|
||||
builder.withGroup("data").withDescription("data tools group (print|exp|imp|exp|encode|decode) (example ./artemis data print)").
|
||||
withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class,
|
||||
DecodeJournal.class, EncodeJournal.class);
|
||||
builder.withGroup("data")
|
||||
.withDescription("data tools group (print|exp|imp|exp|encode|decode) (example ./artemis data print)").
|
||||
withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class,
|
||||
XmlDataImporter.class,DecodeJournal.class, EncodeJournal.class);
|
||||
|
||||
if (instance != null)
|
||||
{
|
||||
builder = builder
|
||||
.withCommands(Run.class, Stop.class, Kill.class);
|
||||
builder = builder.withCommands(Run.class, Stop.class, Kill.class);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder = builder
|
||||
.withCommand(Create.class);
|
||||
builder = builder.withCommand(Create.class);
|
||||
}
|
||||
|
||||
Cli<Action> parser = builder.build();
|
||||
|
@ -67,18 +65,18 @@ public class Artemis
|
|||
{
|
||||
parser.parse(args).execute(ActionContext.system());
|
||||
}
|
||||
catch (ParseArgumentsUnexpectedException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
System.out.println();
|
||||
parser.parse("help").execute(ActionContext.system());
|
||||
}
|
||||
catch (ConfigurationException configException)
|
||||
{
|
||||
System.err.println(configException.getMessage());
|
||||
System.out.println();
|
||||
System.out.println("Configuration should be specified as 'scheme:location'. Default configuration is 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'");
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
System.err.println(re.getMessage());
|
||||
System.out.println();
|
||||
parser.parse("help").execute(ActionContext.system());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ public class Create extends InputAbstract
|
|||
public static final String ETC_CONNECTOR_SETTINGS_TXT = "etc/connector-settings.txt";
|
||||
public static final String ETC_BOOTSTRAP_WEB_SETTINGS_TXT = "etc/bootstrap-web-settings.txt";
|
||||
|
||||
@Arguments(description = "The instance directory to hold the broker's configuration and data", required = true)
|
||||
@Arguments(description = "The instance directory to hold the broker's configuration and data. Path must be writable.", required = true)
|
||||
File directory;
|
||||
|
||||
@Option(name = "--host", description = "The host name of the broker (Default: 0.0.0.0 or input if clustered)")
|
||||
|
@ -412,6 +412,7 @@ public class Create extends InputAbstract
|
|||
@Override
|
||||
public Object execute(ActionContext context) throws Exception
|
||||
{
|
||||
this.checkDirectory();
|
||||
super.execute(context);
|
||||
|
||||
try
|
||||
|
@ -432,6 +433,24 @@ public class Create extends InputAbstract
|
|||
return this.getClass().getResourceAsStream(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the directory provided either exists and is writable or doesn't exist but can be created.
|
||||
*/
|
||||
private void checkDirectory()
|
||||
{
|
||||
if (!directory.exists())
|
||||
{
|
||||
boolean created = directory.mkdirs();
|
||||
if (!created)
|
||||
{
|
||||
throw new RuntimeException(String.format("Unable to create the path '%s'.", directory));
|
||||
}
|
||||
}
|
||||
else if (!directory.canWrite())
|
||||
{
|
||||
throw new RuntimeException(String.format("The path '%s' is not writable.", directory));
|
||||
}
|
||||
}
|
||||
|
||||
public Object run(ActionContext context) throws Exception
|
||||
{
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.artemis.test;
|
||||
|
||||
import org.apache.activemq.artemis.cli.Artemis;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test to validate that the CLI doesn't throw improper exceptions when invoked.
|
||||
*/
|
||||
public class ArtemisTest
|
||||
{
|
||||
@Test
|
||||
public void invalidCliDoesntThrowException()
|
||||
{
|
||||
testCli("create");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidPathDoesntThrowException()
|
||||
{
|
||||
testCli("create","/rawr");
|
||||
}
|
||||
|
||||
private void testCli(String... args)
|
||||
{
|
||||
try
|
||||
{
|
||||
Artemis.main(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Assert.fail("Exception caught " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue