List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule.java
License:Apache License
@Override public boolean isValid(Resource resource) { Validate.notNull(resource);/*from w w w .ja v a 2 s . c om*/ for (String tagName : this.tagNames) { if (((AWSResource) resource).getTag(tagName) == null) { String terminationReason = String.format(" does not have the required tag %s", tagName); LOGGER.error(String.format("The resource %s %s", resource.getId(), terminationReason)); DateTime now = new DateTime(calendar.now().getTimeInMillis()); if (resource.getExpectedTerminationTime() == null) { int retentionDays = retentionDaysWithoutOwner; if (resource.getOwnerEmail() != null) { retentionDays = retentionDaysWithOwner; } Date terminationTime = calendar.getBusinessDay(new Date(now.getMillis()), retentionDays); resource.setExpectedTerminationTime(terminationTime); resource.setTerminationReason(terminationReason); } return false; } else { LOGGER.debug(String.format("The resource %s has the required tag %s", resource.getId(), tagName)); } } LOGGER.info(String.format("The resource %s has all required tags", resource.getId())); return true; }
From source file:com.netflix.simianarmy.aws.janitor.rule.instance.NoOwnerInstanceRule.java
License:Apache License
@Override public boolean isValid(Resource resource) { Validate.notNull(resource);//from ww w .j av a 2 s . c om if (!resource.getResourceType().name().equals("INSTANCE")) { // The rule is supposed to only work on AWS instances. If a non-instance resource // is passed to the rule, the rule simply ignores it and considers it as a valid // resource not for cleanup. return true; } String awsStatus = ((AWSResource) resource).getAWSResourceState(); if (!"running".equals(awsStatus) || "pending".equals(awsStatus)) { return true; } AWSResource instanceResource = (AWSResource) resource; String ownerTag = instanceResource.getTag(AWSResource.FIELD_OWNER_EMAIL); if (ownerTag == null || ownerTag.isEmpty()) { DateTime now = new DateTime(calendar.now().getTimeInMillis()); Date terminationTime = calendar.getBusinessDay(new Date(now.getMillis()), retentionDays); resource.setExpectedTerminationTime(terminationTime); resource.setTerminationReason(TERMINATION_REASON); LOGGER.info(String.format("The instance %s has no ownerEmail tag", resource.getId())); return false; } return true; }
From source file:com.netflix.simianarmy.aws.janitor.rule.instance.OrphanedInstanceRule.java
License:Apache License
@Override public boolean isValid(Resource resource) { Validate.notNull(resource);/* ww w.ja v a 2 s . com*/ if (!resource.getResourceType().name().equals("INSTANCE")) { // The rule is supposed to only work on AWS instances. If a non-instance resource // is passed to the rule, the rule simply ignores it and considers it as a valid // resource not for cleanup. return true; } String awsStatus = ((AWSResource) resource).getAWSResourceState(); if (!"running".equals(awsStatus) || "pending".equals(awsStatus)) { return true; } AWSResource instanceResource = (AWSResource) resource; String asgName = instanceResource.getAdditionalField(InstanceJanitorCrawler.INSTANCE_FIELD_ASG_NAME); if (StringUtils.isEmpty(asgName)) { if (resource.getLaunchTime() == null) { LOGGER.error(String.format("The instance %s has no launch time.", resource.getId())); return true; } else { DateTime launchTime = new DateTime(resource.getLaunchTime().getTime()); DateTime now = new DateTime(calendar.now().getTimeInMillis()); if (now.isBefore(launchTime.plusDays(instanceAgeThreshold))) { LOGGER.info(String.format("The orphaned instance %s has not launched for more than %d days", resource.getId(), instanceAgeThreshold)); return true; } LOGGER.info(String.format("The orphaned instance %s has launched for more than %d days", resource.getId(), instanceAgeThreshold)); if (resource.getExpectedTerminationTime() == null) { int retentionDays = retentionDaysWithoutOwner; if (resource.getOwnerEmail() != null) { retentionDays = retentionDaysWithOwner; } Date terminationTime = calendar.getBusinessDay(new Date(now.getMillis()), retentionDays); resource.setExpectedTerminationTime(terminationTime); resource.setTerminationReason(TERMINATION_REASON); } return false; } } return true; }
From source file:com.netflix.simianarmy.aws.janitor.rule.launchconfig.OldUnusedLaunchConfigRule.java
License:Apache License
@Override public boolean isValid(Resource resource) { Validate.notNull(resource);/*from w w w.j a va 2s. co m*/ if (!"LAUNCH_CONFIG".equals(resource.getResourceType().name())) { return true; } AWSResource lcResource = (AWSResource) resource; String usedByASG = lcResource .getAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG); if (StringUtils.isNotEmpty(usedByASG) && !Boolean.parseBoolean(usedByASG)) { if (resource.getLaunchTime() == null) { LOGGER.error(String.format("The launch config %s has no creation time.", resource.getId())); return true; } else { DateTime launchTime = new DateTime(resource.getLaunchTime().getTime()); DateTime now = new DateTime(calendar.now().getTimeInMillis()); if (now.isBefore(launchTime.plusDays(ageThreshold))) { LOGGER.info( String.format("The unused launch config %s has not been created for more than %d days", resource.getId(), ageThreshold)); return true; } LOGGER.info(String.format("The unused launch config %s has been created for more than %d days", resource.getId(), ageThreshold)); if (resource.getExpectedTerminationTime() == null) { Date terminationTime = calendar.getBusinessDay(new Date(now.getMillis()), retentionDays); resource.setExpectedTerminationTime(terminationTime); resource.setTerminationReason(TERMINATION_REASON); } return false; } } return true; }
From source file:com.netflix.simianarmy.aws.janitor.rule.snapshot.NoGeneratedAMIRule.java
License:Apache License
@Override public boolean isValid(Resource resource) { Validate.notNull(resource);/*from w w w. j a v a 2s .c o m*/ if (!resource.getResourceType().name().equals("EBS_SNAPSHOT")) { return true; } if (!"completed".equals(((AWSResource) resource).getAWSResourceState())) { return true; } String janitorTag = resource.getTag(JanitorMonkey.JANITOR_TAG); if (janitorTag != null) { if ("donotmark".equals(janitorTag)) { LOGGER.info(String.format("The snapshot %s is tagged as not handled by Janitor", resource.getId())); return true; } try { // Owners can tag the volume with a termination date in the "janitor" tag. Date userSpecifiedDate = new Date(TERMINATION_DATE_FORMATTER.parseDateTime(janitorTag).getMillis()); resource.setExpectedTerminationTime(userSpecifiedDate); resource.setTerminationReason(String.format("User specified termination date %s", janitorTag)); return false; } catch (Exception e) { LOGGER.error(String.format("The janitor tag is not a user specified date: %s", janitorTag)); } } if (hasGeneratedImage(resource)) { return true; } if (resource.getLaunchTime() == null) { LOGGER.error(String.format("Snapshot %s does not have a creation time.", resource.getId())); return true; } DateTime launchTime = new DateTime(resource.getLaunchTime().getTime()); DateTime now = new DateTime(calendar.now().getTimeInMillis()); if (launchTime.plusDays(ageThreshold).isBefore(now)) { if (resource.getExpectedTerminationTime() == null) { Date terminationTime = calendar.getBusinessDay(new Date(now.getMillis()), retentionDays); resource.setExpectedTerminationTime(terminationTime); resource.setTerminationReason(TERMINATION_REASON); LOGGER.info(String.format( "Snapshot %s is marked to be cleaned at %s as there is no AMI generated using it", resource.getId(), resource.getExpectedTerminationTime())); } else { LOGGER.info(String.format("Resource %s is already marked.", resource.getId())); } return false; } return true; }
From source file:com.netflix.simianarmy.aws.janitor.rule.volume.OldDetachedVolumeRule.java
License:Apache License
@Override public boolean isValid(Resource resource) { Validate.notNull(resource);// ww w .j ava 2s.c o m if (!resource.getResourceType().name().equals("EBS_VOLUME")) { return true; } if (!"available".equals(((AWSResource) resource).getAWSResourceState())) { return true; } String janitorTag = resource.getTag(JanitorMonkey.JANITOR_TAG); if (janitorTag != null) { if ("donotmark".equals(janitorTag)) { LOGGER.info(String.format("The volume %s is tagged as not handled by Janitor", resource.getId())); return true; } try { // Owners can tag the volume with a termination date in the "janitor" tag. Date userSpecifiedDate = new Date(TERMINATION_DATE_FORMATTER.parseDateTime(janitorTag).getMillis()); resource.setExpectedTerminationTime(userSpecifiedDate); resource.setTerminationReason(String.format("User specified termination date %s", janitorTag)); return false; } catch (Exception e) { LOGGER.error(String.format("The janitor tag is not a user specified date: %s", janitorTag)); } } String janitorMetaTag = resource.getTag(JanitorMonkey.JANITOR_META_TAG); if (janitorMetaTag == null) { LOGGER.info(String.format("Volume %s is not tagged with the Janitor meta information, ignore.", resource.getId())); return true; } Map<String, String> metadata = VolumeTaggingMonkey.parseJanitorMetaTag(janitorMetaTag); String detachTimeTag = metadata.get(JanitorMonkey.DETACH_TIME_TAG_KEY); if (detachTimeTag == null) { return true; } DateTime detachTime = null; try { detachTime = AWSResource.DATE_FORMATTER.parseDateTime(detachTimeTag); } catch (Exception e) { LOGGER.error(String.format("Detach time in the JANITOR_META tag of %s is not in the valid format: %s", resource.getId(), detachTime)); return true; } DateTime now = new DateTime(calendar.now().getTimeInMillis()); if (detachTime != null && detachTime.plusDays(detachDaysThreshold).isBefore(now)) { if (resource.getExpectedTerminationTime() == null) { Date terminationTime = calendar.getBusinessDay(new Date(now.getMillis()), retentionDays); resource.setExpectedTerminationTime(terminationTime); resource.setTerminationReason( String.format("Volume not attached for %d days", detachDaysThreshold + retentionDays)); LOGGER.info(String.format( "Volume %s is marked to be cleaned at %s as it is detached for more than %d days", resource.getId(), resource.getExpectedTerminationTime(), detachDaysThreshold)); } else { LOGGER.info(String.format("Resource %s is already marked.", resource.getId())); } return false; } return true; }
From source file:com.netflix.spinnaker.front50.model.AzureStorageService.java
License:Apache License
@Override public Map<String, Long> listObjectKeys(ObjectType objectType) { Map<String, Long> objectKeys = new HashMap<>(); try {/* w w w .j a v a2 s .c o m*/ ResultContinuation token = null; do { ResultSegment<ListBlobItem> result = getBlobContainer().listBlobsSegmented(objectType.group, true, null, 10000, token, null, null); token = result.getContinuationToken(); result.getResults().stream().filter(item -> match(item, objectType.defaultMetadataFilename)) .forEach(item -> { CloudBlob blob = (CloudBlob) item; DateTime modDate = new DateTime(blob.getProperties().getLastModified()); objectKeys.put(getBlobKey(objectType, blob.getUri().toString()), modDate.getMillis()); }); } while (token != null); } catch (StorageException se) { logStorageException(se, ""); } catch (Exception e) { log.error("Failed to retrieve objects from {}: {}", objectType.group, e.getMessage()); } return objectKeys; }
From source file:com.netflix.spinnaker.front50.model.EventingS3ObjectKeyLoader.java
License:Apache License
private void tick(S3Event s3Event) { s3Event.records.forEach(record -> { if (record.s3.object.key.endsWith("last-modified.json")) { return; }/*w w w . j a v a 2s . c om*/ String eventType = record.eventName; KeyWithObjectType keyWithObjectType = buildObjectKey(rootFolder, record.s3.object.key); DateTime eventTime = new DateTime(record.eventTime); log.debug("Received Event (objectType: {}, type: {}, key: {}, delta: {})", value("objectType", keyWithObjectType.objectType), value("type", eventType), value("key", keyWithObjectType.key), value("delta", System.currentTimeMillis() - eventTime.getMillis())); objectKeysByLastModifiedCache.put(keyWithObjectType, eventTime.getMillis()); }); }
From source file:com.netflix.suro.input.JsonLog4jFormatter.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2 s. co m public String format(LoggingEvent event) { Object obj = event.getMessage(); routingKey = null; if (obj instanceof Map) { Map map = (Map) event.getMessage(); DateTime now = new DateTime(); map.put("ts", now.getMillis()); map.put("datetime", fmt.print(now)); map.put("logLevel", event.getLevel().toString()); map.put("class", event.getLoggerName()); routingKey = (String) map.get(TagKey.ROUTING_KEY); // Extract exceptions String[] s = event.getThrowableStrRep(); if (s != null && s.length > 0) { map.put("Exception", s); } try { return jsonMapper.writeValueAsString(map); } catch (JsonProcessingException e) { jsonParsingError.incrementAndGet(); return stringFormatter.format(event); } } else { jsonParsingError.incrementAndGet(); return stringFormatter.format(event); } }
From source file:com.nfsdb.journal.utils.Dates.java
License:Apache License
public static Interval interval(DateTime start, DateTime end) { return interval(start.getMillis(), end.getMillis()); }