Example usage for com.amazonaws.services.ecs.model Failure getArn

List of usage examples for com.amazonaws.services.ecs.model Failure getArn

Introduction

In this page you can find the example usage for com.amazonaws.services.ecs.model Failure getArn.

Prototype


public String getArn() 

Source Link

Document

The Amazon Resource Name (ARN) of the failed resource.

Usage

From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSService.java

License:Open Source License

String runEcsTask(final ECSSlave slave, final ECSTaskTemplate template, String clusterArn,
        Collection<String> command) throws IOException, AbortException {
    AmazonECSClient client = getAmazonECSClient();
    String definitionArn = template.getTaskDefinitionArn();
    slave.setTaskDefinitonArn(definitionArn);

    KeyValuePair envNodeName = new KeyValuePair();
    envNodeName.setName("SLAVE_NODE_NAME");
    envNodeName.setValue(slave.getComputer().getName());

    KeyValuePair envNodeSecret = new KeyValuePair();
    envNodeSecret.setName("SLAVE_NODE_SECRET");
    envNodeSecret.setValue(slave.getComputer().getJnlpMac());

    final RunTaskResult runTaskResult = client
            .runTask(new RunTaskRequest().withTaskDefinition(definitionArn)
                    .withOverrides(new TaskOverride().withContainerOverrides(new ContainerOverride()
                            .withName(template.getFullQualifiedTemplateName(slave.getCloud()))
                            .withCommand(command).withEnvironment(envNodeName).withEnvironment(envNodeSecret)))
                    .withCluster(clusterArn));

    if (!runTaskResult.getFailures().isEmpty()) {
        LOGGER.log(Level.WARNING, "Slave {0} - Failure to run task with definition {1} on ECS cluster {2}",
                new Object[] { slave.getNodeName(), definitionArn, clusterArn });
        for (Failure failure : runTaskResult.getFailures()) {
            LOGGER.log(Level.WARNING, "Slave {0} - Failure reason={1}, arn={2}",
                    new Object[] { slave.getNodeName(), failure.getReason(), failure.getArn() });
        }//from   w w w.  j av  a2  s.  com
        throw new AbortException("Failed to run slave container " + slave.getNodeName());
    }
    return runTaskResult.getTasks().get(0).getTaskArn();
}