Skip to content

Commit

Permalink
RANGER-5061: checkstyle compliance updates - security-admin module - …
Browse files Browse the repository at this point in the history
…org.apache.ranger.patch package
  • Loading branch information
pradeepagrawal8184 committed Jan 6, 2025
1 parent 6783c30 commit 0fe0e1d
Show file tree
Hide file tree
Showing 58 changed files with 10,192 additions and 10,609 deletions.
49 changes: 49 additions & 0 deletions dev-support/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,53 @@
<suppress files="buildks.java" checks="TypeName"/>
<suppress files="RangerRolesUtil.java" checks="TypeName"/>
<suppress files="SPOOL_FILE_STATUS.java" checks="TypeName"/>
<suppress files="PatchAssignSecurityZonePersmissionToAdmin_J10026.java" checks="TypeName"/>
<suppress files="PatchAtlasForClassificationResource_J10047" checks="TypeName"/>
<suppress files="PatchForAllServiceDefForPolicyConditionUpdate_J10060" checks="TypeName"/>
<suppress files="PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049" checks="TypeName"/>
<suppress files="PatchForAllServiceDefUpdateForResourceSpecificAccesses_J10012" checks="TypeName"/>
<suppress files="PatchForAtlasAdminAudits_J10043" checks="TypeName"/>
<suppress files="PatchForAtlasResourceAndAccessTypeUpdate_J10016" checks="TypeName"/>
<suppress files="PatchForAtlasServiceDefUpdate_J10013" checks="TypeName"/>
<suppress files="PatchForAtlasToAddEntityLabelAndBusinessMetadata_J10034" checks="TypeName"/>
<suppress files="PatchForAtlasToAddTypeRead_J10040" checks="TypeName"/>
<suppress files="PatchForDefaultAuidtFilters_J10050" checks="TypeName"/>
<suppress files="PatchForExternalUserStatusUpdate_J10056" checks="TypeName"/>
<suppress files="PatchForHBaseDefaultPolicyUpdate_J10045" checks="TypeName"/>
<suppress files="PatchForHBaseServiceDefUpdate_J10035" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10006" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10007" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10009" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10010" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10017" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10027" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10030" checks="TypeName"/>
<suppress files="PatchForKafkaServiceDefUpdate_J10015" checks="TypeName"/>
<suppress files="PatchForKafkaServiceDefUpdate_J10025" checks="TypeName"/>
<suppress files="PatchForKafkaServiceDefUpdate_J10033" checks="TypeName"/>
<suppress files="PatchForMigratingOldRegimePolicyJson_J10046" checks="TypeName"/>
<suppress files="PatchForMigratingRangerServiceResource_J10037" checks="TypeName"/>
<suppress files="PatchForNifiResourceUpdateExclude_J10011" checks="TypeName"/>
<suppress files="PatchForOzoneDefaultPoliciesUpdate_J10044" checks="TypeName"/>
<suppress files="PatchForOzoneServiceDefConfigUpdate_J10051" checks="TypeName"/>
<suppress files="PatchForOzoneServiceDefUpdate_J10041" checks="TypeName"/>
<suppress files="PatchForPrestoToSupportPresto333_J10038" checks="TypeName"/>
<suppress files="PatchForServiceVersionInfo_J10004" checks="TypeName"/>
<suppress files="PatchForSolrSvcDefAndPoliciesUpdate_J10055" checks="TypeName"/>
<suppress files="PatchForSyncSourceUpdate_J10054" checks="TypeName"/>
<suppress files="PatchForTagServiceDefUpdate_J10008" checks="TypeName"/>
<suppress files="PatchForTagServiceDefUpdate_J10028" checks="TypeName"/>
<suppress files="PatchForTrinoSvcDefUpdate_J10062" checks="TypeName"/>
<suppress files="PatchForUpdatingAtlasSvcDefAndTagPolicies_J10063" checks="TypeName"/>
<suppress files="PatchForUpdatingPolicyJson_J10019" checks="TypeName"/>
<suppress files="PatchForUpdatingTagsJson_J10020" checks="TypeName"/>
<suppress files="PatchForXGlobalState_J10036" checks="TypeName"/>
<suppress files="PatchGrantAuditPermissionToKeyRoleUser_J10014" checks="TypeName"/>
<suppress files="PatchMigration_J10002" checks="TypeName"/>
<suppress files="PatchPasswordEncryption_J10001" checks="TypeName"/>
<suppress files="PatchPermissionModel_J10003" checks="TypeName"/>
<suppress files="PatchPreSql_057_ForUpdateToUniqueGUID_J10052" checks="TypeName"/>
<suppress files="PatchPreSql_058_ForUpdateToUniqueResoureceSignature_J10053" checks="TypeName"/>
<suppress files="PatchSetAccessTypeCategory_J10061" checks="TypeName"/>
<suppress files="PatchTagModulePermission_J10005" checks="TypeName"/>
</suppressions>
244 changes: 115 additions & 129 deletions security-admin/src/main/java/org/apache/ranger/patch/BaseLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
* under the License.
*/

/**
/**
*
*/
package org.apache.ranger.patch;

import java.text.DecimalFormat;

import org.apache.ranger.authorization.hadoop.config.RangerAdminConfig;
import org.apache.ranger.common.DateUtil;
import org.apache.ranger.util.CLIUtil;
Expand All @@ -32,176 +30,164 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.text.DecimalFormat;

/**
*
*
*/
public abstract class BaseLoader {
private static final Logger logger = LoggerFactory.getLogger(BaseLoader.class);

long startTime = DateUtil.getUTCDate().getTime();
long lastTime = startTime;
int countSoFar = 0;
int countFromLastTime = 0;
boolean moreToProcess = true;
boolean firstCall = true;
int batchSize = -1;
DecimalFormat twoDForm = new DecimalFormat("#.00");
private static final Logger logger = LoggerFactory.getLogger(BaseLoader.class);
protected final RangerAdminConfig config;
long startTime = DateUtil.getUTCDate().getTime();
long lastTime = startTime;
int countSoFar;
int countFromLastTime;
boolean moreToProcess = true;
boolean firstCall = true;
int batchSize = -1;
DecimalFormat twoDForm = new DecimalFormat("#.00");

public BaseLoader() {
this.config = RangerAdminConfig.getInstance();
}

public void init(int batchSize) throws Exception {
this.batchSize = batchSize;
CLIUtil cliUtil = (CLIUtil) CLIUtil.getBean(CLIUtil.class);
cliUtil.authenticate();
this.batchSize = batchSize;
CLIUtil cliUtil = (CLIUtil) CLIUtil.getBean(CLIUtil.class);
cliUtil.authenticate();
}

public void init() throws Exception {
init(-1);
init(-1);
}

abstract public void printStats();
public abstract void printStats();

public abstract void execLoad();

public void onExit() {
logger.info("onExit()");
logger.info("onExit()");
}

/**
* @return the moreToProcess
*/
public boolean isMoreToProcess() {
return moreToProcess;
return moreToProcess;
}

/**
* @param moreToProcess
* the moreToProcess to set
* @param moreToProcess the moreToProcess to set
*/
public void setMoreToProcess(boolean moreToProcess) {
this.moreToProcess = moreToProcess;
this.moreToProcess = moreToProcess;
}

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void load() {
if (firstCall) {
startTime = DateUtil.getUTCDate().getTime();
startProgressMonitor();
firstCall = false;
}
try {
execLoad();
if (batchSize < 0) {
moreToProcess = false;
}
} catch (Throwable t) {
logger.error("Error while loading data.", t);
moreToProcess = false;
}
if (!moreToProcess) {
long endTime = DateUtil.getUTCDate().getTime();

logger.info("###############################################");
printStats();
logger.info("Loading completed!!!. Time taken="
+ formatTimeTaken(endTime - startTime) + " for "
+ countSoFar);
logger.info("###############################################");
synchronized (twoDForm) {
twoDForm.notifyAll();
}

}
if (firstCall) {
startTime = DateUtil.getUTCDate().getTime();
startProgressMonitor();
firstCall = false;
}
try {
execLoad();
if (batchSize < 0) {
moreToProcess = false;
}
} catch (Throwable t) {
logger.error("Error while loading data.", t);
moreToProcess = false;
}
if (!moreToProcess) {
long endTime = DateUtil.getUTCDate().getTime();

logger.info("###############################################");
printStats();
logger.info("Loading completed!!!. Time taken={} for {}", formatTimeTaken(endTime - startTime), countSoFar);
logger.info("###############################################");
synchronized (twoDForm) {
twoDForm.notifyAll();
}
}
}

public void startProgressMonitor() {
Thread monitorThread = new Thread("Loader Monitor") {
@Override
public void run() {
while (isMoreToProcess()) {
printStats();
try {
synchronized (twoDForm) {
if (!isMoreToProcess()) {
break;
}
twoDForm.wait(30 * 1000);
}
// Thread.sleep(60 * 1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
logger.info("Monitor Thread exiting!!!");
}
};
monitorThread.setDaemon(true);
monitorThread.start();

Thread monitorThread = new Thread("Loader Monitor") {
@Override
public void run() {
while (isMoreToProcess()) {
printStats();
try {
synchronized (twoDForm) {
if (!isMoreToProcess()) {
break;
}
twoDForm.wait(30 * 1000);
}
// Thread.sleep(60 * 1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
logger.info("Monitor Thread exiting!!!");
}
};
monitorThread.setDaemon(true);
monitorThread.start();
}

public String timeTakenSoFar(int lineCount) {
countSoFar = lineCount;
long currTime = DateUtil.getUTCDate().getTime();
String retStr = formatTimeTaken(currTime - startTime);
if (currTime - startTime > 0 && countSoFar > 0) {
double rateSoFar = (double)(countSoFar * 1000) / (currTime - startTime);
retStr = retStr + " " + ". Rate so far for " + countSoFar + " is "
+ twoDForm.format(rateSoFar);

if (currTime - lastTime > 0 && lineCount - countFromLastTime > 0) {
double rateFromLastCall = (lineCount - countFromLastTime)
* 1000.0 / (currTime - lastTime);
retStr = retStr + ", Last "
+ formatTimeTaken(currTime - lastTime) + " for "
+ (lineCount - countFromLastTime) + " is "
+ twoDForm.format(rateFromLastCall);
}

}

lastTime = currTime;
countFromLastTime = countSoFar;
return retStr;
countSoFar = lineCount;
long currTime = DateUtil.getUTCDate().getTime();
String retStr = formatTimeTaken(currTime - startTime);
if (currTime - startTime > 0 && countSoFar > 0) {
double rateSoFar = (double) (countSoFar * 1000) / (currTime - startTime);
retStr = retStr + " " + ". Rate so far for " + countSoFar + " is " + twoDForm.format(rateSoFar);

if (currTime - lastTime > 0 && lineCount - countFromLastTime > 0) {
double rateFromLastCall = (lineCount - countFromLastTime) * 1000.0 / (currTime - lastTime);
retStr = retStr + ", Last " + formatTimeTaken(currTime - lastTime) + " for " + (lineCount - countFromLastTime) + " is " + twoDForm.format(rateFromLastCall);
}
}

lastTime = currTime;
countFromLastTime = countSoFar;
return retStr;
}

String formatTimeTaken(long totalTime) {
if (totalTime <= 0) {
return "0ms";
}
long ms = totalTime % 1000;
String retValue = ms + "ms";

totalTime = totalTime / 1000;
if (totalTime > 0) {
long secs = totalTime % 60;
retValue = secs + "secs, " + retValue;

totalTime = totalTime / 60;
if (totalTime > 0) {
long mins = totalTime % 60;
retValue = mins + "mins, " + retValue;

totalTime = totalTime / 60;
if (totalTime > 0) {
long hrs = totalTime % 60;
retValue = hrs + "hrs, " + retValue;
}
}
}

return retValue;

protected void print(int count, String message) {
if (count > 0) {
logger.info("{] : {}", message.trim(), count);
}
}

protected void print(int count, String message) {
if (count > 0) {
logger.info(message.trim() + " : " + count);
}
String formatTimeTaken(long totalTime) {
if (totalTime <= 0) {
return "0ms";
}
long ms = totalTime % 1000;
String retValue = ms + "ms";

totalTime = totalTime / 1000;
if (totalTime > 0) {
long secs = totalTime % 60;
retValue = secs + "secs, " + retValue;

totalTime = totalTime / 60;
if (totalTime > 0) {
long mins = totalTime % 60;
retValue = mins + "mins, " + retValue;

totalTime = totalTime / 60;
if (totalTime > 0) {
long hrs = totalTime % 60;
retValue = hrs + "hrs, " + retValue;
}
}
}

return retValue;
}
}
Loading

0 comments on commit 0fe0e1d

Please sign in to comment.