<commit_before>package io.vamp.core.persistence.actor

import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import io.vamp.common.akka.ExecutionContextProvider
import io.vamp.common.notification.NotificationProvider
import io.vamp.common.pulse.PulseClientProvider
import io.vamp.core.model.artifact._
import io.vamp.core.persistence.notification.ArtifactArchivingError
import io.vamp.pulse.api.Event

trait ArchivingProvider extends PulseClientProvider {
  this: NotificationProvider with ExecutionContextProvider =>

  implicit val timeout: Timeout

  val url = ConfigFactory.load().getString("vamp.core.persistence.pulse.url")

  def archiveCreate(artifact: Artifact, source: Option[String]): Artifact =
    if (source.isDefined) archive(artifact, source, s"archiving:create") else artifact

  def archiveUpdate(artifact: Artifact, source: Option[String]): Artifact =
    if (source.isDefined) archive(artifact, source, s"archiving:update") else artifact

  def archiveDelete(artifact: Artifact): Artifact = archive(artifact, None, s"archiving:delete")

  protected def archive(artifact: Artifact, source: Option[String], archiveTag: String) = {
    tagFor(artifact) match {
      case Some(artifactTag) => client.sendEvent(Event(artifactTag :: archiveTag :: Nil, source))
      case _ => exception(ArtifactArchivingError(artifact))
    }
    artifact
  }

  protected def tagFor(artifact: Artifact): Option[String] = artifact.getClass match {
    case t if classOf[Deployment].isAssignableFrom(t) => Some(s"deployments:${artifact.name}")
    case t if classOf[Breed].isAssignableFrom(t) => Some(s"breeds:${artifact.name}")
    case t if classOf[Blueprint].isAssignableFrom(t) => Some(s"blueprints:${artifact.name}")
    case t if classOf[Sla].isAssignableFrom(t) => Some(s"slas:${artifact.name}")
    case t if classOf[Scale].isAssignableFrom(t) => Some(s"scales:${artifact.name}")
    case t if classOf[Escalation].isAssignableFrom(t) => Some(s"escalations:${artifact.name}")
    case t if classOf[Routing].isAssignableFrom(t) => Some(s"routings:${artifact.name}")
    case t if classOf[Filter].isAssignableFrom(t) => Some(s"filters:${artifact.name}")
    case request => None
  }
}<commit_msg>new pulse interface<commit_after>package io.vamp.core.persistence.actor

import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import io.vamp.common.akka.ExecutionContextProvider
import io.vamp.common.notification.NotificationProvider
import io.vamp.core.model.artifact._
import io.vamp.core.persistence.notification.ArtifactArchivingError
import io.vamp.pulse.client.PulseClientProvider
import io.vamp.pulse.model.Event

trait ArchivingProvider extends PulseClientProvider {
  this: NotificationProvider with ExecutionContextProvider =>

  implicit val timeout: Timeout

  val pulseUrl = ConfigFactory.load().getString("vamp.core.persistence.pulse.url")

  def archiveCreate(artifact: Artifact, source: Option[String]): Artifact =
    if (source.isDefined) archive(artifact, source, s"archiving:create") else artifact

  def archiveUpdate(artifact: Artifact, source: Option[String]): Artifact =
    if (source.isDefined) archive(artifact, source, s"archiving:update") else artifact

  def archiveDelete(artifact: Artifact): Artifact = archive(artifact, None, s"archiving:delete")

  protected def archive(artifact: Artifact, source: Option[String], archiveTag: String) = {
    tagFor(artifact) match {
      case Some(artifactTag) => pulseClient.sendEvent(Event(Set(artifactTag, archiveTag), source))
      case _ => exception(ArtifactArchivingError(artifact))
    }
    artifact
  }

  protected def tagFor(artifact: Artifact): Option[String] = artifact.getClass match {
    case t if classOf[Deployment].isAssignableFrom(t) => Some(s"deployments:${artifact.name}")
    case t if classOf[Breed].isAssignableFrom(t) => Some(s"breeds:${artifact.name}")
    case t if classOf[Blueprint].isAssignableFrom(t) => Some(s"blueprints:${artifact.name}")
    case t if classOf[Sla].isAssignableFrom(t) => Some(s"slas:${artifact.name}")
    case t if classOf[Scale].isAssignableFrom(t) => Some(s"scales:${artifact.name}")
    case t if classOf[Escalation].isAssignableFrom(t) => Some(s"escalations:${artifact.name}")
    case t if classOf[Routing].isAssignableFrom(t) => Some(s"routings:${artifact.name}")
    case t if classOf[Filter].isAssignableFrom(t) => Some(s"filters:${artifact.name}")
    case request => None
  }
}
{'fraction_non_alphanumeric': 0.12736699729486023, 'fraction_numerical': 0.0, 'mean_word_length': 5.911214953271028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347115', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1349, 'n_words': 271}