tepechin_kirill_lab_2
This commit is contained in:
parent
bbeb924b57
commit
79c62bdf6a
100
tepechin_kirill_lab_2/README.md
Normal file
100
tepechin_kirill_lab_2/README.md
Normal file
@ -0,0 +1,100 @@
|
||||
## Лабораторная работа №1, ПИбд-42 Тепечин Кирилл, Вариант 26 (2, 2)
|
||||
|
||||
### Задание
|
||||
#### Задание для первого приложения
|
||||
Формирует файл /var/result/data.txt из первых строк всех файлов каталога /var/data
|
||||
#### Задание для второго приложения
|
||||
Ищет наименьшее число из файла /var/data/data.txt и сохраняет его третью степень в /var/result/result.txt.
|
||||
|
||||
### Содержимое файлов
|
||||
#### data/data.txt
|
||||
````
|
||||
13 50 5 3 33
|
||||
2 3 10 12
|
||||
````
|
||||
#### data/data2.txt
|
||||
````
|
||||
2 3 10 12
|
||||
13 50 5 3 33
|
||||
````
|
||||
### Dockerfile worker-1
|
||||
````dockerfile
|
||||
# Использование образа java
|
||||
FROM openjdk:17
|
||||
|
||||
# Создание директорий
|
||||
RUN mkdir /var/data
|
||||
RUN mkdir /var/result
|
||||
|
||||
# Рабочая директория
|
||||
WORKDIR /app
|
||||
|
||||
# Копирование исходных файлов
|
||||
COPY src /app/src
|
||||
|
||||
# Компиляция
|
||||
RUN javac /app/src/First.java
|
||||
|
||||
# Запуск
|
||||
CMD ["java", "-jar", "/app/src", "First"]
|
||||
````
|
||||
|
||||
### Dockerfile worker-2
|
||||
````dockerfile
|
||||
# Использование образа java
|
||||
FROM openjdk:17
|
||||
|
||||
# Создание директорий
|
||||
RUN mkdir /var/data
|
||||
RUN mkdir /var/result
|
||||
|
||||
# Рабочая директория
|
||||
WORKDIR /app
|
||||
|
||||
# Копирование исходных файлов
|
||||
COPY src /app/src
|
||||
|
||||
# Компиляция
|
||||
RUN javac /app/src/Second.java
|
||||
|
||||
# Запуск
|
||||
CMD ["java", "-jar", "/app/src", "Second"]
|
||||
````
|
||||
|
||||
### docker-compose файл
|
||||
````yaml
|
||||
services:
|
||||
worker-1:
|
||||
build:
|
||||
context: /worker-1
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data # Монтирование
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result
|
||||
worker-2:
|
||||
build:
|
||||
context: /worker-2
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result
|
||||
depends_on: #Зависимость сервисов
|
||||
- worker-1
|
||||
````
|
||||
### Результаты
|
||||
#### Результат выполнения worker-1
|
||||
````
|
||||
13 50 5 3 33
|
||||
2 3 10 12
|
||||
````
|
||||
Результат взят из файлов data.txt и data2.txt
|
||||
#### Результат выполнения worker-2
|
||||
````
|
||||
8
|
||||
````
|
||||
2^3=8
|
||||
### Ссылка на видео
|
||||
https://vk.com/video170089763_456239479?list=ln-gcpaumCqgqZ6urwCaD
|
||||
|
||||
|
||||
|
2
tepechin_kirill_lab_2/data/data.txt
Normal file
2
tepechin_kirill_lab_2/data/data.txt
Normal file
@ -0,0 +1,2 @@
|
||||
13 50 5 3 33
|
||||
2 3 10 12
|
2
tepechin_kirill_lab_2/data/data2.txt
Normal file
2
tepechin_kirill_lab_2/data/data2.txt
Normal file
@ -0,0 +1,2 @@
|
||||
2 3 10 12
|
||||
13 50 5 3 33
|
19
tepechin_kirill_lab_2/docker-compose.yml
Normal file
19
tepechin_kirill_lab_2/docker-compose.yml
Normal file
@ -0,0 +1,19 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
worker-1:
|
||||
build:
|
||||
context: /worker-1
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data # Монтирование
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result
|
||||
worker-2:
|
||||
build:
|
||||
context: /worker-2
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data
|
||||
- C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result
|
||||
depends_on: #Зависимость сервисов
|
||||
- worker-1
|
2
tepechin_kirill_lab_2/result/data.txt
Normal file
2
tepechin_kirill_lab_2/result/data.txt
Normal file
@ -0,0 +1,2 @@
|
||||
13 50 5 3 33
|
||||
2 3 10 12
|
1
tepechin_kirill_lab_2/result/result.txt
Normal file
1
tepechin_kirill_lab_2/result/result.txt
Normal file
@ -0,0 +1 @@
|
||||
8
|
13
tepechin_kirill_lab_2/worker-1/Dockerfile
Normal file
13
tepechin_kirill_lab_2/worker-1/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
# Использование образа java
|
||||
FROM openjdk:17
|
||||
# Создание директорий
|
||||
RUN mkdir /var/data
|
||||
RUN mkdir /var/result
|
||||
# Рабочая директория
|
||||
WORKDIR /app
|
||||
# Копирование исходных файлов
|
||||
COPY src /app/src
|
||||
# Компиляция
|
||||
RUN javac /app/src/First.java
|
||||
# Запуск
|
||||
CMD ["java", "-jar", "/app/src", "First"]
|
35
tepechin_kirill_lab_2/worker-1/src/First.java
Normal file
35
tepechin_kirill_lab_2/worker-1/src/First.java
Normal file
@ -0,0 +1,35 @@
|
||||
import java.io.*;
|
||||
|
||||
public class First {
|
||||
public static void main(String[] args) {
|
||||
String dataDirectoryPath = "/var/data";
|
||||
|
||||
String resultFilePath = "/var/result/data.txt";
|
||||
|
||||
try {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath));
|
||||
|
||||
File dataDirectory = new File(dataDirectoryPath);
|
||||
File[] files = dataDirectory.listFiles();
|
||||
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String line = reader.readLine();
|
||||
|
||||
if (line != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
writer.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
13
tepechin_kirill_lab_2/worker-2/Dockerfile
Normal file
13
tepechin_kirill_lab_2/worker-2/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
# Использование образа java
|
||||
FROM openjdk:17
|
||||
# Создание директорий
|
||||
RUN mkdir /var/data
|
||||
RUN mkdir /var/result
|
||||
# Рабочая директория
|
||||
WORKDIR /app
|
||||
# Копирование исходных файлов
|
||||
COPY src /app/src
|
||||
# Компиляция
|
||||
RUN javac /app/src/Second.java
|
||||
# Запуск
|
||||
CMD ["java", "-jar", "/app/src", "Second"]
|
39
tepechin_kirill_lab_2/worker-2/src/Second.java
Normal file
39
tepechin_kirill_lab_2/worker-2/src/Second.java
Normal file
@ -0,0 +1,39 @@
|
||||
import java.io.*;
|
||||
|
||||
public class Second {
|
||||
public static void main(String[] args) {
|
||||
String dataFilePath = "/var/data/data.txt";
|
||||
String resultFilePath = "/var/result/result.txt";
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(dataFilePath));
|
||||
String line;
|
||||
int minNumber = Integer.MAX_VALUE;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] strNums = line.split(" ");
|
||||
for (var strNum: strNums) {
|
||||
int number = Integer.parseInt(strNum);
|
||||
|
||||
if (number < minNumber) {
|
||||
minNumber = number;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
int result = (int) Math.pow(minNumber, 3);
|
||||
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath));
|
||||
writer.write(String.valueOf(result));
|
||||
writer.newLine();
|
||||
writer.close();
|
||||
|
||||
System.out.println(result);
|
||||
} catch (IOException | NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user