Skip to content

Commit

Permalink
feat: 1. make blocking call to non blocking call so that now it works…
Browse files Browse the repository at this point in the history
… porperly 2. lint
  • Loading branch information
leejiwon1125 committed Nov 22, 2023
1 parent b5db92a commit 5e04944
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
5 changes: 0 additions & 5 deletions master/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ package kr.ac.postech.paranode.master
import kr.ac.postech.paranode.core.WorkerMetadata
import kr.ac.postech.paranode.rpc.MasterServer

import java.nio.file.Files
import java.nio.file.Paths
import java.net._

import java.net.URL
import scala.io.Source
import scala.util.Try

object Main {
Expand Down
10 changes: 5 additions & 5 deletions rpc/src/main/scala/MasterClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import java.util.concurrent.TimeUnit
import java.util.logging.Logger

import common.Node
import master.MasterGrpc.MasterBlockingStub
import master.MasterGrpc.MasterStub
import master.{MasterGrpc, RegisterRequest}

object MasterClient {
def apply(host: String, port: Int): MasterClient = {
val channel =
ManagedChannelBuilder.forAddress(host, port).usePlaintext().build
val blockingStub = MasterGrpc.blockingStub(channel)
new MasterClient(channel, blockingStub)
val stub = MasterGrpc.stub(channel)
new MasterClient(channel, stub)
}

def main(args: Array[String]): Unit = {
Expand All @@ -33,7 +33,7 @@ object MasterClient {

class MasterClient private (
private val channel: ManagedChannel,
private val blockingStub: MasterBlockingStub
private val stub: MasterStub
) {
Logger.getLogger(classOf[MasterClient].getName)

Expand All @@ -49,6 +49,6 @@ class MasterClient private (
Some(Node(workerMetadata.host, workerMetadata.port))
)

blockingStub.register(request)
stub.register(request)
}
}
16 changes: 7 additions & 9 deletions rpc/src/main/scala/MasterServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ package kr.ac.postech.paranode.rpc

import io.grpc.Server
import io.grpc.ServerBuilder
import kr.ac.postech.paranode.core.WorkerMetadata
import kr.ac.postech.paranode.rpc.MasterServer.port

import java.io.File
import java.io.PrintWriter
import java.nio.file.Files
import java.nio.file.Paths
import java.util.logging.Logger
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.WrappedArray
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.concurrent.Promise
import master.{MasterGrpc, RegisterReply, RegisterRequest}

import scala.collection.mutable.{ListBuffer, WrappedArray}
import kr.ac.postech.paranode.core.WorkerMetadata
import master.{MasterGrpc, RegisterReply, RegisterRequest}

object MasterServer {
private val logger = Logger.getLogger(classOf[MasterServer].getName)
Expand All @@ -35,7 +32,7 @@ class MasterServer(executionContext: ExecutionContext) { self =>
.addService(MasterGrpc.bindService(new MasterImpl, executionContext))
.build()

private val workerDetails:ListBuffer[WorkerMetadata] = ListBuffer()
private val workerDetails: ListBuffer[WorkerMetadata] = ListBuffer()

def addWorkerInfo(workerMetadata: WorkerMetadata): Unit = synchronized {
workerDetails += workerMetadata
Expand Down Expand Up @@ -81,7 +78,8 @@ class MasterServer(executionContext: ExecutionContext) { self =>
val promise = Promise[RegisterReply]

Future {
val workerMetadata = WorkerMetadata(request.worker.get.host, request.worker.get.port, None)
val workerMetadata =
WorkerMetadata(request.worker.get.host, request.worker.get.port, None)
addWorkerInfo(workerMetadata)
}(executionContext)

Expand Down
6 changes: 1 addition & 5 deletions worker/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package kr.ac.postech.paranode.worker
import kr.ac.postech.paranode.core.WorkerMetadata
import kr.ac.postech.paranode.rpc.MasterClient

import java.net.{InetAddress, URL}
import scala.io.Source
import java.net.InetAddress
import scala.util.Try

object Main {
Expand Down Expand Up @@ -35,12 +34,9 @@ object Main {
val client = MasterClient(ip, port)
try {
val publicIpAddress = InetAddress.getLocalHost.getHostAddress

val workerMetadata = WorkerMetadata(publicIpAddress, -1, None)
client.register(workerMetadata)

// doesn't come here. I think its because we use blockingStub.

} finally {
client.shutdown()
}
Expand Down

0 comments on commit 5e04944

Please sign in to comment.