use of org.apache.helix.rest.common.HelixRestNamespace in project helix by apache.
the class AbstractTestClass method getTestContainerFactory.
@Override
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
return new TestContainerFactory() {
@Override
public TestContainer create(final URI baseUri, DeploymentContext deploymentContext) {
return new TestContainer() {
private HelixRestServer _helixRestServer;
@Override
public ClientConfig getClientConfig() {
return null;
}
@Override
public URI getBaseUri() {
return baseUri;
}
@Override
public void start() {
// Create namespace manifest map
List<HelixRestNamespace> namespaces = new ArrayList<>();
// Add test namespace
namespaces.add(new HelixRestNamespace(TEST_NAMESPACE, HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, _zkAddrTestNS, false));
// Add default namesapce
namespaces.add(new HelixRestNamespace(ZK_ADDR));
try {
_helixRestServer = new HelixRestServer(namespaces, baseUri.getPort(), baseUri.getPath(), Arrays.<AuditLogger>asList(_auditLogger));
_helixRestServer.start();
} catch (Exception ex) {
throw new TestContainerException(ex);
}
}
@Override
public void stop() {
_helixRestServer.shutdown();
}
};
}
};
}
use of org.apache.helix.rest.common.HelixRestNamespace in project helix by apache.
the class TestHelixRestServer method testInvalidHelixRestServerInitialization.
@Test
public void testInvalidHelixRestServerInitialization() {
// Namespace manifests has invalid metadata store type should generate failure
try {
List<HelixRestNamespace> invalidManifest1 = new ArrayList<>();
invalidManifest1.add(new HelixRestNamespace("test1", HelixRestNamespace.HelixMetadataStoreType.valueOf("InvalidMetadataStore"), ZK_ADDR, false));
HelixRestServer svr = new HelixRestServer(invalidManifest1, 10250, "/", Collections.<AuditLogger>emptyList());
Assert.assertFalse(true, "InvalidManifest1 test failed");
} catch (IllegalArgumentException e) {
// OK
}
// Namespace manifests has invalid namespace name shall generate failure
try {
List<HelixRestNamespace> invalidManifest2 = new ArrayList<>();
invalidManifest2.add(new HelixRestNamespace("", HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR, true));
HelixRestServer svr = new HelixRestServer(invalidManifest2, 10250, "/", Collections.<AuditLogger>emptyList());
Assert.assertFalse(true, "InvalidManifest2 test failed");
} catch (IllegalArgumentException e) {
// OK
}
// Duplicated namespace shall cause exception
try {
List<HelixRestNamespace> invalidManifest3 = new ArrayList<>();
invalidManifest3.add(new HelixRestNamespace("DuplicatedName", HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR, true));
invalidManifest3.add(new HelixRestNamespace("DuplicatedName", HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR, false));
HelixRestServer svr = new HelixRestServer(invalidManifest3, 10250, "/", Collections.<AuditLogger>emptyList());
Assert.assertFalse(true, "InvalidManifest3 test failed");
} catch (IllegalArgumentException e) {
// OK
}
// More than 1 default namespace shall cause failure
try {
List<HelixRestNamespace> invalidManifest4 = new ArrayList<>();
invalidManifest4.add(new HelixRestNamespace("test4-1", HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR, true));
invalidManifest4.add(new HelixRestNamespace("test4-2", HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, ZK_ADDR, true));
HelixRestServer svr = new HelixRestServer(invalidManifest4, 10250, "/", Collections.<AuditLogger>emptyList());
Assert.assertFalse(true, "InvalidManifest4 test failed");
} catch (IllegalStateException e) {
// OK
}
}
use of org.apache.helix.rest.common.HelixRestNamespace in project helix by apache.
the class HelixRestMain method processCommandLineArgs.
private static void processCommandLineArgs(String[] cliArgs) throws Exception {
CommandLineParser cliParser = new GnuParser();
Options cliOptions = constructCommandLineOptions();
CommandLine cmd = null;
try {
cmd = cliParser.parse(cliOptions, cliArgs);
} catch (ParseException pe) {
LOG.error("RestAdminApplication: failed to parse command-line options: " + pe.toString());
printUsage(cliOptions);
System.exit(1);
}
int port = DEFAULT_PORT;
String zkAddr;
List<HelixRestNamespace> namespaces = new ArrayList<>();
if (cmd.hasOption(HELP)) {
printUsage(cliOptions);
return;
} else {
if (cmd.hasOption(PORT)) {
port = Integer.parseInt(cmd.getOptionValue(PORT));
}
zkAddr = String.valueOf(cmd.getOptionValue(ZKSERVERADDRESS));
namespaces.add(new HelixRestNamespace(zkAddr));
if (cmd.hasOption(NAMESPACE_MANIFEST_FILE)) {
constructNamespaceFromConfigFile(String.valueOf(cmd.getOptionValue(NAMESPACE_MANIFEST_FILE)), namespaces);
}
}
final HelixRestServer restServer = new HelixRestServer(namespaces, port, URI_PREFIX, Arrays.<AuditLogger>asList(new FileBasedAuditLogger()));
try {
restServer.start();
restServer.join();
} catch (HelixException ex) {
LOG.error("Failed to start Helix rest server, " + ex);
} finally {
restServer.shutdown();
}
}
use of org.apache.helix.rest.common.HelixRestNamespace in project helix by apache.
the class HelixRestServer method init.
private void init(List<HelixRestNamespace> namespaces, int port, String urlPrefix, List<AuditLogger> auditLoggers) {
if (namespaces.size() == 0) {
throw new IllegalArgumentException("No namespace specified! Please provide ZOOKEEPER address or namespace manifest.");
}
_port = port;
_urlPrefix = urlPrefix;
_server = new Server(_port);
_auditLoggers = auditLoggers;
_resourceConfigMap = new HashMap<>();
_servletContextHandler = new ServletContextHandler(_server, _urlPrefix);
_helixNamespaces = namespaces;
// Initialize all namespaces
try {
for (HelixRestNamespace namespace : _helixNamespaces) {
LOG.info("Initializing namespace " + namespace.getName());
prepareServlet(namespace, ServletType.COMMON_SERVLET);
if (namespace.isDefault()) {
LOG.info("Creating default servlet for default namespace");
prepareServlet(namespace, ServletType.DEFAULT_SERVLET);
}
}
} catch (Exception e) {
LOG.error("Failed to initialize helix rest server. Tearing down.");
cleanupResourceConfigs();
throw e;
}
// Start special servlet for serving namespaces
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
shutdown();
}
}));
}
use of org.apache.helix.rest.common.HelixRestNamespace in project helix by apache.
the class NamespacesAccessor method getHelixRestNamespaces.
@GET
public Response getHelixRestNamespaces() {
@SuppressWarnings("unchecked") List<HelixRestNamespace> allNamespaces = (List<HelixRestNamespace>) _application.getProperties().get(ContextPropertyKeys.ALL_NAMESPACES.name());
List<Map<String, String>> ret = new ArrayList<>();
for (HelixRestNamespace namespace : allNamespaces) {
ret.add(namespace.getRestInfo());
}
return JSONRepresentation(ret);
}
Aggregations