Skip to content

Commit

Permalink
#1906 terminate instead of stop
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 28, 2024
1 parent 65d4710 commit fedcf11
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
33 changes: 16 additions & 17 deletions src/main/java/com/rultor/agents/aws/DescribesInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,24 @@ public DescribesInstance(final AwsEc2 aws) {
@Override
public Iterable<Directive> process(final XML xml) throws IOException {
final String instance = xml.xpath("/talk/ec2/@id").get(0);
while (true) {
final DescribeInstanceStatusResult res = this.api.aws().describeInstanceStatus(
new DescribeInstanceStatusRequest()
.withIncludeAllInstances(true)
final DescribeInstanceStatusResult res = this.api.aws().describeInstanceStatus(
new DescribeInstanceStatusRequest()
.withIncludeAllInstances(true)
.withInstanceIds(instance)
);
final InstanceState state = res.getInstanceStatuses().get(0).getInstanceState();
Logger.info(this, "AWS instance %s state: %s", instance, state.getName());
final Directives dirs = new Directives();
if ("running".equals(state.getName())) {
final Instance ready = this.api.aws().describeInstances(
new DescribeInstancesRequest()
.withInstanceIds(instance)
);
final InstanceState state = res.getInstanceStatuses().get(0).getInstanceState();
Logger.info(this, "AWS instance %s state: %s", instance, state.getName());
if ("running".equals(state.getName())) {
break;
}
new Sleep(5L).now();
).getReservations().get(0).getInstances().get(0);
final String host = ready.getPublicIpAddress();
dirs.xpath("/talk/ec2").add("host").set(host);
Logger.info(this, "AWS instance %s is at %s", instance, host);
}
final Instance ready = this.api.aws().describeInstances(
new DescribeInstancesRequest()
.withInstanceIds(instance)
).getReservations().get(0).getInstances().get(0);
final String host = ready.getPublicIpAddress();
return new Directives().xpath("/talk/ec2").add("host").set(host);
return dirs;
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/rultor/agents/aws/StartsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public Iterable<Directive> process(final XML xml) throws IOException {
try {
final Instance instance = this.run(xml.xpath("/talk/@name").get(0));
Logger.info(
this, "EC2 instance %s on %s started in %s",
instance.getInstanceId(), instance.getPublicIpAddress(),
this, "EC2 instance %s started for %s",
instance.getInstanceId(),
xml.xpath("/talk/@name").get(0)
);
dirs.xpath("/talk")
Expand Down
28 changes: 12 additions & 16 deletions src/main/resources/com/rultor/spi/talk.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<xs:sequence>
<xs:element name="log" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation source="description">
This element has the log specification for the archive
task.
</xs:documentation>
<xs:documentation source="description">This element has the log specification for the archive task.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
Expand All @@ -314,32 +311,31 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</xs:complexType>
<xs:complexType name="ec2">
<xs:annotation>
<xs:documentation source="description">
This type describes the specification about the EC2.
</xs:documentation>
<xs:documentation source="description">This type describes the specification about the EC2.</xs:documentation>
</xs:annotation>
<xs:all>
<xs:element name="host" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation source="description">IP of the EC2 server.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
<xs:element name="talk">
<xs:annotation>
<xs:documentation source="description">
This element has the definition of the talk task.
</xs:documentation>
<xs:documentation source="description">This element has the definition of the talk task.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="daemon" type="daemon" minOccurs="0">
<xs:annotation>
<xs:documentation source="description">
This element has the daemon definition.
</xs:documentation>
<xs:documentation source="description">This element has the daemon definition.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="wire" type="wire" minOccurs="0">
<xs:annotation>
<xs:documentation source="description">
This element has the wire definition.
</xs:documentation>
<xs:documentation source="description">This element has the wire definition.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="shell" type="shell" minOccurs="0">
Expand Down

0 comments on commit fedcf11

Please sign in to comment.