コード例 #1
0
  private void setAttachmentInfo(
      String volumeId, JsonNode attachment, DateTime detachTime, Resource resource) {
    String instanceId = null;
    if (attachment != null) {
      boolean deleteOnTermination = attachment.get(DELETE_ON_TERMINATION).getBooleanValue();
      if (deleteOnTermination) {
        LOGGER.info(
            String.format("Volume %s had set the deleteOnTermination flag as true", volumeId));
      }
      resource.setAdditionalField(DELETE_ON_TERMINATION, String.valueOf(deleteOnTermination));
      instanceId = attachment.get("instanceId").getTextValue();
    }
    // The subclass can customize the way to get the owner for a volume
    String owner = getOwnerEmailForResource(resource);
    if (owner == null && instanceId != null) {
      owner = instanceToOwner.get(instanceId);
    }
    resource.setOwnerEmail(owner);

    String metaTag = makeMetaTag(instanceId, owner, detachTime);
    LOGGER.info(String.format("Setting Janitor Metatag as %s for volume %s", metaTag, volumeId));
    resource.setTag(JanitorMonkey.JANITOR_META_TAG, metaTag);

    LOGGER.info(String.format("The last detach time of volume %s is %s", volumeId, detachTime));
    resource.setAdditionalField(DETACH_TIME, String.valueOf(detachTime.getMillis()));
  }
コード例 #2
0
  private Resource parseJsonElementToVolumeResource(String region, JsonNode jsonNode) {
    Validate.notNull(jsonNode);
    long createTime = jsonNode.get("createTime").asLong();

    Resource resource =
        new AWSResource()
            .withId(jsonNode.get("volumeId").getTextValue())
            .withRegion(region)
            .withResourceType(AWSResourceType.EBS_VOLUME)
            .withLaunchTime(new Date(createTime));

    JsonNode tags = jsonNode.get("tags");
    StringBuilder description = new StringBuilder();
    JsonNode size = jsonNode.get("size");
    description.append(String.format("size=%s", size == null ? "unknown" : size.getIntValue()));

    if (tags == null || !tags.isArray() || tags.size() == 0) {
      LOGGER.debug(String.format("No tags is found for %s", resource.getId()));
    } else {
      for (Iterator<JsonNode> it = tags.getElements(); it.hasNext(); ) {
        JsonNode tag = it.next();
        String key = tag.get("key").getTextValue();
        String value = tag.get("value").getTextValue();
        description.append(String.format("; %s=%s", key, value));
        resource.setTag(key, value);
        if (key.equals(PURPOSE)) {
          resource.setAdditionalField(PURPOSE, value);
        }
      }
      resource.setDescription(description.toString());
    }
    ((AWSResource) resource).setAWSResourceState(jsonNode.get("state").getTextValue());
    return resource;
  }