diff --git a/.gitignore b/.gitignore index 23942b60a..8198352e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,30 @@ *.class *.log *.log.* # mvn target/ *.versionsBackup # emacs cruft *.*~ +# vim swap files +*.swp + # javascript artifacts **/src/main/js/build/ **/js/node/ **/js/node_modules/ **/resources/client/config/ **/resources/client/happy/happy-whoami.xml **/resources/client/index.html **/resources/client/src/ # idea .idea/ *.iml *.ipr *.iws # osx cruft .DS_Store diff --git a/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala b/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala index 9218e49a9..5d86feee8 100644 --- a/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala +++ b/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala @@ -1,159 +1,159 @@ package net.shrine.wiring import javax.sql.DataSource import com.typesafe.config.{Config, ConfigFactory} import net.shrine.adapter.AdapterComponents import net.shrine.adapter.dao.AdapterDao import net.shrine.adapter.service.{AdapterRequestHandler, AdapterResource, AdapterService, I2b2AdminResource, I2b2AdminService} import net.shrine.broadcaster.dao.HubDao import net.shrine.broadcaster.dao.squeryl.SquerylHubDao import net.shrine.broadcaster.service.HubComponents import net.shrine.client.{EndpointConfig, JerseyHttpClient, OntClient, Poster, PosterOntClient} import net.shrine.config.ConfigExtensions import net.shrine.config.mappings.AdapterMappings import net.shrine.crypto.{DefaultSignerVerifier, KeyStoreCertCollection, KeyStoreDescriptorParser, TrustParam} import net.shrine.dao.squeryl.{DataSourceSquerylInitializer, SquerylDbAdapterSelecter, SquerylInitializer} import net.shrine.happy.{HappyShrineResource, HappyShrineService} import net.shrine.log.Loggable -import net.shrine.ont.data.OntClientOntologyMetadata +import net.shrine.ont.data.{OntClientOntologyMetadata, OntClientOntologyMetadataProvider} import net.shrine.protocol.{HiveCredentials, NodeId, ResultOutputType, ResultOutputTypes} import net.shrine.qep.{I2b2BroadcastResource, QueryEntryPointComponents, ShrineResource} import net.shrine.slick.TestableDataSourceCreator import net.shrine.status.StatusJaxrs import org.squeryl.internals.DatabaseAdapter /** * @author clint * @since Jan 14, 2014 * * Application wiring for Shrine. */ object ShrineOrchestrator extends ShrineJaxrsResources with Loggable { override def resources: Iterable[AnyRef] = { Seq(happyResource,statusJaxrs) ++ shrineResource ++ i2b2BroadcastResource ++ adapterResource ++ i2b2AdminResource ++ hubComponents.map(_.broadcasterMultiplexerResource) } //todo another pass to put things only used in one place into that place's apply(Config) //Load config from file on the classpath called "shrine.conf" lazy val config: Config = ConfigFactory.load("shrine") val shrineConfig = config.getConfig("shrine") protected lazy val nodeId: NodeId = NodeId(shrineConfig.getString("humanReadableNodeName")) //TODO: Don't assume keystore lives on the filesystem, could come from classpath, etc lazy val keyStoreDescriptor = shrineConfig.getConfigured("keystore",KeyStoreDescriptorParser(_)) lazy val certCollection: KeyStoreCertCollection = KeyStoreCertCollection.fromFileRecoverWithClassPath(keyStoreDescriptor) protected lazy val keystoreTrustParam: TrustParam = TrustParam.SomeKeyStore(certCollection) //todo used by the adapterServide and happyShrineService, but not by the QEP. maybe each can have its own signerVerivier lazy val signerVerifier: DefaultSignerVerifier = new DefaultSignerVerifier(certCollection) protected lazy val dataSource: DataSource = TestableDataSourceCreator.dataSource(shrineConfig.getConfig("squerylDataSource.database")) protected lazy val squerylAdapter: DatabaseAdapter = SquerylDbAdapterSelecter.determineAdapter(shrineConfig.getString("shrineDatabaseType")) protected lazy val squerylInitializer: SquerylInitializer = new DataSourceSquerylInitializer(dataSource, squerylAdapter) //todo it'd be better for the adapter and qep to each have its own connection to the pm cell. private lazy val pmEndpoint: EndpointConfig = shrineConfig.getConfigured("pmEndpoint", EndpointConfig(_)) lazy val pmPoster: Poster = Poster(certCollection,pmEndpoint) protected lazy val breakdownTypes: Set[ResultOutputType] = shrineConfig.getOptionConfigured("breakdownResultOutputTypes", ResultOutputTypes.fromConfig).getOrElse(Set.empty) //todo why does the qep need a HubDao ? protected lazy val hubDao: HubDao = new SquerylHubDao(squerylInitializer, new net.shrine.broadcaster.dao.squeryl.tables.Tables) //todo really should be part of the adapter config, but is out in shrine's part of the name space lazy val crcHiveCredentials: HiveCredentials = shrineConfig.getConfigured("hiveCredentials", HiveCredentials(_, HiveCredentials.CRC)) val adapterComponents:Option[AdapterComponents] = shrineConfig.getOptionConfiguredIf("adapter", AdapterComponents( _, certCollection, squerylInitializer, breakdownTypes, crcHiveCredentials, signerVerifier, pmPoster, nodeId )) //todo maybe just break demeter too use this lazy val adapterService: Option[AdapterService] = adapterComponents.map(_.adapterService) //todo maybe just break demeter too use this lazy val i2b2AdminService: Option[I2b2AdminService] = adapterComponents.map(_.i2b2AdminService) //todo this is only used by happy lazy val adapterDao: Option[AdapterDao] = adapterComponents.map(_.adapterDao) //todo this is only used by happy lazy val adapterMappings: Option[AdapterMappings] = adapterComponents.map(_.adapterMappings) val shouldQuerySelf = "hub.shouldQuerySelf" lazy val localAdapterServiceOption: Option[AdapterRequestHandler] = if(shrineConfig.getOption(shouldQuerySelf,_.getBoolean).getOrElse(false)) { //todo give this a default value (of false) in the reference.conf for the Hub, and make it part of the Hub's apply(config) require(adapterService.isDefined, s"Self-querying requested because shrine.$shouldQuerySelf is true, but this node is not configured to have an adapter") adapterService } else None //todo eventually make this just another downstream node accessed via loopback val hubConfig = shrineConfig.getConfig("hub") lazy val hubComponents: Option[HubComponents] = shrineConfig.getOptionConfiguredIf("hub",HubComponents(_, keystoreTrustParam, nodeId, localAdapterServiceOption, breakdownTypes, hubDao )) //todo anything that requires qepConfig should be inside QueryEntryPointComponents's apply protected lazy val qepConfig = shrineConfig.getConfig("queryEntryPoint") lazy val queryEntryPointComponents:Option[QueryEntryPointComponents] = shrineConfig.getOptionConfiguredIf("queryEntryPoint",QueryEntryPointComponents(_, certCollection, breakdownTypes, hubComponents.map(_.broadcastDestinations), hubDao, //todo the QEP should not need the hub dao squerylInitializer, //todo could really have its own pmPoster //todo could really have its own )) protected lazy val pmUrlString: String = pmEndpoint.url.toString private lazy val ontEndpoint: EndpointConfig = shrineConfig.getConfigured("ontEndpoint", EndpointConfig(_)) protected lazy val ontPoster: Poster = Poster(certCollection,ontEndpoint) //todo only used by happy outside of here - lazy val ontologyMetadata: OntClientOntologyMetadata = { + lazy val ontologyMetadata: OntClientOntologyMetadataProvider = { import scala.concurrent.duration._ //TODO: XXX: Un-hard-code max wait time param val ontClient: OntClient = new PosterOntClient(shrineConfig.getConfigured("hiveCredentials", HiveCredentials(_, HiveCredentials.ONT)), 1.minute, ontPoster) new OntClientOntologyMetadata(ontClient) } protected lazy val happyResource: HappyShrineResource = new HappyShrineResource(HappyShrineService) protected lazy val statusJaxrs: StatusJaxrs = StatusJaxrs(config) protected lazy val shrineResource: Option[ShrineResource] = queryEntryPointComponents.map(x => ShrineResource(x.shrineService)) protected lazy val i2b2BroadcastResource: Option[I2b2BroadcastResource] = queryEntryPointComponents.map(x => new I2b2BroadcastResource(x.i2b2Service,breakdownTypes)) protected lazy val adapterResource: Option[AdapterResource] = adapterService.map(AdapterResource(_)) protected lazy val i2b2AdminResource: Option[I2b2AdminResource] = i2b2AdminService.map(I2b2AdminResource(_, breakdownTypes)) def poster(keystoreCertCollection: KeyStoreCertCollection)(endpoint: EndpointConfig): Poster = { val httpClient = JerseyHttpClient(keystoreCertCollection, endpoint) Poster(endpoint.url.toString, httpClient) } } diff --git a/apps/steward-app/src/test/resources/get-json-data.py b/apps/steward-app/src/test/resources/add_json_data.py similarity index 100% rename from apps/steward-app/src/test/resources/get-json-data.py rename to apps/steward-app/src/test/resources/add_json_data.py diff --git a/commons/ont-support/src/main/scala/net/shrine/ont/data/OntClientOntologyMetadata.scala b/commons/ont-support/src/main/scala/net/shrine/ont/data/OntClientOntologyMetadata.scala index 9ad0631b3..8ef86409b 100644 --- a/commons/ont-support/src/main/scala/net/shrine/ont/data/OntClientOntologyMetadata.scala +++ b/commons/ont-support/src/main/scala/net/shrine/ont/data/OntClientOntologyMetadata.scala @@ -1,29 +1,29 @@ package net.shrine.ont.data import net.shrine.client.OntClient /** * @author clint * @since Jan 28, 2014 */ final case class OntClientOntologyMetadata(client: OntClient) { def ontologyVersion: String = { import OntClientOntologyMetadata._ val versionTermOption = for { versionTerm <- client.childrenOf(versionContainerTerm).headOption lastPathPart <- dropTrailingSlash(versionTerm).split(backslashRegex).lastOption } yield lastPathPart versionTermOption.getOrElse("UNKNOWN") } } object OntClientOntologyMetadata { private val backslash = """\""" private val backslashRegex = """\\""" def dropTrailingSlash(s: String): String = if (s.endsWith(backslash)) s.dropRight(1) else s val versionContainerTerm = """\\SHRINE\SHRINE\ONTOLOGYVERSION""" -} +} \ No newline at end of file diff --git a/commons/util/src/main/scala/net/shrine/source/ConfigSource.scala b/commons/util/src/main/scala/net/shrine/source/ConfigSource.scala index b7a2b0c64..924961cff 100644 --- a/commons/util/src/main/scala/net/shrine/source/ConfigSource.scala +++ b/commons/util/src/main/scala/net/shrine/source/ConfigSource.scala @@ -1,37 +1,38 @@ package net.shrine.source import com.typesafe.config.{Config, ConfigFactory} /** * @author ty * @since 7/22/16 */ trait ConfigSource { val configName: String lazy val atomicConfig = new AtomicConfigSource(ConfigFactory.load(configName)) + atomicConfig.config.resolveWith() def config: Config = { atomicConfig.config } def configForBlock[T](key: String, value: AnyRef, origin: String)(block: => T): T = { atomicConfig.configForBlock(key, value, origin)(block) } def configForBlock[T](config:Config,origin:String)(block: => T):T = { atomicConfig.configForBlock(config,origin)(block) } def objectForName[T](objectName: String): T = { import scala.reflect.runtime.universe val runtimeMirror = universe.runtimeMirror(getClass.getClassLoader) val module = runtimeMirror.staticModule(objectName) val reflectedObj = runtimeMirror.reflectModule(module) val obj = reflectedObj.instance obj.asInstanceOf[T] } }