private void markResource(Resource resource, DateTime now) {
   if (resource.getExpectedTerminationTime() == null) {
     Date terminationTime = calendar.getBusinessDay(new Date(now.getMillis()), retentionDays);
     resource.setExpectedTerminationTime(terminationTime);
     resource.setTerminationReason(
         String.format(
             "Launch config older than %d days. Not in Discovery. No ELB.",
             launchConfigAgeThreshold + retentionDays));
   } else {
     LOGGER.info(
         String.format("Resource %s is already marked as cleanup candidate.", resource.getId()));
   }
 }
  /** {@inheritDoc} */
  @Override
  public boolean isValid(Resource resource) {
    Validate.notNull(resource);
    if (!"ASG".equals(resource.getResourceType().name())) {
      return true;
    }

    if (StringUtils.isNotEmpty(resource.getAdditionalField(ASGJanitorCrawler.ASG_FIELD_ELBS))) {
      LOGGER.info(String.format("ASG %s has ELBs.", resource.getId()));
      return true;
    }

    if (instanceValidator.hasActiveInstance(resource)) {
      LOGGER.info(String.format("ASG %s has active instance.", resource.getId()));
      return true;
    }

    String lcName = resource.getAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_NAME);
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    if (StringUtils.isEmpty(lcName)) {
      LOGGER.error(
          String.format("Failed to find launch configuration for ASG %s", resource.getId()));
      markResource(resource, now);
      return false;
    }

    String lcCreationTime =
        resource.getAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_CREATION_TIME);
    if (StringUtils.isEmpty(lcCreationTime)) {
      LOGGER.error(
          String.format("Failed to find creation time for launch configuration %s", lcName));
      return true;
    }

    DateTime createTime = new DateTime(Long.parseLong(lcCreationTime));
    if (now.isBefore(createTime.plusDays(launchConfigAgeThreshold))) {
      LOGGER.info(
          String.format(
              "The launch configuation %s has not been created for more than %d days",
              lcName, launchConfigAgeThreshold));
      return true;
    }
    LOGGER.info(
        String.format(
            "The launch configuation %s has been created for more than %d days",
            lcName, launchConfigAgeThreshold));

    if (lastChangeDaysThreshold != null) {
      String lastChangeTimeField =
          resource.getAdditionalField(EddaASGJanitorCrawler.ASG_FIELD_LAST_CHANGE_TIME);
      if (StringUtils.isNotBlank(lastChangeTimeField)) {
        DateTime lastChangeTime = new DateTime(Long.parseLong(lastChangeTimeField));
        if (lastChangeTime.plusDays(lastChangeDaysThreshold).isAfter(now)) {
          LOGGER.info(
              String.format(
                  "ASG %s had change during the last %d days",
                  resource.getId(), lastChangeDaysThreshold));
          return true;
        }
      }
    }

    markResource(resource, now);
    return false;
  }