accumulo-dev mailing list archives

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

    https://github.com/apache/accumulo/pull/194#discussion_r93932212
  
    --- Diff: server/monitor/src/main/java/org/apache/accumulo/monitor/rest/resources/TracesResource.java
---
    @@ -0,0 +1,356 @@
    +/*
    + * 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.resources;
    +
    +import static java.lang.Math.min;
    +import static java.nio.charset.StandardCharsets.UTF_8;
    +
    +import java.io.IOException;
    +import java.security.PrivilegedAction;
    +import java.security.PrivilegedExceptionAction;
    +import java.util.AbstractMap;
    +import java.util.Collection;
    +import java.util.Map;
    +import java.util.Map.Entry;
    +import java.util.Set;
    +import java.util.TreeMap;
    +
    +import javax.ws.rs.GET;
    +import javax.ws.rs.Path;
    +import javax.ws.rs.PathParam;
    +import javax.ws.rs.Produces;
    +import javax.ws.rs.core.MediaType;
    +
    +import org.apache.accumulo.core.client.AccumuloException;
    +import org.apache.accumulo.core.client.AccumuloSecurityException;
    +import org.apache.accumulo.core.client.Connector;
    +import org.apache.accumulo.core.client.Scanner;
    +import org.apache.accumulo.core.client.TableNotFoundException;
    +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
    +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties;
    +import org.apache.accumulo.core.client.security.tokens.KerberosToken;
    +import org.apache.accumulo.core.client.security.tokens.PasswordToken;
    +import org.apache.accumulo.core.conf.AccumuloConfiguration;
    +import org.apache.accumulo.core.conf.Property;
    +import org.apache.accumulo.core.data.Key;
    +import org.apache.accumulo.core.data.Range;
    +import org.apache.accumulo.core.data.Value;
    +import org.apache.accumulo.monitor.Monitor;
    +import org.apache.accumulo.monitor.rest.api.AddlInformation;
    +import org.apache.accumulo.monitor.rest.api.AnnotationInformation;
    +import org.apache.accumulo.monitor.rest.api.DataInformation;
    +import org.apache.accumulo.monitor.rest.api.RecentTracesInformation;
    +import org.apache.accumulo.monitor.rest.api.RecentTracesList;
    +import org.apache.accumulo.monitor.rest.api.TraceInformation;
    +import org.apache.accumulo.monitor.rest.api.TraceList;
    +import org.apache.accumulo.monitor.rest.api.TraceType;
    +import org.apache.accumulo.monitor.rest.api.TracesForTypeInformation;
    +import org.apache.accumulo.monitor.servlets.trace.NullScanner;
    +import org.apache.accumulo.server.client.HdfsZooInstance;
    +import org.apache.accumulo.server.security.SecurityUtil;
    +import org.apache.accumulo.tracer.SpanTree;
    +import org.apache.accumulo.tracer.SpanTreeVisitor;
    +import org.apache.accumulo.tracer.TraceDump;
    +import org.apache.accumulo.tracer.TraceFormatter;
    +import org.apache.accumulo.tracer.thrift.Annotation;
    +import org.apache.accumulo.tracer.thrift.RemoteSpan;
    +import org.apache.hadoop.io.Text;
    +import org.apache.hadoop.security.UserGroupInformation;
    +
    +@Path("/trace")
    +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    +public class TracesResource {
    +
    +  @Path("/summary/{minutes}")
    +  @GET
    +  public RecentTracesList getTraces(@PathParam("minutes") int minutes) throws Exception
{
    +
    +    RecentTracesList recentTraces = new RecentTracesList();
    +
    +    Entry<Scanner,UserGroupInformation> pair = getScanner();
    +    final Scanner scanner = pair.getKey();
    +    if (scanner == null) {
    +      return null;
    +    }
    +
    +    Range range = getRangeForTrace(minutes);
    +    scanner.setRange(range);
    +
    +    final Map<String,RecentTracesInformation> summary = new TreeMap<>();
    +    if (null != pair.getValue()) {
    +      pair.getValue().doAs(new PrivilegedAction<Void>() {
    +        @Override
    +        public Void run() {
    +          parseSpans(scanner, summary);
    +          return null;
    +        }
    +      });
    +    } else {
    +      parseSpans(scanner, summary);
    +    }
    +
    +    for (Entry<String,RecentTracesInformation> entry : summary.entrySet()) {
    +      RecentTracesInformation stat = entry.getValue();
    +      recentTraces.addTrace(stat);
    +    }
    +
    +    return recentTraces;
    +  }
    +
    +  @Path("/listType/{type}/{minutes}")
    +  @GET
    +  public TraceType getTracesType(@PathParam("type") String type, @PathParam("minutes")
int minutes) throws Exception {
    +
    +    TraceType typeTraces = new TraceType(type);
    +
    +    Entry<Scanner,UserGroupInformation> pair = getScanner();
    +    final Scanner scanner = pair.getKey();
    +    if (scanner == null) {
    +      return null;
    +    }
    +
    +    Range range = getRangeForTrace(minutes);
    +
    +    scanner.setRange(range);
    +
    +    if (null != pair.getValue()) {
    +      pair.getValue().doAs(new PrivilegedAction<Void>() {
    +        @Override
    +        public Void run() {
    +          for (Entry<Key,Value> entry : scanner) {
    +            RemoteSpan span = TraceFormatter.getRemoteSpan(entry);
    +
    +            if (span.description.equals(type)) {
    +              typeTraces.addTrace(new TracesForTypeInformation(span));
    +            }
    +          }
    +          return null;
    +        }
    +      });
    +    } else {
    +      for (Entry<Key,Value> entry : scanner) {
    +        RemoteSpan span = TraceFormatter.getRemoteSpan(entry);
    +        if (span.description.equals(type)) {
    +          typeTraces.addTrace(new TracesForTypeInformation(span));
    +        }
    +
    +      }
    +    }
    +
    +    return typeTraces;
    +  }
    +
    +  @Path("/show/{id}")
    +  @GET
    +  public TraceList getTracesType(@PathParam("id") String id) throws Exception {
    +    TraceList traces = new TraceList(id);
    +
    +    if (id == null) {
    +      return null;
    +    }
    +
    +    Entry<Scanner,UserGroupInformation> entry = getScanner();
    +    final Scanner scanner = entry.getKey();
    +    if (scanner == null) {
    +      return null;
    +    }
    +
    +    Range range = new Range(new Text(id));
    +    scanner.setRange(range);
    +    final SpanTree tree = new SpanTree();
    +    long start;
    +
    +    if (null != entry.getValue()) {
    +      start = entry.getValue().doAs(new PrivilegedAction<Long>() {
    +        @Override
    +        public Long run() {
    +          return addSpans(scanner, tree, Long.MAX_VALUE);
    +        }
    +      });
    +    } else {
    +      start = addSpans(scanner, tree, Long.MAX_VALUE);
    +    }
    +
    +    final long finalStart = start;
    +    Set<Long> visited = tree.visit(new SpanTreeVisitor() {
    +      @Override
    +      public void visit(int level, RemoteSpan parent, RemoteSpan node, Collection<RemoteSpan>
children) {
    +        traces.addTrace(addTraceInformation(level, node, finalStart));
    +      }
    +    });
    +    tree.nodes.keySet().removeAll(visited);
    +    if (!tree.nodes.isEmpty()) {
    +      for (RemoteSpan span : TraceDump.sortByStart(tree.nodes.values())) {
    +        traces.addTrace(addTraceInformation(0, span, finalStart));
    +      }
    +    }
    +
    +    return traces;
    +  }
    +
    +  private static TraceInformation addTraceInformation(int level, RemoteSpan node, long
finalStart) {
    +
    +    boolean hasData = node.data != null && !node.data.isEmpty();
    +    boolean hasAnnotations = node.annotations != null && !node.annotations.isEmpty();
    +
    +    AddlInformation addlData = new AddlInformation();
    +
    +    if (hasData || hasAnnotations) {
    --- End diff --
    
    I see it now, I took it from the current monitor and it is needed there, but not here,
thanks!


---
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