Skip to content

Commit f4e2d73

Browse files
author
Nick Grippin
committed
switch to URL
1 parent 1f07b2c commit f4e2d73

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

Documents/panel.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@
44
The panel loader is designed to read a CSV file and load the data onto the HMDA-Platform. The CSV file should use the `|` (pipe) delimiter, and should include a header row as the first line.
55

66
## Environment Variables
7-
There are two environment variables used by the panel loader. Both must be set correctly in order for the data to be sent to the admin API.
7+
There is only one environment variable used by the panel loader. It must be set correctly in order for the data to be sent to the admin API.
88

9-
For testing locally, no changes need to be made. The defaults for both of these variables will point to the correct local admin API.
9+
For testing on an API running in SBT, no changes need to be made. The default for this variable will point to the correct local admin API.
1010

11-
For loading panel data into a remote system, you'll need to set the following environment variables:
11+
For loading panel data into a remote system or into a local Docker container, you'll need to set the following environment variable:
1212
```shell
13-
> export HMDA_HTTP_ADMIN_HOST={ip address}
14-
> export HMDA_HTTP_ADMIN_PORT={port #}
13+
> export HMDA_HTTP_ADMIN_URL={base URL}
14+
```
15+
16+
**IMPORTANT NOTE:** The base URL should *include* `http://` or `https://`, but *exclude* any trailing backslash `/`. For example:
17+
18+
```shell
19+
> export HMDA_HTTP_ADMIN_URL=http://192.168.99.100:8081
1520
```
1621

1722
## Running the parser
1823
A small example file is located at `panel/src/main/resources/inst_data_2017_dummy.csv`
1924

2025
The real panel file is located at `panel/src/main/resources/inst_data_2017.csv`
2126

22-
In order for the panel data to be loaded locally, the API project must be up and running, along with Docker containers running Cassandra and Zookeper. Otherwise, no other running services are needed (but make sure your environment variables are set). In a terminal, execute the following commands:
27+
In order for the panel data to be loaded locally, the API project must be up and running, along with Docker containers running Cassandra and Zookeper, or run the full `docker-compose` setup. To load panel data into the cluster, simply find the URL of the admin api (for the release branch: `https://hmda-ops-api.demo.cfpb.gov/admin`). No other running services are necessary.
28+
29+
In a terminal, execute the following commands:
2330

2431
```shell
2532
> sbt

panel/src/main/resources/application.conf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ akka {
44
}
55

66
hmda {
7-
adminHost = "0.0.0.0"
8-
adminHost = ${?HMDA_HTTP_ADMIN_HOST}
9-
adminPort = 80
10-
adminPort = ${?HMDA_HTTP_ADMIN_PORT}
7+
adminUrl = "http://0.0.0.0:8081"
8+
adminUrl = ${?HMDA_HTTP_ADMIN_URL}
119
}
1210

panel/src/main/scala/hmda/panel/PanelCsvLoader.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ object PanelCsvLoader extends WriteInstitutionProtocol {
2626
val log = LoggerFactory.getLogger("hmda")
2727

2828
val config = ConfigFactory.load()
29-
val host = config.getString("hmda.adminHost")
30-
val port = config.getInt("hmda.adminPort")
29+
val url = config.getString("hmda.adminUrl")
3130

3231
def main(args: Array[String]): Unit = {
3332

@@ -44,7 +43,6 @@ object PanelCsvLoader extends WriteInstitutionProtocol {
4443
val response = sendRequest("create")
4544

4645
val source = FileIO.fromPath(file.toPath)
47-
val connectionFlow = Http().outgoingConnection(host, port)
4846

4947
response.onComplete(s =>
5048
if (s.getOrElse("").equals("InstitutionSchemaCreated()")) {
@@ -54,7 +52,7 @@ object PanelCsvLoader extends WriteInstitutionProtocol {
5452
.drop(1)
5553
.via(byte2StringFlow)
5654
.via(stringToHttpFlow)
57-
.via(connectionFlow)
55+
.via(singleConnectionFlow)
5856
.runWith(Sink.foreach[HttpResponse](elem => log.info(elem.entity.toString)))
5957

6058
completedF.onComplete(result => {
@@ -72,16 +70,19 @@ object PanelCsvLoader extends WriteInstitutionProtocol {
7270

7371
private def singleConnectionFlow: Flow[HttpRequest, HttpResponse, NotUsed] =
7472
Flow[HttpRequest]
75-
.map(r => {
76-
Http().singleRequest(r).
77-
})
73+
.mapAsync[HttpResponse](5)(request => {
74+
for {
75+
response <- Http().singleRequest(request)
76+
} yield response
77+
})
7878

7979
private def stringToHttpFlow: Flow[String, HttpRequest, NotUsed] =
8080
Flow[String]
8181
.map(x => {
8282
val payload = ByteString(InstitutionParser(x).toJson.toString)
8383
HttpRequest(
8484
HttpMethods.POST,
85+
uri = s"$url/institutions",
8586
entity = HttpEntity(MediaTypes.`application/json`, payload)
8687
)
8788
})
@@ -90,7 +91,7 @@ object PanelCsvLoader extends WriteInstitutionProtocol {
9091
Flow[ByteString].map(bs => bs.utf8String)
9192

9293
private def sendRequest(req: String) = {
93-
val request = HttpRequest(HttpMethods.GET, uri = s"http://$host:$port/institutions/$req")
94+
val request = HttpRequest(HttpMethods.GET, uri = s"$url/institutions/$req")
9495
for {
9596
response <- Http().singleRequest(request)
9697
content <- Unmarshal(response.entity).to[String]

0 commit comments

Comments
 (0)