-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e65a0b7
commit c47c7ed
Showing
24 changed files
with
727 additions
and
332 deletions.
There are no files selected for viewing
204 changes: 171 additions & 33 deletions
204
neo4j-store/src/main/kotlin/org/ostelco/prime/storage/graph/Neo4jStore.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...j-store/src/test/resources/META-INF/services/org.ostelco.prime.analytics.AnalyticsService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.ostelco.prime.storage.graph.MockAnalyticsService |
1 change: 0 additions & 1 deletion
1
neo4j-store/src/test/resources/META-INF/services/org.ostelco.prime.ocs.OcsAdminService
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
.../src/test/resources/META-INF/services/org.ostelco.prime.paymentprocessor.PaymentProcessor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.ostelco.prime.storage.graph.MockPaymentProcessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id "org.jetbrains.kotlin.jvm" version "1.3.10" | ||
id "java-library" | ||
} | ||
|
||
dependencies { | ||
implementation project(':prime-modules') | ||
|
||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinXCoroutinesVersion" | ||
|
||
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion" | ||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" | ||
testImplementation "org.mockito:mockito-core:$mockitoVersion" | ||
} | ||
|
||
apply from: '../gradle/jacoco.gradle' |
34 changes: 34 additions & 0 deletions
34
ocs-ktc/src/main/kotlin/org/ostelco/prime/ocs/OcsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.ostelco.prime.ocs | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonTypeName | ||
import io.dropwizard.setup.Environment | ||
import org.hibernate.validator.constraints.NotEmpty | ||
import org.ostelco.prime.module.PrimeModule | ||
import org.ostelco.prime.ocs.consumption.OcsGrpcServer | ||
import org.ostelco.prime.ocs.consumption.OcsGrpcService | ||
import org.ostelco.prime.ocs.core.OnlineCharging | ||
|
||
@JsonTypeName("ocs") | ||
class OcsModule : PrimeModule { | ||
|
||
@JsonProperty | ||
fun setConfig(config: Config) { | ||
ConfigRegistry.config = config | ||
} | ||
|
||
override fun init(env: Environment) { | ||
env.lifecycle().manage( | ||
OcsGrpcServer(8082, OcsGrpcService(OnlineCharging))) | ||
} | ||
} | ||
|
||
class Config { | ||
@NotEmpty | ||
@JsonProperty("lowBalanceThreshold") | ||
var lowBalanceThreshold: Long = 0 | ||
} | ||
|
||
object ConfigRegistry { | ||
lateinit var config: Config | ||
} |
29 changes: 29 additions & 0 deletions
29
ocs-ktc/src/main/kotlin/org/ostelco/prime/ocs/analytics/AnalyticsReporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.ostelco.prime.ocs.analytics | ||
|
||
import org.ostelco.ocs.api.CreditControlRequestInfo | ||
import org.ostelco.prime.analytics.AnalyticsService | ||
import org.ostelco.prime.getLogger | ||
import org.ostelco.prime.module.getResource | ||
|
||
/** | ||
* This class publishes the data consumption information events analytics. | ||
*/ | ||
object AnalyticsReporter { | ||
|
||
private val logger by getLogger() | ||
|
||
private val analyticsReporter by lazy { getResource<AnalyticsService>() } | ||
|
||
fun report(request: CreditControlRequestInfo, bundleBytes: Long) { | ||
val msisdn = request.msisdn | ||
if (msisdn != null) { | ||
logger.info("Sent Data Consumption info event to analytics") | ||
analyticsReporter.reportTrafficInfo( | ||
msisdn = msisdn, | ||
usedBytes = request.msccList?.firstOrNull()?.used?.totalOctets ?: 0L, | ||
bundleBytes = bundleBytes, | ||
apn = request.serviceInformation?.psInformation?.calledStationId, | ||
mccMnc = request.serviceInformation?.psInformation?.sgsnMccMnc) | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
ocs-ktc/src/main/kotlin/org/ostelco/prime/ocs/consumption/Interfaces.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.ostelco.prime.ocs.consumption | ||
|
||
import io.grpc.stub.StreamObserver | ||
import org.ostelco.ocs.api.ActivateResponse | ||
import org.ostelco.ocs.api.CreditControlAnswerInfo | ||
import org.ostelco.ocs.api.CreditControlRequestInfo | ||
|
||
/** | ||
* Ocs Requests from [OcsGrpcService] are consumed by implementation [OcsService] of [OcsAsyncRequestConsumer] | ||
*/ | ||
interface OcsAsyncRequestConsumer { | ||
fun putCreditControlClient(streamId: String, creditControlAnswer: StreamObserver<CreditControlAnswerInfo>) | ||
fun creditControlRequestEvent(streamId: String, request: CreditControlRequestInfo) | ||
fun deleteCreditControlClient(streamId: String) | ||
fun updateActivateResponse(streamId: String, activateResponse: StreamObserver<ActivateResponse>) | ||
} | ||
|
||
/** | ||
* Ocs Events from [OcsEventToGrpcResponseMapper] forwarded to implementation [OcsService] of [OcsAsyncResponseProducer] | ||
*/ | ||
interface OcsAsyncResponseProducer { | ||
fun activateOnNextResponse(response: ActivateResponse) | ||
fun sendCreditControlAnswer(streamId: String, creditControlAnswer: CreditControlAnswerInfo) | ||
fun returnUnusedDataBucketEvent(msisdn: String, reservedBucketBytes: Long) | ||
} |
43 changes: 43 additions & 0 deletions
43
ocs-ktc/src/main/kotlin/org/ostelco/prime/ocs/consumption/OcsGrpcServer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.ostelco.prime.ocs.consumption | ||
|
||
import io.dropwizard.lifecycle.Managed | ||
import io.grpc.BindableService | ||
import io.grpc.Server | ||
import io.grpc.ServerBuilder | ||
import org.ostelco.prime.getLogger | ||
|
||
/** | ||
* This is OCS Server running on gRPC protocol. | ||
* Its startup and shutdown are managed by Dropwizard's lifecycle | ||
* through the Managed interface. | ||
* | ||
*/ | ||
class OcsGrpcServer(private val port: Int, service: BindableService) : Managed { | ||
|
||
private val logger by getLogger() | ||
|
||
// may add Transport Security with Certificates if needed. | ||
// may add executor for control over number of threads | ||
private val server: Server = ServerBuilder.forPort(port).addService(service).build() | ||
|
||
override fun start() { | ||
server.start() | ||
logger.info("OcsServer Server started, listening for incoming gRPC traffic on {}", port) | ||
} | ||
|
||
override fun stop() { | ||
logger.info("Stopping OcsServer Server listening for gRPC traffic on {}", port) | ||
server.shutdown() | ||
blockUntilShutdown() | ||
} | ||
|
||
// Used for unit testing | ||
fun forceStop() { | ||
logger.info("Stopping forcefully OcsServer Server listening for gRPC traffic on {}", port) | ||
server.shutdownNow() | ||
} | ||
|
||
private fun blockUntilShutdown() { | ||
server.awaitTermination() | ||
} | ||
} |
Oops, something went wrong.