private Set<Metric> getAllPredictedMetrics() {

    Set<Relationship> relationships =
        inventory.relationships().named(Configuration.PREDICTION_RELATIONSHIP).entities();

    Set<CanonicalPath> metricsCp = new HashSet<>();
    Set<CanonicalPath> metricTypesCp = new HashSet<>();
    Set<CanonicalPath> tenantsCp = new HashSet<>();

    for (Relationship relationship : relationships) {

      predictionRelationships.relationships().put(relationship.getTarget(), relationship);

      if (relationship.getTarget().getSegment().getElementType().equals(Metric.class)) {
        metricsCp.add(relationship.getTarget());
      } else if (relationship.getTarget().getSegment().getElementType().equals(MetricType.class)) {
        metricTypesCp.add(relationship.getTarget());
      } else if (relationship.getTarget().getSegment().getElementType().equals(Tenant.class)) {
        tenantsCp.add(relationship.getTarget());
      }
    }

    Set<Metric> metrics =
        inventory
            .tenants()
            .getAll()
            .feeds()
            .getAll()
            .metrics()
            .getAll(With.paths(metricsCp.toArray(new CanonicalPath[0])))
            .entities();
    Set<Metric> metricsUnderTypes =
        inventory
            .tenants()
            .getAll()
            .feeds()
            .getAll()
            .metricTypes()
            .getAll(With.paths(metricTypesCp.toArray(new CanonicalPath[0])))
            .metrics()
            .getAll()
            .entities();
    Set<Metric> metricsUnderTenant =
        inventory
            .tenants()
            .getAll(With.paths(tenantsCp.toArray(new CanonicalPath[0])))
            .feeds()
            .getAll()
            .metrics()
            .getAll()
            .entities();

    metrics.addAll(metricsUnderTypes);
    metrics.addAll(metricsUnderTenant);

    return metrics;
  }
  @PostConstruct
  public void init() {
    predictionRelationships = new PredictionRelationships();

    Set<Metric> predictedMetrics = getAllPredictedMetrics();

    predictedMetrics.forEach(
        metric -> {
          CanonicalPath tenantCp = metric.getPath().getRoot();
          CanonicalPath metricTypeCp = metric.getType().getPath();
          CanonicalPath metricCp = metric.getPath();

          Set<Subscription.SubscriptionOwner> subscriptionOwners = new HashSet<>();
          CanonicalPath forecastingHorizonCp = null;
          if (predictionRelationships.relationships().get(tenantCp) != null) {
            subscriptionOwners.add(Subscription.SubscriptionOwner.Tenant);
            forecastingHorizonCp = tenantCp;
          }
          if (predictionRelationships.relationships().get(metricTypeCp) != null) {
            subscriptionOwners.add(Subscription.SubscriptionOwner.MetricType);
            forecastingHorizonCp = metricTypeCp;
          }
          if (predictionRelationships.relationships().get(metricCp) != null) {
            subscriptionOwners.add(Subscription.SubscriptionOwner.Metric);
            forecastingHorizonCp = metricCp;
          }

          final Long forecastingHorizon =
              InventoryUtil.parseForecastingHorizon(
                  predictionRelationships.relationships().get(forecastingHorizonCp));

          org.hawkular.datamining.api.model.Metric dataMMetric =
              InventoryUtil.convertMetric(metric, forecastingHorizon);

          final Subscription subscription =
              new DataMiningSubscription(new DataMiningForecaster(dataMMetric), subscriptionOwners);

          subscriptionManager.subscribe(subscription);
        });

    Logger.LOGGER.inventoryInitialized(predictedMetrics.size());
  }
  @Override
  public Set<Relationship> predictionRelationships(CanonicalPath... targetEntity) {

    Set<Relationship> result = new HashSet<>();
    for (CanonicalPath target : targetEntity) {
      Relationship relationship = predictionRelationships.relationships().get(target);

      if (relationship != null) {
        result.add(relationship);
      }
    }

    return result;
  }
 @Override
 public void removePredictionRelationship(Relationship relationship) {
   predictionRelationships.relationships().remove(relationship.getTarget());
 }
 @Override
 public void addPredictionRelationship(Relationship relationship) {
   predictionRelationships.relationships().put(relationship.getTarget(), relationship);
 }