Skip to content

Commit

Permalink
Fix docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
msosav committed Apr 10, 2024
1 parent 9a75f4f commit 8a18a82
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 177 deletions.
7 changes: 5 additions & 2 deletions Cliente/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ RUN pip install pipenv

RUN pipenv install --deploy --ignore-pipfile

ARG SERVER_URL
ENV SERVER_URL $SERVER_URL
ARG SERVER_IP
ENV SERVER_IP $SERVER_IP

ARG SERVER_PORT
ENV SERVER_PORT $SERVER_PORT
9 changes: 5 additions & 4 deletions Cliente/cliente.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

dotenv.load_dotenv()

SERVER_URL = os.getenv("SERVER_URL")
SERVER_IP = os.getenv("SERVER_IP")
SERVER_PORT = os.getenv("SERVER_PORT")


def list_files():
"""
Lista los archivos
return: None
"""
channel = grpc.insecure_channel(f"{SERVER_URL}:8080")
channel = grpc.insecure_channel(f"{SERVER_IP}:{SERVER_PORT}")
stub = Service_pb2_grpc.NameNodeStub(channel)
response = stub.ListFiles(Service_pb2.ListFilesRequest())
files = response.files
Expand Down Expand Up @@ -98,7 +99,7 @@ def upload_file(file_name, num_partitions, size):
param size: El tamaño del archivo
return: None
"""
channel = grpc.insecure_channel(f"{SERVER_URL}:8080")
channel = grpc.insecure_channel(f"{SERVER_IP}:{SERVER_PORT}")
stub = Service_pb2_grpc.NameNodeStub(channel)
response = stub.Create(
Service_pb2.CreateRequest(
Expand Down Expand Up @@ -140,7 +141,7 @@ def upload_file(file_name, num_partitions, size):


def download_file(file_name):
channel = grpc.insecure_channel(f"{SERVER_URL}:8080")
channel = grpc.insecure_channel(f"{SERVER_IP}:{SERVER_PORT}")
stub = Service_pb2_grpc.NameNodeStub(channel)
response = stub.Download(Service_pb2.DownloadRequest(file_name=file_name))
partitions = response.partitions
Expand Down
6 changes: 3 additions & 3 deletions DataNode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ RUN pip install pipenv

RUN pipenv install --deploy --ignore-pipfile

ARG SERVER_URL
ENV SERVER_URL $SERVER_URL
ARG SERVER_IP
ENV SERVER_IP $SERVER_IP

ARG SELF_IP
ENV SELF_IP $SELF_IP

EXPOSE 50051

CMD [ "pipenv", "run", "python", "namenode.py" ]
CMD [ "pipenv", "run", "python", "datanode.py" ]
12 changes: 6 additions & 6 deletions DataNode/datanode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

dotenv.load_dotenv()

SERVER_URL = os.getenv("SERVER_URL")
SERVER_IP = os.getenv("SERVER_IP")
SELF_IP = os.getenv("SELF_IP")


Expand All @@ -20,7 +20,7 @@ def get_replication_url(partition_name, file_name):
param partition_name: El nombre de la partición
return: None
"""
channel = grpc.insecure_channel(f"{SERVER_URL}:8080")
channel = grpc.insecure_channel(f"{SERVER_IP}:8080")
stub = Service_pb2_grpc.NameNodeStub(channel)
response = stub.ReplicationUrl(
Service_pb2.ReplicationUrlRequest(
Expand All @@ -43,7 +43,7 @@ def SendPartition(self, request, context):
storage_path = f"{file_name}/{partition_name}"
with open(storage_path, "wb") as f:
f.write(request.partition_data)
channel = grpc.insecure_channel(f"{SERVER_URL}:8080")
channel = grpc.insecure_channel(f"{SERVER_IP}:8080")
stub = Service_pb2_grpc.NameNodeStub(channel)
reponse = stub.SaveNodeFile(
Service_pb2.SaveNodeFileRequest(
Expand Down Expand Up @@ -100,7 +100,7 @@ def send_heartbeats():
while True:
timestamp = int(time.time())
try:
channel = grpc.insecure_channel(f"{SERVER_URL}:8080")
channel = grpc.insecure_channel(f"{SERVER_IP}:8080")
stub = Service_pb2_grpc.NameNodeStub(channel)
stub.HeartBeat(
Service_pb2.HeartBeatRequest(
Expand All @@ -117,7 +117,7 @@ def save_node_file(file_name):
param file_name: El nombre del archivo
return: None
"""
channel = grpc.insecure_channel(f"{SERVER_URL}:8080")
channel = grpc.insecure_channel(f"{SERVER_IP}:8080")
stub = Service_pb2_grpc.NameNodeStub(channel)
stub.SaveNodeFile(
Service_pb2.SaveNodeFileRequest(
Expand All @@ -128,7 +128,7 @@ def save_node_file(file_name):
if __name__ == "__main__":
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
Service_pb2_grpc.add_DataNodeServicer_to_server(DataNodeServicer(), server)
server.add_insecure_port(f"{SELF_IP}:50051")
server.add_insecure_port(f"[::]:50051")
server.start()
send_heartbeats_thread = Thread(target=send_heartbeats)
send_heartbeats_thread.daemon = True
Expand Down
1 change: 1 addition & 0 deletions NameNode/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]
grpcio = "*"
grpcio-tools = "*"
python-dotenv = "*"

[dev-packages]

Expand Down
Loading

0 comments on commit 8a18a82

Please sign in to comment.