Skip to content

Commit

Permalink
#1877 wait for running state
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 27, 2024
1 parent 24d2c4f commit 039841c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
33 changes: 18 additions & 15 deletions src/main/java/com/rultor/agents/Agents.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,25 @@ public Agent agent(final Talk talk, final Profile profile)
),
new StartsRequest(profile),
new Agent.Quiet(
new StartsInstance(
new AwsEc2(
Manifests.read("Rultor-EC2Key"),
Manifests.read("Rultor-EC2Secret")
),
new PfShell(
profile,
"none",
Agents.PORT,
"ubuntu",
Agents.priv()
new Agent.Disabled(
new StartsInstance(
new AwsEc2(
Manifests.read("Rultor-EC2Key"),
Manifests.read("Rultor-EC2Secret")
),
new PfShell(
profile,
"none",
Agents.PORT,
"ubuntu",
Agents.priv()
),
Manifests.read("Rultor-EC2Image"),
Manifests.read("Rultor-EC2Type"),
Manifests.read("Rultor-EC2Group"),
Manifests.read("Rultor-EC2Subnet")
),
Manifests.read("Rultor-EC2Image"),
Manifests.read("Rultor-EC2Type"),
Manifests.read("Rultor-EC2Group"),
Manifests.read("Rultor-EC2Subnet")
false
)
),
new RegistersShell(
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/com/rultor/agents/aws/StartsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
package com.rultor.agents.aws;

import com.amazonaws.services.ec2.model.CreateTagsRequest;
import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest;
import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.InstanceState;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
import com.amazonaws.services.ec2.model.RunInstancesResult;
import com.amazonaws.services.ec2.model.Tag;
Expand Down Expand Up @@ -167,14 +170,23 @@ private Instance run() {
final RunInstancesResult response =
this.api.aws().runInstances(request);
final Instance instance = response.getReservation().getInstances().get(0);
final Tag awstag = new Tag()
.withKey("name")
.withValue("rultor");
final CreateTagsRequest req = new CreateTagsRequest()
.withResources(instance.getInstanceId())
.withTags(awstag);
this.api.aws().createTags(req);
Logger.info(this, "AWS instance %s launched", instance.getInstanceId());
final String iid = instance.getInstanceId();
this.api.aws().createTags(
new CreateTagsRequest()
.withResources(iid)
.withTags(new Tag().withKey("name").withValue("rultor"))
);
while (true) {
final DescribeInstanceStatusResult res = this.api.aws().describeInstanceStatus(
new DescribeInstanceStatusRequest().withInstanceIds(iid)
);
final InstanceState state = res.getInstanceStatuses().get(0).getInstanceState();
Logger.info(this, "AWS instance %s state: %s", state.getName());
if ("running".equals(state.getName())) {
break;
}
}
Logger.info(this, "AWS instance %s launched and running", iid);
return instance;
}
}

0 comments on commit 039841c

Please sign in to comment.