private void cleanupArtifacts()

in aws-core-server/src/main/java/jetbrains/buildServer/clouds/amazon/ami/cleanup/EC2AmiCleanupExtension.java [102:130]


  private void cleanupArtifacts(@NotNull SFinishedBuild build,
                                @NotNull SBuildType buildType,
                                @NotNull String connectionId,
                                @NotNull List<AmiArtifact> artifacts,
                                @NotNull HashMap<String, Ec2Client> clientsCache,
                                @NotNull BuildCleanupContext cleanupContext) {
    final List<String> amiIds = artifacts.stream()
      .map(AmiArtifact::getAmiId)
      .collect(Collectors.toList());

    final Ec2Client client = getEC2Client(build, buildType.getProject(), connectionId, artifacts, cleanupContext, clientsCache);

    if (client != null) {
      List<Image> images = Collections.emptyList();
      try {
        images = client.describeImages(
            DescribeImagesRequest.builder()
              .imageIds(amiIds)
              .build())
          .images();
      } catch (SdkException e) {
        CLEANUP.warnAndDebugDetails(AMIS_INFO_ERROR, e);
        cleanupContext.onBuildCleanupError(this, build, AMIS_INFO_ERROR);
      }
      for (Image image : images) {
        cleanupImage(cleanupContext, build, client, image);
      }
    }
  }