예제 #1
0
 /**
  * Returns the JSON string built by the builder. This is the JSON that can be used by the client
  * add metrics.
  *
  * @return JSON
  * @throws IOException if metrics cannot be converted to JSON
  */
 public String build() throws IOException {
   for (Metric metric : metrics) {
     // verify that there is at least one tag for each metric
     checkState(metric.getTags().size() > 0, metric.getName() + " must contain at least one tag.");
   }
   return mapper.toJson(metrics);
 }
예제 #2
0
  @Override
  // @Secured TODO: we need to handle this property, since getTestByRelation will not work as metric
  // is associated with more tests
  public void removeMetric(Metric metric, Test test) throws ServiceException {
    Metric freshMetric = metricDAO.get(metric.getId());
    Test freshTest = testDAO.get(test.getId());

    // List<Test> newTests = freshMetric.getTests().stream().filter(o ->
    // !o.equals(freshTest)).collect(Collectors.toList());
    // freshMetric.setTests(newTests);

    // List<Metric> newMetrics = freshTest.getMetrics().stream().filter(o ->
    // !o.equals(freshMetric)).collect(Collectors.toList());
    // freshTest.setMetrics(newMetrics);

    freshMetric.getTests().remove(freshTest);
    freshTest.getMetrics().remove(freshMetric);

    metricDAO.update(freshMetric);
    testDAO.update(freshTest);

    if (freshMetric.getTests() == null || freshMetric.getTests().isEmpty()) {
      metricDAO.remove(freshMetric);
    }
  }
예제 #3
0
 /**
  * Calculates the k-means costs of the ClusteringFeature and another ClusteringFeature too a
  * center.
  *
  * @param center the center too calculate the costs
  * @param points the points too calculate the costs
  * @return the costs
  */
 public double calcKMeansCosts(double[] center, ClusteringFeature points) {
   assert (this.sumPoints.length == center.length
       && this.sumPoints.length == points.sumPoints.length);
   return (this.sumSquaredLength + points.sumSquaredLength)
       - 2 * Metric.dotProductWithAddition(this.sumPoints, points.sumPoints, center)
       + (this.numPoints + points.numPoints) * Metric.dotProduct(center);
 }
예제 #4
0
 @Test
 public void testToString() {
   Metric m = new Metric();
   String value = m.toString();
   assertNotNull(value);
   assertFalse(value.isEmpty());
 }
예제 #5
0
 @Test
 public void tesNottEquals() {
   Metric m1 = new Metric();
   Metric m2 = new Metric();
   m1.setFrom("from1");
   m2.setFrom("from2");
   assertFalse(m1.equals(m2));
 }
예제 #6
0
  public void entryUpdated(int statusesCount) {

    thisHour.entriesInserted++;
    thisMinute.entriesInserted++;

    thisHour.statusesInserted += statusesCount;
    thisMinute.statusesInserted += statusesCount;
  }
예제 #7
0
 /**
  * Computes total quota allocations.
  *
  * @return Total allocated quota.
  * @throws StorageException if there was a problem fetching quotas from storage.
  */
 public Metric computeQuotaAllocationTotals() throws StorageException {
   return storage.read(
       storeProvider -> {
         Metric allocation = new Metric();
         for (IResourceAggregate quota : storeProvider.getQuotaStore().fetchQuotas().values()) {
           allocation.accumulate(quota);
         }
         return allocation;
       });
 }
예제 #8
0
    @Override
    public boolean equals(Object o) {
      if (!(o instanceof Metric)) {
        return false;
      }

      Metric other = (Metric) o;
      return getCpu() == other.getCpu()
          && getRamGb() == other.getRamGb()
          && getDiskGb() == other.getDiskGb();
    }
  public void internalTestPerformance(Metric<double[]> metric, double[] value1, double[] value2)
      throws IOException {

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    for (int i = 0; i < 10000000; i++) {
      metric.distance(value1, value2);
    }

    System.out.println(metric.getClass().getName() + ": " + stopWatch.meanTime());
  }
예제 #10
0
 @Override
 @Secured
 public Value addValue(Value value) throws ServiceException {
   TestExecution exec = testExecutionDAO.get(value.getTestExecution().getId());
   if (exec == null) {
     throw new ServiceException(
         "serviceException.addValue.testExecutionNotFound", value.getTestExecution().getName());
   }
   Metric metric = null;
   if (value.getMetric().getId() != null) {
     metric = metricDAO.get(value.getMetric().getId());
   } else {
     List<Metric> metrics =
         metricDAO.getMetricByNameAndGroup(
             value.getMetric().getName(), exec.getTest().getGroupId());
     if (metrics.size() > 0) {
       metric = metricDAO.get(metrics.get(0).getId());
     }
   }
   if (metric == null) {
     throw new ServiceException("serviceException.metricNotFound", value.getMetric().getName());
   }
   value.setTestExecution(exec);
   value.setMetric(metric);
   // check if other values for given metric exist, if yes, we can only add one if both old and new
   // one have at least one parameter
   List<Value> existingValuesForMetric = valueDAO.find(exec.getId(), metric.getId());
   if (!existingValuesForMetric.isEmpty()) {
     for (Value v : existingValuesForMetric) {
       if (!v.hasParameters()) {
         throw new ServiceException("serviceException.unparametrizedMultiValue");
       }
     }
     if (!value.hasParameters()) {
       throw new ServiceException("serviceException.unparametrizedMultiValue");
     }
   }
   Value freshValue = valueDAO.create(value);
   Value freshValueClone = freshValue.clone();
   List<ValueParameter> newParams = new ArrayList<ValueParameter>();
   if (value.hasParameters()) {
     for (ValueParameter valueParameter : value.getParameters()) {
       valueParameter.setValue(freshValue);
       newParams.add(valueParameterDAO.create(valueParameter).clone());
       newParams.get(newParams.size() - 1).setValue(freshValueClone);
     }
   }
   freshValueClone.setParameters(newParams.isEmpty() ? null : newParams);
   return freshValueClone;
 }
예제 #11
0
  @Override
  public Metric getFullMetric(Long id) {
    Metric metric = metricDAO.get(id);
    if (metric == null) {
      return null;
    }
    metric = metric.clone();

    if (metric.getTests() != null) {
      List<Test> clonedTests = metric.getTests().stream().collect(Collectors.toList());
      metric.setTests(clonedTests);
    }

    return metric;
  }
 protected void sendRegularMetrics(final Long epoch) {
   for (Entry<String, SortedMap<MetricName, Metric>> entry :
       getMetricsRegistry().groupedMetrics(c.predicate).entrySet()) {
     for (Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) {
       final Metric metric = subEntry.getValue();
       if (metric != null) {
         try {
           metric.processWith(this, subEntry.getKey(), epoch);
         } catch (Exception ignored) {
           LOG.error("Error sending regular metric:", ignored);
         }
       }
     }
   }
 }
  private <T> void checkNormalized(Iterable<T> targets, Metric<T> metric) {
    for (T target1 : targets) {
      for (T target2 : targets) {
        if (target1 == target2) continue;

        double distance1 = metric.distance(target1, target2);
        assertTrue(">1", Double.compare(distance1, 1d) <= 0);
        assertTrue("<0", Double.compare(distance1, 0d) >= 0);

        double distance2 = metric.distance(target2, target1);
        assertTrue(">1", Double.compare(distance2, 1d) <= 0);
        assertTrue("<0", Double.compare(distance2, 0d) >= 0);
      }
    }
  }
예제 #14
0
 /**
  * Creates a ClusteringFeature.
  *
  * @param center the center point
  * @param radius the radius
  */
 public ClusteringFeature(double[] center, double radius) {
   super(center, radius, 1);
   this.numPoints = 1;
   this.sumPoints = new double[center.length];
   System.arraycopy(center, 0, this.sumPoints, 0, center.length);
   this.sumSquaredLength = Metric.distanceSquared(center);
 }
예제 #15
0
 /**
  * Creates a measure with a metric and an alert level
  *
  * @param metric the metric
  * @param level the alert level
  */
 public Measure(Metric metric, Metric.Level level) {
   this.metric = metric;
   this.metricKey = metric.getKey();
   if (level != null) {
     this.data = level.toString();
   }
 }
예제 #16
0
    @Override
    public Metric deserialize(
        JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext)
        throws JsonParseException {
      JsonObject jsonObject = jsonElement.getAsJsonObject();

      String name = null;
      if (jsonObject.get("name") != null) name = jsonObject.get("name").getAsString();

      boolean exclude_tags = false;
      if (jsonObject.get("exclude_tags") != null)
        exclude_tags = jsonObject.get("exclude_tags").getAsBoolean();

      TreeMultimap<String, String> tags = TreeMultimap.create();
      JsonElement jeTags = jsonObject.get("tags");
      if (jeTags != null) {
        JsonObject joTags = jeTags.getAsJsonObject();
        int count = 0;
        for (Map.Entry<String, JsonElement> tagEntry : joTags.entrySet()) {
          String context = "tags[" + count + "]";
          if (tagEntry.getKey().isEmpty())
            throw new ContextualJsonSyntaxException(context, "name must not be empty");

          if (tagEntry.getValue().isJsonArray()) {
            for (JsonElement element : tagEntry.getValue().getAsJsonArray()) {
              if (element.isJsonNull() || element.getAsString().isEmpty())
                throw new ContextualJsonSyntaxException(
                    context + "." + tagEntry.getKey(), "value must not be null or empty");
              tags.put(tagEntry.getKey(), element.getAsString());
            }
          } else {
            if (tagEntry.getValue().isJsonNull() || tagEntry.getValue().getAsString().isEmpty())
              throw new ContextualJsonSyntaxException(
                  context + "." + tagEntry.getKey(), "value must not be null or empty");
            tags.put(tagEntry.getKey(), tagEntry.getValue().getAsString());
          }
          count++;
        }
      }

      Metric ret = new Metric(name, exclude_tags, tags);

      JsonElement limit = jsonObject.get("limit");
      if (limit != null) ret.setLimit(limit.getAsInt());

      return (ret);
    }
예제 #17
0
  public void copy(String inSource, String inTarget) throws Exception {
    // get arguments
    URL source = URLFactory.createURL(inSource);
    URL target = URLFactory.createURL(inTarget);

    // execute command
    Session session = SessionFactory.createSession(true);
    NSEntry entry = NSFactory.createNSEntry(session, source, Flags.NONE.getValue());

    Task task = entry.copy(TaskMode.TASK, target);
    try {
      Metric metric = task.getMetric("file.copy.progress");
      metric.addCallback(
          new Callback() {
            public boolean cb(Monitorable mt, Metric metric, Context ctx)
                throws NotImplementedException, AuthorizationFailedException {
              try {
                String value = metric.getAttribute(Metric.VALUE);
                String unit = metric.getAttribute(Metric.UNIT);
                System.out.println("Progress: " + value + " " + unit);
              } catch (NotImplementedException e) {
                throw e;
              } catch (AuthorizationFailedException e) {
                throw e;
              } catch (Exception e) {
                e.printStackTrace();
              }
              // callback must stay registered
              return true;
            }
          });
    } catch (DoesNotExistException e) {
      System.err.println("WARN: Monitoring is not supported for this kind of transfer");
    }
    task.run();
    task.waitFor();
    switch (task.getState()) {
      case DONE:
        System.out.println("File successfully copied !");
        break;
      default:
        task.rethrow();
        break;
    }
    entry.close();
  }
예제 #18
0
 /**
  * Sets the data field of the measure.
  *
  * @param s the data
  * @return the measure object instance
  */
 public Measure setData(String s) {
   if (s != null && s.length() >= MAX_TEXT_SIZE && !metric.isDataType()) {
     throw new IllegalArgumentException(
         "Data is too long for non-data metric : size=" + s.length() + ", max=" + MAX_TEXT_SIZE);
   }
   this.data = s;
   return this;
 }
예제 #19
0
 public void setMetric(Metric metric) {
   if (metric == null) {
     throw new DaoException(
         "To-one property 'metric_id' has not-null constraint; cannot set to-one to null");
   }
   synchronized (this) {
     this.metric = metric;
     metric_id = metric.getId();
     metric__resolvedKey = metric_id;
   }
 }
예제 #20
0
  // --------------------------------------------------------------------------
  public DataPoint setMetricRef(Metric table) {
    // We add the record to the transaction if one of the key values change
    if (m_metricId.setValue(table.getId())) {
      if ((m_dirtyFlags.isEmpty()) && (GenOrmDataSource.getGenOrmConnection() != null))
        GenOrmDataSource.getGenOrmConnection().addToTransaction(this);

      m_dirtyFlags.set(METRIC_ID_FIELD_META.getDirtyFlag());
    }

    return ((DataPoint) this);
  }
  private <T> void checkSymmetric(Iterable<T> targets, Metric<T> metric) {
    for (T target1 : targets) {
      for (T target2 : targets) {
        if (target1 == target2) continue;

        double distance1 = metric.distance(target1, target2);
        double distance2 = metric.distance(target2, target1);

        assertTrue("not symmetric", Double.compare(distance1, distance2) == 0);
      }
    }
  }
예제 #22
0
 private void searchA(final int maxALength) {
   stackA[0].length = 0;
   stackA[0].turnIndex = 0;
   int d = 0;
   do {
     while (stackA[d].length < maxALength) {
       final ANode node = stackA[d];
       if (node.turnIndex >= node.turns.length) {
         if (--d < 0) return;
       } else {
         final Turn userTurn = node.turns[node.turnIndex++];
         node.userTurn = userTurn;
         final Turn cubeTurn = SymTransform.getTurn(userTurn, node.symmetry);
         node.cubeTurn = cubeTurn;
         final ANode nextNode = stackA[d + 1];
         final int length = node.length + metric.length(cubeTurn);
         if (length <= maxALength && length <= maxSearchLength) {
           final int ct = transform.twistTable.turn(cubeTurn, node.twist);
           final int ef = transform.flipTable.turn(cubeTurn, node.flip);
           aprn++;
           if (aprn % CYCLES_BETWEEN_USER_CHECK == 0 && (isInterrupted = reporter.shouldStop()))
             return;
           final int ct_ef_d = pruneA.get_twist_flip_dist(node.twist_flip_dist, ct, ef);
           if (ct_ef_d <= maxALength - length) {
             final int meps = transform.mEdgePosSetTable.turn(cubeTurn, node.mEdgePosSet);
             final int ct_meps_d =
                 pruneA.get_twist_mEdgePosSet_dist(node.twist_mEdgePosSet_dist, ct, meps);
             if (ct_meps_d <= maxALength - length) {
               final int ef_meps_d =
                   pruneA.get_flip_mEdgePosSet_dist(node.flip_mEdgePosSet_dist, ef, meps);
               if (ef_meps_d <= maxALength - length) {
                 final int ct_d = pruneA.get_twistFull_dist(node.twist_dist, ct);
                 final int ef_d = pruneA.get_flipFull_dist(node.flip_dist, ef);
                 if (ct_d <= maxALength - length && ef_d <= maxALength - length) {
                   nextNode.setCubeStateA(ct, ef, meps);
                   nextNode.setDists(ct_ef_d, ct_meps_d, ef_meps_d, ct_d, ef_d);
                   nextNode.setTurnState(node, userTurn, turnList);
                   nextNode.length = length;
                   d++;
                 } else apry++;
               } else apry++;
             } else apry++;
           } else apry++;
         }
       }
     }
     stackASize = d--;
     solveB(maxALength);
   } while (!isInterrupted && d >= 0);
 }
예제 #23
0
  public MetricRepositoryRule add(Metric metric) {
    requireNonNull(metric.getKey(), "key can not be null");
    requireNonNull(metric.getId(), "id can not be null");

    checkState(
        !metricsByKey.containsKey(metric.getKey()),
        format("Repository already contains a metric for key %s", metric.getKey()));
    checkState(
        !metricsById.containsKey((long) metric.getId()),
        format("Repository already contains a metric for id %s", metric.getId()));

    metricsByKey.put(metric.getKey(), metric);
    metricsById.put((long) metric.getId(), metric);

    return this;
  }
예제 #24
0
  public List<Metric> reportFindings() {
    swapCaches();

    Map<String, List<MetricDataPoint>> cache = getInActiveCache();
    Set<String> keys = cache.keySet();
    List<Metric> metrics = new ArrayList<Metric>();
    for (String key : keys) {
      List<MetricDataPoint> dps = cache.get(key);
      int max = 0;
      int min = 10000000;
      int counter = 0;
      long total = 0;
      long executionTime;
      double average = 0;
      for (MetricDataPoint dp : dps) {
        counter++;
        executionTime = dp.getExecutionTime();
        if (executionTime < min) min = (int) executionTime;

        if (executionTime > max) max = (int) executionTime;

        total += executionTime;
      }
      if (counter > 0) average = total / counter;

      Metric metric = new Metric();
      metric.setKey(key);
      metric.setMax(max);
      metric.setMin(min);
      metric.setAverage(average);

      metrics.add(metric);
    }

    return metrics;
  }
예제 #25
0
 private void searchB(final int maxALength, final int maxBLength) {
   stackB[0].length = 0;
   stackB[0].turnIndex = 0;
   int d = 0;
   do {
     while (stackB[d].length < maxBLength) {
       final BNode node = stackB[d];
       if (node.turnIndex >= node.turns.length) {
         if (--d < 0) return;
       } else {
         final Turn userTurn = node.turns[node.turnIndex++];
         node.userTurn = userTurn;
         final Turn cubeTurn = SymTransform.getTurn(userTurn, node.symmetry);
         node.cubeTurn = cubeTurn;
         final int length = node.length + metric.length(userTurn);
         if (cubeTurn.isB() && maxALength + length <= maxSearchLength && length <= maxBLength) {
           final BNode nextNode = stackB[d + 1];
           final int mep = transformB.mEdgePosTable.turn(cubeTurn, node.mEdgePos);
           final int cp = transformB.cornerPosTable.turn(cubeTurn, node.cornerPos);
           bprn++;
           if (bprn % CYCLES_BETWEEN_USER_CHECK == 0 && (isInterrupted = reporter.shouldStop()))
             return;
           final int mep_cp_d =
               pruneB.get_mEdgePos_cornerPos_dist(node.mEdgePos_cornerPos_dist, mep, cp);
           if (mep_cp_d <= maxBLength - length) {
             final int udep = transformB.udEdgePosTable.turn(cubeTurn, node.udEdgePos);
             final int mep_udep_d =
                 pruneB.get_mEdgePos_udEdgePos_dist(node.mEdgePos_udEdgePos_dist, mep, udep);
             if (mep_udep_d <= maxBLength - length) {
               nextNode.setCubeState(mep, cp, udep);
               nextNode.setDists(mep_cp_d, mep_udep_d);
               nextNode.setTurnState(node, userTurn, turnListB);
               nextNode.length = length;
               d++;
             } else bpry++;
           } else bpry++;
         }
       }
     }
     stackBSize = d--;
     display();
     maxSearchLength = maxALength + maxBLength - (findAll ? 0 : 1);
   } while (!isInterrupted && d >= 0);
 }
예제 #26
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof Metric == false) return false;
    Metric other = (Metric) obj;

    if (other.getNamespace() == null ^ this.getNamespace() == null) return false;
    if (other.getNamespace() != null && other.getNamespace().equals(this.getNamespace()) == false)
      return false;
    if (other.getMetricName() == null ^ this.getMetricName() == null) return false;
    if (other.getMetricName() != null
        && other.getMetricName().equals(this.getMetricName()) == false) return false;
    if (other.getDimensions() == null ^ this.getDimensions() == null) return false;
    if (other.getDimensions() != null
        && other.getDimensions().equals(this.getDimensions()) == false) return false;
    return true;
  }
예제 #27
0
 private void logMetrics() {
   for (Metric m : metrics.values()) log.info(m.toString());
 }
예제 #28
0
  private List<QueryMetric> parseQueryMetric(JsonObject obj, String contextPrefix)
      throws QueryException, BeanValidationException {
    List<QueryMetric> ret = new ArrayList<QueryMetric>();

    Query query;
    try {
      query = m_gson.fromJson(obj, Query.class);
      validateObject(query);
    } catch (ContextualJsonSyntaxException e) {
      throw new BeanValidationException(
          new SimpleConstraintViolation(e.getContext(), e.getMessage()), "query");
    }

    JsonArray metricsArray = obj.getAsJsonArray("metrics");
    if (metricsArray == null) {
      throw new BeanValidationException(
          new SimpleConstraintViolation("metric[]", "must have a size of at least 1"),
          contextPrefix + "query");
    }

    for (int I = 0; I < metricsArray.size(); I++) {
      String context =
          (!contextPrefix.isEmpty() ? contextPrefix + "." : contextPrefix)
              + "query.metric["
              + I
              + "]";
      try {
        Metric metric = m_gson.fromJson(metricsArray.get(I), Metric.class);

        validateObject(metric, context);

        long startTime = getStartTime(query, context);
        QueryMetric queryMetric =
            new QueryMetric(startTime, query.getCacheTime(), metric.getName());
        queryMetric.setExcludeTags(metric.isExcludeTags());
        queryMetric.setLimit(metric.getLimit());

        long endTime = getEndTime(query);
        if (endTime > -1) queryMetric.setEndTime(endTime);

        if (queryMetric.getEndTime() < startTime)
          throw new BeanValidationException(
              new SimpleConstraintViolation("end_time", "must be greater than the start time"),
              context);

        queryMetric.setCacheString(query.getCacheString() + metric.getCacheString());

        JsonObject jsMetric = metricsArray.get(I).getAsJsonObject();

        JsonElement group_by = jsMetric.get("group_by");
        if (group_by != null) {
          JsonArray groupBys = group_by.getAsJsonArray();
          parseGroupBy(context, queryMetric, groupBys);
        }

        JsonElement aggregators = jsMetric.get("aggregators");
        if (aggregators != null) {
          JsonArray asJsonArray = aggregators.getAsJsonArray();
          if (asJsonArray.size() > 0)
            parseAggregators(context, queryMetric, asJsonArray, query.getTimeZone());
        }

        JsonElement plugins = jsMetric.get("plugins");
        if (plugins != null) {
          JsonArray pluginArray = plugins.getAsJsonArray();
          if (pluginArray.size() > 0) parsePlugins(context, queryMetric, pluginArray);
        }

        JsonElement order = jsMetric.get("order");
        if (order != null) queryMetric.setOrder(Order.fromString(order.getAsString(), context));

        queryMetric.setTags(metric.getTags());

        ret.add(queryMetric);
      } catch (ContextualJsonSyntaxException e) {
        throw new BeanValidationException(
            new SimpleConstraintViolation(e.getContext(), e.getMessage()), context);
      }
    }

    return (ret);
  }
예제 #29
0
 /**
  * Calculates the k-means costs of the ClusteringFeature too a center.
  *
  * @param center the center too calculate the costs
  * @return the costs
  */
 public double calcKMeansCosts(double[] center) {
   assert (this.sumPoints.length == center.length);
   return this.sumSquaredLength
       - 2 * Metric.dotProduct(this.sumPoints, center)
       + this.numPoints * Metric.dotProduct(center);
 }
예제 #30
0
 /**
  * Calculates the k-means costs of the ClusteringFeature and a point too a center.
  *
  * @param center the center too calculate the costs
  * @param point the point too calculate the costs
  * @return the costs
  */
 public double calcKMeansCosts(double[] center, double[] point) {
   assert (this.sumPoints.length == center.length && this.sumPoints.length == point.length);
   return (this.sumSquaredLength + Metric.distanceSquared(point))
       - 2 * Metric.dotProductWithAddition(this.sumPoints, point, center)
       + (this.numPoints + 1) * Metric.dotProduct(center);
 }