podkorytova_yulia_lab_2 is ready
This commit is contained in:
parent
f2adafe2e1
commit
6ddd513f75
8
podkorytova_yulia_lab_2/data/file1.txt
Normal file
8
podkorytova_yulia_lab_2/data/file1.txt
Normal file
@ -0,0 +1,8 @@
|
||||
84
|
||||
6
|
||||
56
|
||||
4
|
||||
32
|
||||
47
|
||||
4
|
||||
62
|
6
podkorytova_yulia_lab_2/data/file_two.txt
Normal file
6
podkorytova_yulia_lab_2/data/file_two.txt
Normal file
@ -0,0 +1,6 @@
|
||||
1
|
||||
65
|
||||
93
|
||||
91
|
||||
20
|
||||
62
|
6
podkorytova_yulia_lab_2/data/file_with_numbers.txt
Normal file
6
podkorytova_yulia_lab_2/data/file_with_numbers.txt
Normal file
@ -0,0 +1,6 @@
|
||||
43
|
||||
60
|
||||
31
|
||||
13
|
||||
2
|
||||
87
|
20
podkorytova_yulia_lab_2/docker-compose.yml
Normal file
20
podkorytova_yulia_lab_2/docker-compose.yml
Normal file
@ -0,0 +1,20 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
worker-1: # название 1 сервиса
|
||||
build: # директива build для сборки образа
|
||||
context: /worker-1
|
||||
dockerfile: Dockerfile
|
||||
volumes: # монтирование папок
|
||||
- .\data:/var/data
|
||||
- .\result:/var/result
|
||||
|
||||
worker-2: # название 2 сервиса
|
||||
build: # директива build для сборки образа
|
||||
context: /worker-2
|
||||
dockerfile: Dockerfile
|
||||
depends_on: # зависимость сервисов
|
||||
- worker-1
|
||||
volumes: # монтирование папок
|
||||
- .\data:/var/data
|
||||
- .\result:/var/result
|
BIN
podkorytova_yulia_lab_2/images/console.JPG
Normal file
BIN
podkorytova_yulia_lab_2/images/console.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 103 KiB |
BIN
podkorytova_yulia_lab_2/images/dockerhub.JPG
Normal file
BIN
podkorytova_yulia_lab_2/images/dockerhub.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 79 KiB |
BIN
podkorytova_yulia_lab_2/images/files.JPG
Normal file
BIN
podkorytova_yulia_lab_2/images/files.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 82 KiB |
BIN
podkorytova_yulia_lab_2/images/files_res.JPG
Normal file
BIN
podkorytova_yulia_lab_2/images/files_res.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
BIN
podkorytova_yulia_lab_2/images/result.JPG
Normal file
BIN
podkorytova_yulia_lab_2/images/result.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
18
podkorytova_yulia_lab_2/worker-1/Dockerfile
Normal file
18
podkorytova_yulia_lab_2/worker-1/Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
# использование образа java
|
||||
FROM openjdk:17
|
||||
|
||||
# создание директорий для файлов
|
||||
RUN mkdir /var/data
|
||||
RUN mkdir /var/result
|
||||
|
||||
# установка рабочей директории проекта
|
||||
WORKDIR /app
|
||||
|
||||
# копирование исходных файлов
|
||||
COPY src /app/src
|
||||
|
||||
# компиляция
|
||||
RUN javac /app/src/App1.java
|
||||
|
||||
# запуск java-приложения
|
||||
CMD ["java", "-cp", "/app/src", "App1"]
|
32
podkorytova_yulia_lab_2/worker-1/src/App1.java
Normal file
32
podkorytova_yulia_lab_2/worker-1/src/App1.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
public class App1 {
|
||||
public static void main(String[] args) {
|
||||
File dataDirectory = new File("/var/data");
|
||||
File[] files = dataDirectory.listFiles();
|
||||
|
||||
if (files.length > 0) {
|
||||
File shortestFileName = files[0];
|
||||
for (File file : files) {
|
||||
if (file.getName().length() < shortestFileName.getName().length()) {
|
||||
shortestFileName = file;
|
||||
}
|
||||
}
|
||||
|
||||
Path sourcePath = shortestFileName.toPath();
|
||||
Path destinationPath = new File("/var/result/data.txt").toPath();
|
||||
try {
|
||||
Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
System.out.println("Файл успешно перемещен.");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Ошибка при перемещении файла: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
System.out.println("Каталог /var/data пустой.");
|
||||
}
|
||||
}
|
||||
}
|
18
podkorytova_yulia_lab_2/worker-2/Dockerfile
Normal file
18
podkorytova_yulia_lab_2/worker-2/Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
# использование образа java
|
||||
FROM openjdk:17
|
||||
|
||||
# создание директорий для файлов
|
||||
RUN mkdir /var/data
|
||||
RUN mkdir /var/result
|
||||
|
||||
# установка рабочей директории проекта
|
||||
WORKDIR /app
|
||||
|
||||
# копирование исходных файлов
|
||||
COPY src /app/src
|
||||
|
||||
# компиляция
|
||||
RUN javac /app/src/App2.java
|
||||
|
||||
# запуск java-приложения
|
||||
CMD ["java", "-cp", "/app/src", "App2"]
|
34
podkorytova_yulia_lab_2/worker-2/src/App2.java
Normal file
34
podkorytova_yulia_lab_2/worker-2/src/App2.java
Normal file
@ -0,0 +1,34 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class App2 {
|
||||
public static void main(String[] args) {
|
||||
String inputFile = "/var/result/data.txt";
|
||||
String outputFile = "/var/result/result.txt";
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
FileWriter writer = new FileWriter(outputFile)) {
|
||||
|
||||
String line;
|
||||
int smallestNumber = Integer.MAX_VALUE;
|
||||
int count = 0;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
int number = Integer.parseInt(line);
|
||||
if (number < smallestNumber) {
|
||||
smallestNumber = number;
|
||||
count = 1;
|
||||
} else if (number == smallestNumber) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
writer.write(String.valueOf(count));
|
||||
System.out.println("Количество чисел, равных наименьшему значению: " + count);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Ошибка при обработке файла: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user