LifecycleReaperJob.java (eucalyptus-4.4.1) | : | LifecycleReaperJob.java (eucalyptus-4.4.2) | ||
---|---|---|---|---|
skipping to change at line 71 | skipping to change at line 71 | |||
************************************************************************/ | ************************************************************************/ | |||
package com.eucalyptus.objectstorage.jobs; | package com.eucalyptus.objectstorage.jobs; | |||
import java.util.Calendar; | import java.util.Calendar; | |||
import java.util.Collections; | import java.util.Collections; | |||
import java.util.Date; | import java.util.Date; | |||
import java.util.List; | import java.util.List; | |||
import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | |||
import org.quartz.DisallowConcurrentExecution; | ||||
import org.quartz.InterruptableJob; | import org.quartz.InterruptableJob; | |||
import org.quartz.JobExecutionContext; | import org.quartz.JobExecutionContext; | |||
import org.quartz.JobExecutionException; | import org.quartz.JobExecutionException; | |||
import org.quartz.UnableToInterruptJobException; | import org.quartz.UnableToInterruptJobException; | |||
import com.eucalyptus.bootstrap.Databases; | import com.eucalyptus.bootstrap.Databases; | |||
import com.eucalyptus.objectstorage.BucketLifecycleManagers; | import com.eucalyptus.objectstorage.BucketLifecycleManagers; | |||
import com.eucalyptus.objectstorage.BucketMetadataManagers; | import com.eucalyptus.objectstorage.BucketMetadataManagers; | |||
import com.eucalyptus.objectstorage.BucketState; | import com.eucalyptus.objectstorage.BucketState; | |||
import com.eucalyptus.objectstorage.ObjectMetadataManagers; | import com.eucalyptus.objectstorage.ObjectMetadataManagers; | |||
import com.eucalyptus.objectstorage.ObjectState; | import com.eucalyptus.objectstorage.ObjectState; | |||
import com.eucalyptus.objectstorage.entities.Bucket; | import com.eucalyptus.objectstorage.entities.Bucket; | |||
import com.eucalyptus.objectstorage.entities.LifecycleRule; | import com.eucalyptus.objectstorage.entities.LifecycleRule; | |||
import com.eucalyptus.objectstorage.entities.ObjectEntity; | import com.eucalyptus.objectstorage.entities.ObjectEntity; | |||
import com.eucalyptus.objectstorage.exceptions.ObjectStorageException; | import com.eucalyptus.objectstorage.exceptions.ObjectStorageException; | |||
import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | |||
/* | /* | |||
* | * | |||
*/ | */ | |||
@DisallowConcurrentExecution | ||||
public class LifecycleReaperJob implements InterruptableJob { | public class LifecycleReaperJob implements InterruptableJob { | |||
private static Logger LOG = Logger.getLogger(LifecycleReaperJob.class); | private static final Logger LOG = Logger.getLogger(LifecycleReaperJob.class); | |||
private boolean interrupted = false; | private volatile boolean interrupted = false; | |||
@Override | @Override | |||
public void interrupt() throws UnableToInterruptJobException { | public void interrupt() throws UnableToInterruptJobException { | |||
this.interrupted = true; | this.interrupted = true; | |||
} | } | |||
@Override | @Override | |||
public void execute(JobExecutionContext context) throws JobExecutionException { | public void execute(JobExecutionContext context) throws JobExecutionException { | |||
if ( Databases.isVolatile( ) ) { | if ( Databases.isVolatile( ) ) { | |||
LOG.warn( "Skipping job due to database not available" ); | LOG.warn( "Skipping job due to database not available" ); | |||
skipping to change at line 163 | skipping to change at line 165 | |||
LOG.debug("rule id - " + rule.getRuleId() + " on bucket " + rule.getBu cketUuid() + " is not enabled"); | LOG.debug("rule id - " + rule.getRuleId() + " on bucket " + rule.getBu cketUuid() + " is not enabled"); | |||
} | } | |||
} | } | |||
} else { | } else { | |||
LOG.info("there are no rules to process"); | LOG.info("there are no rules to process"); | |||
} | } | |||
} | } | |||
private List<String> findMatchingObjects(String ruleId, Bucket bucket, String objPrefix, Date age) { | private List<String> findMatchingObjects(String ruleId, Bucket bucket, String objPrefix, Date age) { | |||
try { | try { | |||
// this check has the additional responsibility of keeping other OSGs from processing the same rule | // this check has the additional responsibility of keeping other OSGs from processing the same rule | |||
LifecycleRule retrievedRule = BucketLifecycleManagers.getInstance().getLif ecycleRuleForReaping(ruleId, bucket.getBucketUuid()); | LifecycleRule retrievedRule = BucketLifecycleManagers.getInstance().getLif ecycleRuleForReaping(ruleId, bucket.getBucketUuid()); | |||
if (retrievedRule == null) { | if (retrievedRule == null) { | |||
return Collections.EMPTY_LIST; | return Collections.emptyList( ); | |||
} | } | |||
} catch (ObjectStorageException e) { | } catch (ObjectStorageException e) { | |||
LOG.error("exception caught while attempting to retrieve lifecycle rule wi th id - " + ruleId + " in bucket - " + bucket.getBucketName() | LOG.error("exception caught while attempting to retrieve lifecycle rule wi th id - " + ruleId + " in bucket - " + bucket.getBucketName() | |||
+ " with message " + e.getMessage()); | + " with message " + e.getMessage()); | |||
return Collections.emptyList( ); | ||||
} | } | |||
// normalize the date to query by | // normalize the date to query by | |||
Calendar ageCal = Calendar.getInstance(); | Calendar ageCal = Calendar.getInstance(); | |||
ageCal.setTime(age); | ageCal.setTime(age); | |||
Calendar queryCal = Calendar.getInstance(); | Calendar queryCal = Calendar.getInstance(); | |||
queryCal.set(Calendar.DAY_OF_MONTH, ageCal.get(Calendar.DAY_OF_MONTH)); | queryCal.set(Calendar.DAY_OF_MONTH, ageCal.get(Calendar.DAY_OF_MONTH)); | |||
queryCal.set(Calendar.MONTH, ageCal.get(Calendar.MONTH)); | queryCal.set(Calendar.MONTH, ageCal.get(Calendar.MONTH)); | |||
queryCal.set(Calendar.YEAR, ageCal.get(Calendar.YEAR)); | queryCal.set(Calendar.YEAR, ageCal.get(Calendar.YEAR)); | |||
queryCal.set(Calendar.HOUR_OF_DAY, 0); | queryCal.set(Calendar.HOUR_OF_DAY, 0); | |||
queryCal.set(Calendar.MINUTE, 0); | queryCal.set(Calendar.MINUTE, 0); | |||
queryCal.set(Calendar.SECOND, 0); | queryCal.set(Calendar.SECOND, 0); | |||
queryCal.set(Calendar.MILLISECOND, 0); | queryCal.set(Calendar.MILLISECOND, 0); | |||
List<ObjectEntity> results = ObjectMetadataManagers.getInstance().lookupObje ctsForReaping(bucket, objPrefix, queryCal.getTime()); | List<ObjectEntity> results = ObjectMetadataManagers.getInstance().lookupObje ctsForReaping(bucket, objPrefix, queryCal.getTime()); | |||
if (results == null || results.size() == 0) { | if (results == null || results.size() == 0) { | |||
LOG.debug("there were no objects in bucket " + bucket.getBucketName() + " with prefix " + objPrefix + " older than " + queryCal.toString()); | LOG.debug("there were no objects in bucket " + bucket.getBucketName() + " with prefix " + objPrefix + " older than " + queryCal.toString()); | |||
// no matches | // no matches | |||
return Collections.EMPTY_LIST; | return Collections.emptyList( ); | |||
} | } | |||
// gather up keys | // gather up keys | |||
List<String> objectKeys = Lists.newArrayList(); | List<String> objectKeys = Lists.newArrayList(); | |||
for (ObjectEntity objectInfo : results) { | for (ObjectEntity objectInfo : results) { | |||
objectKeys.add(objectInfo.getObjectKey()); | objectKeys.add(objectInfo.getObjectKey()); | |||
} | } | |||
LOG.debug("found " + objectKeys.size() + " matching objects in bucket " + bu cket.getBucketName()); | LOG.debug("found " + objectKeys.size() + " matching objects in bucket " + bu cket.getBucketName()); | |||
return interrupted ? Collections.EMPTY_LIST : objectKeys; | return interrupted ? Collections.emptyList( ) : objectKeys; | |||
} | } | |||
private static abstract class ObjectInfoProcessor { | private static abstract class ObjectInfoProcessor { | |||
private List<String> objectKeys; | private List<String> objectKeys; | |||
private Bucket bucket; | private Bucket bucket; | |||
private boolean interrupted = false; | private boolean interrupted = false; | |||
public ObjectInfoProcessor(List<String> objectKeys, Bucket foundBucket) { | public ObjectInfoProcessor(List<String> objectKeys, Bucket foundBucket) { | |||
this.objectKeys = objectKeys; | this.objectKeys = objectKeys; | |||
this.bucket = foundBucket; | this.bucket = foundBucket; | |||
End of changes. 9 change blocks. | ||||
6 lines changed or deleted | 8 lines changed or added |