Skip to content
Permalink
Browse files

Fixing some codestyle issues

  • Loading branch information...
atooni committed Jun 28, 2019
1 parent cd13d10 commit d1146fbf7fb6ba72bad537c0b2156186d620ab02
Showing with 108 additions and 80 deletions.
  1. +1 −1 blended.activemq.client/src/main/scala/blended/activemq/client/internal/AmqClientActivator.scala
  2. +7 −6 blended.akka.http.restjms/src/main/scala/blended/akka/http/restjms/internal/JMSRequestor.scala
  3. +0 −1 blended.jmx/jvm/src/main/scala/blended/jmx/internal/BlendedMBeanServerFacadeImpl.scala
  4. +8 −8 blended.mgmt.mock/src/main/scala/blended/mgmt/mock/MockObjects.scala
  5. +6 −5 ...ded.mgmt.repo.rest/src/main/scala/blended/mgmt/repo/rest/internal/ArtifactRepoRestActivator.scala
  6. +1 −1 blended.mgmt.repo/src/main/scala/blended/mgmt/repo/internal/ArtifactRepoActivator.scala
  7. +12 −9 ...ded.samples/blended.samples.jms/src/main/scala/blended/samples/jms/internal/JmsSampleConfig.scala
  8. +1 −1 blended.security.crypto/src/main/scala/blended/security/crypto/BlendedCryptoSupport.scala
  9. +1 −1 ...er/src/main/scala/blended/streams/dispatcher/internal/builder/DispatcherDestinationResolver.scala
  10. +1 −1 ...ms.dispatcher/src/main/scala/blended/streams/dispatcher/internal/builder/RunnableDispatcher.scala
  11. +12 −3 blended.streams/src/main/scala/blended/streams/FlowProcessor.scala
  12. +4 −0 blended.streams/src/main/scala/blended/streams/jms/JmsFlowSupport.scala
  13. +2 −1 blended.streams/src/main/scala/blended/streams/transaction/FlowTransactionEvent.scala
  14. +2 −4 blended.updater.config/shared/src/main/scala/blended/updater/config/OverlayConfig.scala
  15. +18 −11 blended.updater.config/shared/src/main/scala/blended/updater/config/RuntimeConfig.scala
  16. +9 −9 blended.updater.config/shared/src/test/scala/blended/updater/config/PrickleSpec.scala
  17. +15 −10 blended.updater.tools/src/main/scala/blended/updater/tools/configbuilder/FeatureBuilder.scala
  18. +7 −7 blended.updater/src/main/scala/blended/updater/internal/BlendedUpdaterActivator.scala
  19. +1 −1 blended.updater/src/test/scala/blended/updater/ArtifactDownloaderTest.scala
@@ -74,7 +74,7 @@ class AmqClientActivator extends DominoActivator with ActorSystemWatching {
log.warn(s"Failed to verify connection [${cf.vendor}:${cf.provider}]...invoking failed handler")
failedHandler.verificationFailed(cf)
}
case Failure(t) =>
case Failure(_) =>
s"Unable to verify connection [${cf.vendor}:${cf.provider}]. This connection will not be active"
}
}
@@ -20,7 +20,7 @@ trait JMSRequestor {

private[this] val log = Logger[JMSRequestor]
private[this] val defaultContentTypes = List("application/json", "text/xml")
private[this] val opCounter : AtomicLong = new AtomicLong(0l)
private[this] val opCounter : AtomicLong = new AtomicLong(0L)

implicit val eCtxt : ExecutionContext
implicit val materializer : ActorMaterializer
@@ -66,7 +66,7 @@ trait JMSRequestor {
)
)

case h :: _ =>
case _ :: _ =>
complete {
val f = requestReply(path.toString(), opCfg, cType, request)

@@ -103,8 +103,9 @@ trait JMSRequestor {

val baseUri = s"jms:${opCfg.destination}?jmsKeyFormatStrategy=passthrough&disableTimeToLive=true&requestTimeout=${opCfg.timeout}&replyTo=restJMS.$operation"

val uri = (opCfg.receivetimeout > 0) match {
case true => baseUri + s"&receiveTimeout=${opCfg.receivetimeout}"
val uri : String = if (opCfg.receivetimeout > 0) {
baseUri + s"&receiveTimeout=${opCfg.receivetimeout}"
} else {
case false => baseUri
}

@@ -136,14 +137,14 @@ trait JMSRequestor {
data.map { result =>

val content : Array[Byte] = result.flatten.toArray
log.debug(s"Received request [$opNum] of length [${content.size}] encoding [${opCfg.encoding}], [${new String(content, opCfg.encoding)}]")
log.debug(s"Received request [$opNum] of length [${content.length}] encoding [${opCfg.encoding}], [${new String(content, opCfg.encoding)}]")

executeCamel(operation, opCfg, cType, content) match {
case Success(exchange) =>

if (opCfg.jmsReply) {
val body = exchange.getOut().getBody(classOf[Array[Byte]])
log.info(s"Received response [$opNum] of length [${body.size}] encoding [${opCfg.encoding}], [${new String(body, opCfg.encoding)}]")
log.info(s"Received response [$opNum] of length [${body.length}] encoding [${opCfg.encoding}], [${new String(body, opCfg.encoding)}]")

HttpResponse(
status = StatusCodes.OK,
@@ -39,6 +39,5 @@ class BlendedMBeanServerFacadeImpl(svr : MBeanServer) extends BlendedMBeanServer


val json : String = Pickle.intoString(obj)
//println(s"\n\n${System.currentTimeMillis() - start} : $json")
}
}
@@ -5,16 +5,12 @@ import java.util.UUID
import java.util.concurrent.atomic.AtomicInteger

import blended.updater.config._
import blended.util.logging.Logger

import scala.util.Random

object MockObjects {

private[this] val log = Logger("blended.mgmt.mock.MockObjects")

private[this] lazy val countries : List[String] = List("de", "cz", "bg", "ro")
private[this] lazy val osTypes : List[String] = List("Lnx", "Windows")
private[this] lazy val connectIds : List[String] = List("A", "B")

private[this] lazy val serviceCount = new AtomicInteger(0)
@@ -33,16 +29,18 @@ object MockObjects {
private[this] def sizedProperties(namePrefix : String = "prop", numProps : Int) =
1.to(numProps).map(i => (s"$namePrefix-$i", s"value$i")).toMap

// scalastyle:off magic.number
private[this] def serviceInfo(numProps : Int = 10) : ServiceInfo = ServiceInfo(
name = s"service-${serviceCount.incrementAndGet()}",
serviceType = s"type-${rnd.nextInt(3) + 1}",
timestampMsec = System.currentTimeMillis(),
lifetimeMsec = 5000l,
lifetimeMsec = 5000L,
props = sizedProperties(namePrefix = "property", numProps = rnd.nextInt(10) + 1)
)
// scalastyle:on magic.number

private[this] def serviceSeq(numServices : Int) : List[ServiceInfo] =
1.to(numServices).map(i => serviceInfo()).toList
1.to(numServices).map(_ => serviceInfo()).toList

val noOverlays = OverlaySet(
overlays = Set.empty[OverlayRef],
@@ -74,11 +72,13 @@ object MockObjects {
ProfileGroup(name = "blended-simple", "1.1", List(noOverlays, someOverlays, invalid))
).flatMap(_.toSingle)

def createContainer(numContainers : Integer) : List[ContainerInfo] = 1.to(numContainers).map { i =>
def createContainer(numContainers : Integer) : List[ContainerInfo] = 1.to(numContainers).map { _ =>

val serviceSeqs = 1.to(3).map { i =>
// scalastyle:off magic.number
val serviceSeqs = 1.to(3).map { _ =>
serviceSeq(rnd.nextInt(5) + 1)
}.toList
// scalastyle:on magic.number

ContainerInfo(
containerId = UUID.randomUUID().toString(),
@@ -25,14 +25,15 @@ class ArtifactRepoRestActivator
}

log.info("Registering route under context path: repo")
new SimpleHttpContext("repo", repoRoutes.httpRoute).providesService[HttpContext]
SimpleHttpContext("repo", repoRoutes.httpRoute).providesService[HttpContext]

watchServices[ArtifactRepo] {
case AddingService(repo, r) =>
case AddingService(repo, _) =>
repoRoutes.addRepo(repo)
case ModifiedService(repo, r) =>
// nothing to do
case RemovedService(repo, r) =>
case ModifiedService(repo, _) =>
repoRoutes.removeRepo(repo)
repoRoutes.addRepo(repo)
case RemovedService(repo, _) =>
repoRoutes.removeRepo(repo)
}

@@ -16,7 +16,7 @@ class ArtifactRepoActivator() extends DominoActivator with TypesafeConfigWatchin
whenBundleActive {
log.info(s"About to activate bundle: ${bundleContext.getBundle().getSymbolicName()}")

whenTypesafeConfigAvailable { (config, idService) =>
whenTypesafeConfigAvailable { (config, _) =>
log.debug(s"Config: $config")

try {
@@ -4,19 +4,22 @@ import com.typesafe.config.Config

object JmsSampleConfig {
def apply(cfg : Config) : JmsSampleConfig = new JmsSampleConfig(
destination = cfg.hasPath("destination") match {
case true => cfg.getString("destination")
case false => "topic:jmsSample"
destination = if (cfg.hasPath("destination")) {
cfg.getString("destination")
} else {
"topic:jmsSample"
},

producerInterval = cfg.hasPath("producerInterval") match {
case true => cfg.getLong("producerInterval")
case false => 0l
producerInterval = if (cfg.hasPath("producerInterval")) {
cfg.getLong("producerInterval")
} else {
0L
},

consumeSelector = cfg.hasPath("consumeSelector") match {
case true => Some(cfg.getString("consumeSelector"))
case false => None
consumeSelector = if (cfg.hasPath("consumeSelector")) {
Some(cfg.getString("consumeSelector"))
} else {
None
}
)
}
@@ -31,7 +31,7 @@ object BlendedCryptoSupport {
defaultPwd
}
} catch {
case NonFatal(t) => defaultPwd
case NonFatal(_) => defaultPwd
} finally {
src.foreach(_.close())
}
@@ -44,7 +44,7 @@ class DispatcherDestinationResolver(
message = msg,
destination = dest,
deliveryMode = delMode,
priority = 4,
priority = JmsSendParameter.defaultPriority,
ttl = ttl
)
}
@@ -67,7 +67,7 @@ class RunnableDispatcher(
destinationResolver = s => new TransactionDestinationResolver(s, JmsDestination.asString(internal.transactions)),
jmsDestination = None,
deliveryMode = JmsDeliveryMode.Persistent,
priority = 4,
priority = JmsSendParameter.defaultPriority,
timeToLive = None
)

@@ -14,7 +14,10 @@ object FlowProcessor {

type IntegrationStep = FlowEnvelope => Try[FlowEnvelope]

def transform[T](name : String, log : Logger)(f : FlowEnvelope => Try[T])(implicit clazz : ClassTag[T]) : Graph[FlowShape[FlowEnvelope, Either[FlowEnvelope, T]], NotUsed] = {
def transform[T](
name : String,
log : Logger
)(f : FlowEnvelope => Try[T])(implicit clazz : ClassTag[T]) : Graph[FlowShape[FlowEnvelope, Either[FlowEnvelope, T]], NotUsed] = {

Flow.fromFunction[FlowEnvelope, Either[FlowEnvelope, T]] { env =>
env.exception match {
@@ -51,7 +54,9 @@ object FlowProcessor {
s

case Failure(t) =>
log.warn(t)(s"Exception in FlowProcessor [${env.id}]:[$name] for message [${env.flowMessage}] : [${t.getClass().getSimpleName()} - ${t.getMessage()}]")
log.warn(t)(
s"Exception in FlowProcessor [${env.id}]:[$name] for message [${env.flowMessage}] : [${t.getClass().getSimpleName()} - ${t.getMessage()}]"
)
env.withException(t)
}

@@ -63,7 +68,11 @@ object FlowProcessor {
}.named(name)
}

def log(level : LogLevel, logger : Logger, text : String = "") : Graph[FlowShape[FlowEnvelope, FlowEnvelope], NotUsed] = Flow.fromFunction[FlowEnvelope, FlowEnvelope] { env =>
def log(
level : LogLevel,
logger : Logger,
text : String = ""
) : Graph[FlowShape[FlowEnvelope, FlowEnvelope], NotUsed] = Flow.fromFunction[FlowEnvelope, FlowEnvelope] { env =>
logger.log(level, s"$text : $env")
env
}
@@ -30,6 +30,10 @@ case class JmsAcknowledgeHandler(
}
}

object JmsSendParameter {
val defaultPriority : Int = 4
}

final case class JmsSendParameter(
message : Message,
destination : JmsDestination,
@@ -179,7 +179,8 @@ object FlowTransactionEvent {

val updatedState : WorklistState = envelope.flowMessage match {
case txtMsg : TextFlowMessage => WorklistState.withName(txtMsg.content)
case m => throw new InvalidTransactionEnvelopeException(s"Expected TextFlowMessage for an update envelope, actual [${m.getClass().getName()}]")
case m =>
throw new InvalidTransactionEnvelopeException(s"Expected TextFlowMessage for an update envelope, actual [${m.getClass().getName()}]")
}

FlowTransactionUpdate(id, envelope.flowMessage.header, updatedState, branchIds : _*)
@@ -3,10 +3,8 @@ package blended.updater.config
/**
* Definition of an overlay.
*
* @param name
* The name of the overlay.
* @param version
* The version of the overlay.
* @param name The name of the overlay.
* @param version The version of the overlay.
* @param generatedConfigs
* The config file generators.
* @param properties
@@ -19,9 +19,9 @@ case class RuntimeConfig(
resolvedFeatures : List[FeatureConfig] = List.empty
) {

override def toString() : String = s"${getClass().getSimpleName()}(name=${name},version=${version},bundles=${bundles}" +
s",startLevel=${startLevel},defaultStartLevel=${defaultStartLevel},properties=${properties},frameworkProperties=${frameworkProperties}" +
s",systemProperties=${systemProperties},features=${features},resources=${resources},resolvedFeatures=${resolvedFeatures})"
override def toString() : String = s"${getClass().getSimpleName()}(name=$name,version=$version,bundles=$bundles" +
s",startLevel=$startLevel,defaultStartLevel=$defaultStartLevel,properties=$properties,frameworkProperties=$frameworkProperties" +
s",systemProperties=$systemProperties,features=$features,resources=$resources,resolvedFeatures=$resolvedFeatures)"

def mvnBaseUrl : Option[String] = properties.get(RuntimeConfig.Properties.MVN_REPO)

@@ -30,7 +30,7 @@ case class RuntimeConfig(
def resolveFileName(url : String) : Try[String] = RuntimeConfig.resolveFileName(url)

// TODO: Review this for JavaScript
def baseDir(profileBaseDir : File) : File = new File(profileBaseDir, s"${name}/${version}")
def baseDir(profileBaseDir : File) : File = new File(profileBaseDir, s"$name/$version")

// def localRuntimeConfig(baseDir: File): LocalRuntimeConfig = LocalRuntimeConfig(runtimeConfig = this, baseDir = baseDir)

@@ -45,7 +45,10 @@ case class RuntimeConfig(
}

object RuntimeConfig
extends ((String, String, List[BundleConfig], Int, Int, Map[String, String], Map[String, String], Map[String, String], List[FeatureRef], List[Artifact], List[FeatureConfig]) => RuntimeConfig) {
extends ((
String, String, List[BundleConfig], Int, Int, Map[String, String], Map[String, String],
Map[String, String], List[FeatureRef], List[Artifact], List[FeatureConfig]) => RuntimeConfig
) {

val MvnPrefix = "mvn:"

@@ -55,7 +58,7 @@ object RuntimeConfig
val PROFILE_NAME = "blended.updater.profile.name"
val PROFILE_VERSION = "blended.updater.profile.version"
/**
* selected overlays, format: name:version,name:verion
* selected overlays, format: name:version,name:version
*/
val OVERLAYS = "blended.updater.profile.overlays"
val PROFILE_LOOKUP_FILE = "blended.updater.profile.lookup.file"
@@ -67,16 +70,20 @@ object RuntimeConfig
def resolveBundleUrl(url : String, mvnBaseUrl : Option[String] = None) : Try[String] = Try {
if (url.startsWith(MvnPrefix)) {
mvnBaseUrl match {
case Some(base) => MvnGav.parse(url.substring(MvnPrefix.size)).get.toUrl(base)
case None => sys.error("No repository defined to resolve url: " + url)
case Some(base) => MvnGav.parse(url.substring(MvnPrefix.length)).get.toUrl(base)
case None => sys.error("No repository defined to resolve url: " + url)
}
} else url
} else {
url
}
}

def resolveFileName(url : String) : Try[String] = Try {
val resolvedUrl = if (url.startsWith(MvnPrefix)) {
MvnGav.parse(url.substring(MvnPrefix.size)).get.toUrl("file:///")
} else url
MvnGav.parse(url.substring(MvnPrefix.length)).get.toUrl("file:///")
} else {
url
}
val path = new URL(resolvedUrl).getPath()
path.split("[/]").filter(!_.isEmpty()).reverse.headOption.getOrElse(path)
}

0 comments on commit d1146fb

Please sign in to comment.
You can’t perform that action at this time.