Skip to content

Commit

Permalink
#1906 /instance instead of /@id
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 28, 2024
1 parent fedcf11 commit 9741b9f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/rultor/agents/aws/ConnectsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ public final class ConnectsInstance extends AbstractAgent {
*/
public ConnectsInstance(final PfShell shll) {
super(
"/talk[daemon and ec2 and not(shell)]",
"/talk[daemon and not(shell)]",
"/talk/ec2/instance",
"/talk/ec2/host"
);
this.shell = shll;
}

@Override
public Iterable<Directive> process(final XML xml) throws IOException {
final String instance = xml.xpath("/talk/ec2/@id").get(0);
final String host = xml.xpath("/talk/ec2/host").get(0);
final String instance = xml.xpath("/talk/ec2/instance/text()").get(0);
final String host = xml.xpath("/talk/ec2/host/text()").get(0);
final Directives dirs = new Directives();
if (this.alive(host)) {
Logger.warn(
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/rultor/agents/aws/DescribesInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ public final class DescribesInstance extends AbstractAgent {
* @param aws API
*/
public DescribesInstance(final AwsEc2 aws) {
super("/talk[daemon and ec2 and not(ec2/host)]");
super(
"/talk[daemon and not(ec2/host)]",
"/talk/ec2/instance"
);
this.api = aws;
}

@Override
public Iterable<Directive> process(final XML xml) throws IOException {
final String instance = xml.xpath("/talk/ec2/@id").get(0);
final String instance = xml.xpath("/talk/ec2/instance/text()").get(0);
final DescribeInstanceStatusResult res = this.api.aws().describeInstanceStatus(
new DescribeInstanceStatusRequest()
.withIncludeAllInstances(true)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rultor/agents/aws/KillsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class KillsInstance extends AbstractAgent {
*/
public KillsInstance(final AwsEc2 aws, final long mins) {
super(
"/talk/ec2",
"/talk/ec2/instance",
"/talk/daemon[started and not(code) and not(ended)]",
"/talk/daemon/dir",
String.format(
Expand All @@ -74,7 +74,7 @@ public KillsInstance(final AwsEc2 aws, final long mins) {

@Override
public Iterable<Directive> process(final XML xml) throws IOException {
final String instance = xml.xpath("/talk/ec2/@id").get(0);
final String instance = xml.xpath("/talk/ec2/instance/text()").get(0);
this.api.aws().stopInstances(
new StopInstancesRequest()
.withInstanceIds(instance)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/aws/PingsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public PingsInstance() {
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public Iterable<Directive> process(final XML xml) throws IOException {
final Shell shell = new TalkShells(xml).get();
final String instance = xml.xpath("/talk/ec2/@id").get(0);
final String instance = xml.xpath("/talk/ec2/instance/text()").get(0);
final String host = xml.xpath("/talk/shell/host/text()").get(0);
final Directives dirs = new Directives();
int attempt = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/aws/StartsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Iterable<Directive> process(final XML xml) throws IOException {
);
dirs.xpath("/talk")
.add("ec2")
.attr("id", instance.getInstanceId());
.add("instance").set(instance.getInstanceId());
} catch (final Profile.ConfigException ex) {
dirs.xpath("/talk/daemon/script").set(
String.format(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rultor/agents/aws/TerminatesInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public final class TerminatesInstance extends AbstractAgent {
*/
public TerminatesInstance(final AwsEc2 api) {
super(
"/talk/ec2[@id and host]",
"/talk/ec2[instance and host]",
"/talk[not(daemon)]"
);
this.api = api;
}

@Override
public Iterable<Directive> process(final XML xml) throws IOException {
final String instance = xml.xpath("/talk/ec2/@id").get(0);
final String instance = xml.xpath("/talk/ec2/instance/text()").get(0);
this.api.aws().terminateInstances(
new TerminateInstancesRequest()
.withInstanceIds(instance)
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/com/rultor/spi/talk.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,17 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<xs:documentation source="description">This type describes the specification about the EC2.</xs:documentation>
</xs:annotation>
<xs:all>
<xs:element name="instance" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation source="description">Instance ID of the EC2 server.</xs:documentation>
</xs:annotation>
</xs:element>
<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>
Expand Down

0 comments on commit 9741b9f

Please sign in to comment.