Skip to content

Commit 2d0ce12

Browse files
committed
#1877 with security group
1 parent 0f8fee7 commit 2d0ce12

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

src/main/java/com/rultor/agents/Agents.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ public Agent agent(final Talk talk, final Profile profile)
271271
Manifests.read("Rultor-EC2Secret")
272272
),
273273
Manifests.read("Rultor-EC2Image"),
274-
Manifests.read("Rultor-EC2Type")
274+
Manifests.read("Rultor-EC2Type"),
275+
Manifests.read("Rultor-EC2Group")
275276
),
276277
profile,
277278
Agents.PORT,

src/main/java/com/rultor/agents/aws/AwsEc2Image.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,39 @@ public final class AwsEc2Image {
6161
private final transient InstanceType type;
6262

6363
/**
64-
* Ctor.
65-
* @param api AwsEc2 api client
66-
* @param image Ec2 instance ami_id
64+
* EC2 security group.
6765
*/
68-
public AwsEc2Image(final AwsEc2 api, final String image) {
69-
this(api, image, "t2.nano");
70-
}
66+
private final String sgroup;
7167

7268
/**
7369
* Ctor.
7470
* @param api AwsEc2 api client
7571
* @param image Ec2 instance ami_id
7672
* @param type Instance type
73+
* @param grp Security group
74+
* @checkstyle ParameterNumberCheck (5 lines)
7775
*/
7876
public AwsEc2Image(final AwsEc2 api, final String image,
79-
final String type) {
77+
final String type, final String grp) {
78+
this.api = api;
8079
if (image.isEmpty()) {
8180
throw new IllegalArgumentException(
8281
"Machine image id is mandatory"
8382
);
8483
}
84+
this.image = image;
8585
if (type.isEmpty()) {
8686
throw new IllegalArgumentException(
8787
"Machine type is mandatory"
8888
);
8989
}
90-
this.api = api;
91-
this.image = image;
9290
this.type = InstanceType.fromValue(type);
91+
if (grp.isEmpty()) {
92+
throw new IllegalArgumentException(
93+
"Security group is mandatory"
94+
);
95+
}
96+
this.sgroup = grp;
9397
}
9498

9599
/**
@@ -98,6 +102,7 @@ public AwsEc2Image(final AwsEc2 api, final String image,
98102
*/
99103
public AwsEc2Instance run() {
100104
final RunInstancesRequest request = new RunInstancesRequest()
105+
.withSecurityGroups(this.sgroup)
101106
.withImageId(this.image)
102107
.withInstanceType(this.type)
103108
.withMaxCount(1)

src/main/java/com/rultor/agents/aws/AwsEc2Instance.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void stop() {
122122
final StopInstancesRequest request = new StopInstancesRequest()
123123
.withInstanceIds(this.id);
124124
client.stopInstances(request);
125-
Logger.info("Successfully stop instance %s", this.id);
125+
Logger.info("Successfully stopped instance %s", this.id);
126126
}
127127

128128
/**

src/main/java/com/rultor/spi/Agent.java

+45
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,49 @@ public void execute(final Talk talk) throws IOException {
133133
}
134134
}
135135
}
136+
137+
/**
138+
* Swallows all exceptions.
139+
*
140+
* @since 1.0
141+
*/
142+
@Immutable
143+
@ToString
144+
@EqualsAndHashCode(of = "agent")
145+
final class Quiet implements Agent {
146+
/**
147+
* Agent to disable.
148+
*/
149+
private final transient Agent agent;
150+
151+
/**
152+
* Disable it?
153+
*/
154+
private final transient boolean disable;
155+
156+
/**
157+
* Ctor.
158+
* @param agt Agent
159+
*/
160+
public Disabled(final Agent agt) {
161+
this(agt, true);
162+
}
163+
164+
/**
165+
* Ctor.
166+
* @param agt Agent
167+
* @param dsbl Disable it?
168+
*/
169+
public Disabled(final Agent agt, final boolean dsbl) {
170+
this.agent = agt;
171+
this.disable = dsbl;
172+
}
173+
174+
@Override
175+
public void execute(final Talk talk) throws IOException {
176+
if (!this.disable) {
177+
this.agent.execute(talk);
178+
}
179+
}
180+
}
136181
}

src/main/resources/META-INF/MANIFEST.MF

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Rultor-EC2Key: ${ec2.key}
1616
Rultor-EC2Secret: ${ec2.secret}
1717
Rultor-EC2Image: ${ec2.image}
1818
Rultor-EC2Type: ${ec2.type}
19+
Rultor-EC2Group: ${ec2.group}
1920
Rultor-TwitterKey: ${twitter.key}
2021
Rultor-TwitterSecret: ${twitter.secret}
2122
Rultor-TwitterToken: ${twitter.token}

src/test/resources/META-INF/MANIFEST.MF

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ Rultor-EC2Key: none
1919
Rultor-EC2Secret: none
2020
Rultor-EC2Image: none
2121
Rultor-EC2Type: t3.large
22+
Rultor-EC2Group: none
23+

0 commit comments

Comments
 (0)