Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
changed LOG and log to logger for standardizing logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jewest27 committed Jan 8, 2016
1 parent f9aab91 commit bc33c88
Show file tree
Hide file tree
Showing 82 changed files with 740 additions and 791 deletions.
Expand Up @@ -26,7 +26,6 @@
import java.util.concurrent.atomic.AtomicLong;

import com.google.inject.Injector;
import org.apache.usergrid.corepersistence.CpSetup;
import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -56,7 +55,7 @@
public class JobSchedulerService extends AbstractScheduledService {
protected static final long DEFAULT_DELAY = 1000;

private static final Logger LOG = LoggerFactory.getLogger( JobSchedulerService.class );
private static final Logger logger = LoggerFactory.getLogger( JobSchedulerService.class );

private long interval = DEFAULT_DELAY;
private int workerSize = 1;
Expand Down Expand Up @@ -94,16 +93,16 @@ protected void runOneIteration() throws Exception {
failCounter = metricsFactory.getCounter( JobSchedulerService.class, "scheduler.failed_jobs" );

try {
LOG.info( "Running one check iteration ..." );
logger.info( "Running one check iteration ..." );
List<JobDescriptor> activeJobs;

// run until there are no more active jobs
while ( true ) {

// get the semaphore if we can. This means we have space for at least 1
// job
if ( LOG.isDebugEnabled() ) {
LOG.debug( "About to acquire semaphore. Capacity is {}", capacitySemaphore.availablePermits() );
if ( logger.isDebugEnabled() ) {
logger.debug( "About to acquire semaphore. Capacity is {}", capacitySemaphore.availablePermits() );
}

capacitySemaphore.acquire();
Expand All @@ -113,30 +112,30 @@ protected void runOneIteration() throws Exception {

int capacity = capacitySemaphore.availablePermits();

if (LOG.isDebugEnabled()) {
LOG.debug("Capacity is {}", capacity);
if (logger.isDebugEnabled()) {
logger.debug("Capacity is {}", capacity);
}

activeJobs = jobAccessor.getJobs( capacity );

// nothing to do, we don't have any jobs to run
if ( activeJobs.size() == 0 ) {
if (LOG.isDebugEnabled()) {
LOG.debug("No jobs returned. Exiting run loop");
if (logger.isDebugEnabled()) {
logger.debug("No jobs returned. Exiting run loop");
}
return;
}

for ( JobDescriptor jd : activeJobs ) {
LOG.info( "Submitting work for {}", jd );
logger.info( "Submitting work for {}", jd );
submitWork( jd );
LOG.info( "Work submitted for {}", jd );
logger.info( "Work submitted for {}", jd );
}
}
}
catch ( Throwable t ) {
if (LOG.isDebugEnabled()) {
LOG.debug("Scheduler run failed, error is", t);
if (logger.isDebugEnabled()) {
logger.debug("Scheduler run failed, error is", t);
}
}
}
Expand All @@ -163,7 +162,7 @@ private void submitWork( final JobDescriptor jobDescriptor ) {
job = jobFactory.jobsFrom( jobDescriptor );
}
catch ( JobNotFoundException e ) {
LOG.error( "Could not create jobs", e );
logger.error( "Could not create jobs", e );
return;
}

Expand All @@ -185,7 +184,7 @@ private void submitWork( final JobDescriptor jobDescriptor ) {
capacitySemaphore.acquire();
}
catch ( InterruptedException e ) {
LOG.error( "Unable to acquire semaphore capacity before submitting job", e );
logger.error( "Unable to acquire semaphore capacity before submitting job", e );
//just return, they'll get picked up again later
return;
}
Expand All @@ -198,8 +197,8 @@ private void submitWork( final JobDescriptor jobDescriptor ) {
@Override
public Void call() throws Exception {

if (LOG.isDebugEnabled()) {
LOG.debug("Starting the job with job id {}", execution.getJobId());
if (logger.isDebugEnabled()) {
logger.debug("Starting the job with job id {}", execution.getJobId());
}
runCounter.inc();

Expand All @@ -216,7 +215,7 @@ public Void call() throws Exception {
catch ( Exception t ) {
//we purposefully swallow all exceptions here, we don't want it to effect the outcome
//of finally popping this job from the queue
LOG.error( "Unable to invoke dead event on job", t );
logger.error( "Unable to invoke dead event on job", t );
}

return null;
Expand All @@ -227,7 +226,7 @@ public Void call() throws Exception {
// TODO wrap and throw specifically typed exception for onFailure,
// needs jobId

LOG.info( "Starting job {} with execution data {}", job, execution );
logger.info( "Starting job {} with execution data {}", job, execution );

job.execute( execution );

Expand All @@ -247,8 +246,8 @@ public void onSuccess( Void param ) {
* Release semaphore first in case there are other problems with communicating with Cassandra
*/

if (LOG.isDebugEnabled()) {
LOG.debug("Job succeeded with the job id {}", execution.getJobId());
if (logger.isDebugEnabled()) {
logger.debug("Job succeeded with the job id {}", execution.getJobId());
}
capacitySemaphore.release();
timer.stop();
Expand All @@ -258,7 +257,7 @@ public void onSuccess( Void param ) {

//TODO, refactor into the execution itself for checking if done
if ( execution.getStatus() == Status.IN_PROGRESS ) {
LOG.info( "Successful completion of bulkJob {}", execution );
logger.info( "Successful completion of bulkJob {}", execution );
execution.completed();
}

Expand All @@ -277,14 +276,14 @@ public void onFailure( Throwable throwable ) {
/**
* Release semaphore first in case there are other problems with communicating with Cassandra
*/
LOG.error( "Job failed with the job id {}", execution.getJobId() );
logger.error( "Job failed with the job id {}", execution.getJobId() );
capacitySemaphore.release();
timer.stop();
runCounter.dec();
failCounter.inc();


LOG.error( "Failed execution for bulkJob", throwable );
logger.error( "Failed execution for bulkJob", throwable );
// mark it as failed
if ( execution.getStatus() == Status.IN_PROGRESS ) {
execution.failed();
Expand Down Expand Up @@ -374,11 +373,11 @@ protected void startUp() throws Exception {
.listeningDecorator( Executors.newScheduledThreadPool( workerSize, JobThreadFactory.INSTANCE ) );
capacitySemaphore = new Semaphore( workerSize );

LOG.info( "Starting executor pool. Capacity is {}", workerSize );
logger.info( "Starting executor pool. Capacity is {}", workerSize );

super.startUp();

LOG.info( "Job Scheduler started" );
logger.info( "Job Scheduler started" );
}


Expand All @@ -389,11 +388,11 @@ protected void startUp() throws Exception {
*/
@Override
protected void shutDown() throws Exception {
LOG.info( "Shutting down job scheduler" );
logger.info( "Shutting down job scheduler" );

service.shutdown();

LOG.info( "Job scheduler shut down" );
logger.info( "Job scheduler shut down" );
super.shutDown();
}

Expand Down
Expand Up @@ -62,7 +62,7 @@ public class SchedulerServiceImpl implements SchedulerService, JobAccessor, JobR

private static final String JOB_NAME = "jobName";

private static final Logger LOG = LoggerFactory.getLogger( SchedulerServiceImpl.class );
private static final Logger logger = LoggerFactory.getLogger( SchedulerServiceImpl.class );

private static final String DEFAULT_QUEUE_NAME = "/jobs";

Expand Down Expand Up @@ -144,8 +144,8 @@ public void deleteJob( UUID jobId ) {
* as discarded
*/
try {
if (LOG.isDebugEnabled()) {
LOG.debug("deleteJob {}", jobId);
if (logger.isDebugEnabled()) {
logger.debug("deleteJob {}", jobId);
}
getEm().delete( new SimpleEntityRef(
Schema.getDefaultSchema().getEntityType(JobData.class), jobId ) );
Expand Down Expand Up @@ -189,7 +189,7 @@ public List<JobDescriptor> getJobs( int size ) {
* still fire. Ignore this job
*/
if ( data == null || stats == null ) {
LOG.info( "Received job with data id '{}' from the queue, but no data was found. Dropping job",
logger.info( "Received job with data id '{}' from the queue, but no data was found. Dropping job",
jobUuid );
getQm().deleteTransaction( jobQueueName, job.getTransaction(), null );

Expand All @@ -210,7 +210,7 @@ public List<JobDescriptor> getJobs( int size ) {
// log and skip. This is a catastrophic runtime error if we see an
// exception here. We don't want to cause job loss, so leave the job in
// the Q.
LOG.error(
logger.error(
"Unable to retrieve job data for jobname {}, job id {}, stats id {}. Skipping to avoid job "
+ "loss", new Object[] { jobName, jobUuid, statsUuid, e } );
}
Expand All @@ -222,8 +222,8 @@ public List<JobDescriptor> getJobs( int size ) {

@Override
public void heartbeat( JobRuntime execution, long delay ) {
if (LOG.isDebugEnabled()) {
LOG.debug("renew transaction {}", execution.getTransactionId());
if (logger.isDebugEnabled()) {
logger.debug("renew transaction {}", execution.getTransactionId());
}
try {
// @TODO - what's the point to this sychronized block on an argument?
Expand All @@ -232,13 +232,13 @@ public void heartbeat( JobRuntime execution, long delay ) {
new QueueQuery().withTimeout( delay ) );

execution.setTransactionId( newId );
if (LOG.isDebugEnabled()) {
LOG.debug("renewed transaction {}", newId);
if (logger.isDebugEnabled()) {
logger.debug("renewed transaction {}", newId);
}
}
}
catch ( TransactionNotFoundException e ) {
LOG.error( "Could not renew transaction", e );
logger.error( "Could not renew transaction", e );
throw new JobRuntimeException( "Could not renew transaction during heartbeat", e );
}
}
Expand Down Expand Up @@ -284,18 +284,18 @@ public void save( JobExecution bulkJobExecution ) {

// we're done. Mark the transaction as complete and delete the job info
if ( jobStatus == Status.COMPLETED ) {
LOG.info( "Job {} is complete id: {}", data.getJobName(), bulkJobExecution.getTransactionId() );
logger.info( "Job {} is complete id: {}", data.getJobName(), bulkJobExecution.getTransactionId() );
getQm().deleteTransaction( jobQueueName, bulkJobExecution.getTransactionId(), null );
if (LOG.isDebugEnabled()) {
LOG.debug("delete job data {}", data.getUuid());
if (logger.isDebugEnabled()) {
logger.debug("delete job data {}", data.getUuid());
}
getEm().delete( data );
}

// the job failed too many times. Delete the transaction to prevent it
// running again and save it for querying later
else if ( jobStatus == Status.DEAD ) {
LOG.warn( "Job {} is dead. Removing", data.getJobName() );
logger.warn( "Job {} is dead. Removing", data.getJobName() );
getQm().deleteTransaction( jobQueueName, bulkJobExecution.getTransactionId(), null );
getEm().update( data );
}
Expand All @@ -305,7 +305,7 @@ else if ( jobStatus == Status.DEAD ) {
getEm().update( data );
}

LOG.info( "Updating stats for job {}", data.getJobName() );
logger.info( "Updating stats for job {}", data.getJobName() );

getEm().update( stat );
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class Slf4JBatchSubmitter implements BatchSubmitter {

// TODO custom logger for printing counts
// - should be configed programatically
private static final Logger log = LoggerFactory.getLogger( Slf4JBatchSubmitter.class );
private static final Logger logger = LoggerFactory.getLogger( Slf4JBatchSubmitter.class );

private int threadCount = 3;

Expand All @@ -62,7 +62,7 @@ public Object call() throws Exception {
// TODO perhaps this could be pushed down further into CountProducer Impl?
// - this would leave generic submitter class
for ( Count c : counts ) {
log.info( "found count {}", c );
logger.info( "found count {}", c );
}
timer.stop();
return true;
Expand All @@ -72,7 +72,7 @@ public Object call() throws Exception {


public void shutdown() {
log.warn( "Shutdown Slf4jBatchSubmitter" );
logger.warn( "Shutdown Slf4jBatchSubmitter" );
executor.shutdown();
}
}
Expand Up @@ -136,7 +136,7 @@ public static <K, V> V getValue( Map<K, ?> map, K k ) {
v = ( V ) map.get( k );
}
catch ( ClassCastException e ) {
//LOG.war( "Map value {} was not the expected class", map.get( k ), e );
//logger.war( "Map value {} was not the expected class", map.get( k ), e );
}

return v;
Expand Down
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

Expand All @@ -47,7 +46,7 @@


public class UUIDUtils {
private static final Logger LOG = LoggerFactory.getLogger( UUIDUtils.class );
private static final Logger logger = LoggerFactory.getLogger( UUIDUtils.class );
private static final int[] MICROS = new int[1000];


Expand Down Expand Up @@ -324,7 +323,7 @@ public static UUID tryGetUUID( String s ) {
uuid = UUID.fromString( s );
}
catch ( Exception e ) {
LOG.info( "Could not convert String {} into a UUID", s, e );
logger.info( "Could not convert String {} into a UUID", s, e );
}
return uuid;
}
Expand Down
Expand Up @@ -27,7 +27,7 @@

public abstract class AbstractCoreIT {

private static final Logger LOG = LoggerFactory.getLogger( AbstractCoreIT.class );
private static final Logger logger = LoggerFactory.getLogger( AbstractCoreIT.class );

@ClassRule
public static CoreITSetup setup = new CoreITSetupImpl( );
Expand All @@ -38,8 +38,8 @@ public abstract class AbstractCoreIT {


public void dump( String name, Object obj ) {
if ( obj != null && LOG.isInfoEnabled() ) {
LOG.info( name + ":\n" + JsonUtils.mapToFormattedJsonString( obj ) );
if ( obj != null && logger.isInfoEnabled() ) {
logger.info( name + ":\n" + JsonUtils.mapToFormattedJsonString( obj ) );
}
}
}

0 comments on commit bc33c88

Please sign in to comment.