-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloudApp.java
More file actions
114 lines (96 loc) · 2.82 KB
/
CloudApp.java
File metadata and controls
114 lines (96 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package Architecture;
// Абстрактные сервисы
interface ComputeInstance {
void start();
}
interface BlobStorage {
void save(String name);
}
// Абстрактная фабрика
interface CloudFactory {
ComputeInstance createCompute();
BlobStorage createStorage();
}
// Конкретные реализации для AWS
class AwsCompute implements ComputeInstance {
@Override
public void start() {
System.out.println("Запущен AWS EC2 инстанс");
}
}
class AwsBlobStorage implements BlobStorage {
@Override
public void save(String name) {
System.out.println("Файл сохранен в AWS S3: " + name);
}
}
class AwsFactory implements CloudFactory {
@Override
public ComputeInstance createCompute() {
return new AwsCompute();
}
@Override
public BlobStorage createStorage() {
return new AwsBlobStorage();
}
}
// Конкретные реализации для Azure
class AzureCompute implements ComputeInstance {
@Override
public void start() {
System.out.println("Запущен Azure VM инстанс");
}
}
class AzureBlobStorage implements BlobStorage {
@Override
public void save(String name) {
System.out.println("Файл сохранен в Azure Storage: " + name);
}
}
class AzureFactory implements CloudFactory {
@Override
public ComputeInstance createCompute() {
return new AzureCompute();
}
@Override
public BlobStorage createStorage() {
return new AzureBlobStorage();
}
}
// Класс-клиент
class DeploymentManager {
private ComputeInstance compute;
private BlobStorage storage;
public DeploymentManager(CloudFactory factory) {
this.compute = factory.createCompute();
this.storage = factory.createStorage();
}
public void deploy() {
compute.start();
storage.save("deployment.log");
}
}
// Точка входа
public class CloudApp {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Укажите провайдера: aws или azure");
return;
}
CloudFactory factory;
String provider = args[0].toLowerCase();
switch (provider) {
case "aws":
factory = new AwsFactory();
break;
case "azure":
factory = new AzureFactory();
break;
default:
System.out.println("Неизвестный провайдер");
return;
}
DeploymentManager manager = new DeploymentManager(factory);
manager.deploy();
}
}