accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshelser <...@git.apache.org>
Subject [GitHub] accumulo pull request #194: ACCUMULO-3005 Added REST API calls
Date Sat, 24 Dec 2016 18:23:31 GMT
Github user joshelser commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/194#discussion_r93819796
  
    --- Diff: server/monitor/src/main/java/org/apache/accumulo/monitor/rest/JettyMonitorApplication.java
---
    @@ -0,0 +1,89 @@
    +/*
    + * 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.accumulo.monitor.rest;
    +
    +import java.io.IOException;
    +import java.net.URI;
    +
    +import org.apache.accumulo.core.client.AccumuloException;
    +import org.apache.accumulo.core.client.AccumuloSecurityException;
    +import org.apache.accumulo.core.client.Instance;
    +import org.apache.accumulo.server.AccumuloServerContext;
    +import org.apache.accumulo.server.client.HdfsZooInstance;
    +import org.apache.accumulo.server.conf.ServerConfigurationFactory;
    +import org.eclipse.jetty.server.Server;
    +import org.eclipse.jetty.server.ServerConnector;
    +import org.glassfish.jersey.filter.LoggingFilter;
    +import org.glassfish.jersey.jackson.JacksonFeature;
    +import org.glassfish.jersey.jetty.JettyHttpContainerFactory;
    +import org.glassfish.jersey.server.ResourceConfig;
    +import org.glassfish.jersey.server.ServerProperties;
    +import org.glassfish.jersey.server.mvc.MvcFeature;
    +import org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature;
    +import org.glassfish.jersey.servlet.ServletProperties;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class JettyMonitorApplication extends MonitorApplication {
    +  private static final Logger log = LoggerFactory.getLogger(JettyMonitorApplication.class);
    +
    +  public JettyMonitorApplication() {}
    +
    +  public void run() {
    +    Instance instance = HdfsZooInstance.getInstance();
    +    ServerConfigurationFactory config = new ServerConfigurationFactory(instance);
    +    AccumuloServerContext serverContext = new AccumuloServerContext(config);
    +
    +    // Set the objects on the old monitor and start daemons to regularly poll the data
    +    startDataDaemons(config, instance, serverContext);
    +
    +    final ResourceConfig rc = new ResourceConfig().register(FreemarkerMvcFeature.class).property(MvcFeature.TEMPLATE_BASE_PATH,
"/templates")
    +        .packages("org.apache.accumulo.monitor.rest.api", "org.apache.accumulo.monitor.rest.resources",
"org.apache.accumulo.monitor.rest.view")
    +        .property(ServerProperties.TRACING, "ALL").property(ServletProperties.FILTER_FORWARD_ON_404,
"true")
    +        .property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/web/.*")
    +        .register(new LoggingFilter(java.util.logging.Logger.getLogger("JettyMonitorApplication"),
true)).register(JacksonFeature.class)
    +        .registerClasses(AccumuloExceptionMapper.class);
    +
    +    final URI serverUri = getServerUri();
    +
    +    Server server = JettyHttpContainerFactory.createServer(serverUri, rc);
    +
    +    int port = serverUri.getPort();
    +    if (0 == port) {
    +      port = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
    +    }
    +
    +    String hostname = serverUri.getHost();
    +
    +    log.info("Server bound to " + hostname + ":" + port);
    +
    +    try {
    +      advertiseHttpAddress(serverContext.getConnector().getInstance(), hostname, port);
    +    } catch (AccumuloException | AccumuloSecurityException e) {
    +      throw new RuntimeException("Failed to connect to Accumulo", e);
    +    }
    +
    +    try {
    +      System.in.read();
    --- End diff --
    
    We'll need to create some lifecycle management code here. The `System.in.read()` was a
quick hack to start/stop the server. Stopping the monitor can be done via `kill` (and the
normal JVM shutdown handler can be used). So, likely, we'd just want a `while (true) { Thread.sleep(5000);
}`, breaking on `InterruptedException`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message