* The Enum InternalState.
*/
private enum InternalState {
- IDLE, PRE_SYNC, SYNC_OPERATION, SELECTIVE_DELETE, ABORTING_SYNC, REPAIRING_INDEX, POST_SYNC, TEST_INDEX_INTEGRITY, GENERATE_FINAL_REPORT
+ IDLE, PRE_SYNC, SYNC_OPERATION, SELECTIVE_DELETE, ABORTING_SYNC, REPAIRING_INDEX, POST_SYNC,
+ TEST_INDEX_INTEGRITY, GENERATE_FINAL_REPORT
}
/**
* The Enum SyncActions.
*/
public enum SyncActions {
- SYNCHRONIZE, REPAIR_INDEX, INDEX_INTEGRITY_VALIDATION_COMPLETE, PRE_SYNC_COMPLETE, SYNC_COMPLETE, SYNC_ABORTED, SYNC_FAILURE, POST_SYNC_COMPLETE, PURGE_COMPLETE, REPORT_COMPLETE
+ SYNCHRONIZE, REPAIR_INDEX, INDEX_INTEGRITY_VALIDATION_COMPLETE, PRE_SYNC_COMPLETE,
+ SYNC_COMPLETE, SYNC_ABORTED, SYNC_FAILURE, POST_SYNC_COMPLETE, PURGE_COMPLETE, REPORT_COMPLETE
}
private Collection<IndexSynchronizer> registeredSynchronizers;
private InternalState currentInternalState;
private ExecutorService syncControllerExecutor;
private ExecutorService statReporterExecutor;
-
+
private long delayInMs;
private long syncFrequencyInMs;
private Date syncStartTime;
-
+
private Date lastExecutionDate;
- private AtomicInteger runCount;
+ private AtomicInteger runCount;
private Semaphore performingActionGate;
private Calendar creationTime;
-
+
private String syncStartTimeWithTimeZone;
private String controllerName;
-
+
protected SyncControllerConfig syncControllerConfig;
-
+
+
/**
* @throws Exception the exception
*/
public SyncControllerImpl(SyncControllerConfig syncControllerConfig) throws Exception {
- this(syncControllerConfig, null);
+ this(syncControllerConfig,null);
}
-
+
public SyncControllerImpl(SyncControllerConfig syncControllerConfig, String targetEntityType)
throws Exception {
if (targetEntityType != null) {
controllerName += " (" + targetEntityType + ")";
}
-
+
this.controllerName = controllerName;
this.syncControllerExecutor = NodeUtils.createNamedExecutor("SyncController-" + controllerName,
this.currentInternalState = InternalState.IDLE;
- this.creationTime = Calendar
- .getInstance(TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp()));
+ this.creationTime =
+ Calendar.getInstance(TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp()));
}
+
+
-
+
+
/**
* Change internal state.
*
* @param causedByAction the caused by action
*/
private void changeInternalState(InternalState newState, SyncActions causedByAction) {
- LOG.info(AaiUiMsgs.SYNC_INTERNAL_STATE_CHANGED, controllerName, currentInternalState.toString(),
- newState.toString(), causedByAction.toString());
+ LOG.info(AaiUiMsgs.SYNC_INTERNAL_STATE_CHANGED, controllerName,
+ currentInternalState.toString(), newState.toString(), causedByAction.toString());
this.currentInternalState = newState;
performStateAction();
}
-
-
-
- /*
- * (non-Javadoc)
- *
+
+
+
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getDelayInMs()
*/
@Override
return delayInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setDelayInMs(long)
*/
@Override
this.delayInMs = delayInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getSyncFrequencyInMs()
*/
@Override
return syncFrequencyInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setSyncFrequencyInMs(long)
*/
@Override
this.syncFrequencyInMs = syncFrequencyInMs;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getSyncStartTime()
*/
@Override
return syncStartTime;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setSyncStartTime(java.util.Date)
*/
@Override
this.syncStartTime = syncStartTime;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#getLastExecutionDate()
*/
@Override
return lastExecutionDate;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncController2#setLastExecutionDate(java.util.Date)
*/
@Override
public void setLastExecutionDate(Date lastExecutionDate) {
this.lastExecutionDate = lastExecutionDate;
}
-
+
@Override
public String getControllerName() {
return controllerName;
}
-
-
+
+
+
@Override
public OperationState performAction(SyncActions requestedAction) {
if (currentInternalState == InternalState.IDLE) {
-
+
try {
-
+
/*
* non-blocking semaphore acquire used to guarantee only 1 execution of the synchronization
* at a time.
*/
-
+
switch (requestedAction) {
case SYNCHRONIZE:
long opEndTime = System.currentTimeMillis();
long opTime = (opEndTime - opStartTime);
-
+
String durationMessage =
String.format(getControllerName() + " synchronization took '%d' ms.", opTime);
LOG.info(AaiUiMsgs.SYNC_DURATION, durationMessage);
-
+
if (syncControllerConfig.isPeriodicSyncEnabled()) {
LOG.info(AaiUiMsgs.INFO_GENERIC,
getControllerName() + " next sync to begin at " + getNextSyncTime());
- TimeZone tz =
- TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp());
+ TimeZone tz = TimeZone.getTimeZone(syncControllerConfig.getTimeZoneOfSyncStartTimeStamp());
if (opTime > this.getSyncFrequencyInMs()) {
default:
break;
}
-
+
return OperationState.OK;
} catch (Exception exc) {
LOG.error(AaiUiMsgs.ERROR_GENERIC, message);
return OperationState.ERROR;
} finally {
-
+
}
} else {
LOG.error(AaiUiMsgs.SYNC_NOT_VALID_STATE_DURING_REQUEST, currentInternalState.toString());
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncControllerInterface#shutdown()
*/
@Override
}
}
- if (System.currentTimeMillis() > nextReportTimeStampInMs) {
+ if ( System.currentTimeMillis() > nextReportTimeStampInMs) {
dumpPeriodicStatReport = true;
- nextReportTimeStampInMs = System.currentTimeMillis() + 30000L;
+ nextReportTimeStampInMs = System.currentTimeMillis() + 30000L;
} else {
dumpPeriodicStatReport = false;
}
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.openecomp.sparky.synchronizer.SyncControllerInterface#getState()
*/
@Override
public boolean isRunOnceSyncEnabled() {
return syncControllerConfig.isRunOnceSyncEnabled();
}
-
-}
+
+}
\ No newline at end of file