Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package edu.internet2.middleware.grouper.app.provisioning;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import edu.internet2.middleware.grouper.app.loader.GrouperLoaderStatus;
import edu.internet2.middleware.grouper.app.loader.OtherJobException;
import edu.internet2.middleware.grouper.misc.GrouperFailsafe;
import edu.internet2.middleware.grouper.misc.GrouperFailsafeBean;
import edu.internet2.middleware.grouper.util.GrouperUtil;
import edu.internet2.middleware.grouperClient.jdbc.GcDbAccess;
import edu.internet2.middleware.grouperClient.jdbc.tableSync.GcGrouperSyncLogState;
import edu.internet2.middleware.grouperClient.util.GrouperClientUtils;
/**
*
* @author mchyzer
*
*/
public class GrouperProvisioningFailsafe {
/**
* reference back up to the provisioner
*/
private GrouperProvisioner grouperProvisioner = null;
/**
*
*/
private GrouperFailsafeBean grouperFailsafeBean = new GrouperFailsafeBean();
/**
* see if there is a failsafe issue and throw a failsafe error
*/
public void processFailsafes() {
processFailsafesMinOverallNumberOfMembers();
processFailsafesMaxGroupPercentRemove();
processFailsafesMinManagedGroups();
}
/**
*
*/
public void processFailsafesMinManagedGroups() {
if (this.grouperFailsafeBean.getMinManagedGroups() != null && this.grouperFailsafeBean.getMinManagedGroups() > -1) {
this.processFailsafesSetupGroupTotals();
this.processFailsafesSetupGroupCount();
Set groupUuidsToDelete = new HashSet(this.getGrouperProvisioner().retrieveGrouperProvisioningCompare().getGroupUuidsToDelete());
Map groupUuidToMembershipDeleteCount = new HashMap(this.getGrouperProvisioner().retrieveGrouperProvisioningCompare().getGroupUuidToMembershipDeleteCount());
Map groupUuidToMembershipAddCount = new HashMap(this.getGrouperProvisioner().retrieveGrouperProvisioningCompare().getGroupUuidToMembershipAddCount());
for (String groupUuid : groupUuidsToDelete) {
groupUuidToMembershipDeleteCount.remove(groupUuid);
groupUuidToMembershipAddCount.remove(groupUuid);
}
for (String groupUuid : this.groupUuidToGroupMembershipCount.keySet()) {
// already accounted for
if (groupUuidsToDelete.contains(groupUuid)) {
continue;
}
int currentCount = this.groupUuidToGroupMembershipCount.get(groupUuid);
currentCount += GrouperUtil.intValue(groupUuidToMembershipAddCount.get(groupUuid), 0);
currentCount -= GrouperUtil.intValue(groupUuidToMembershipDeleteCount.get(groupUuid), 0);
// not sure why it would be less than zero but...
if (currentCount <= 0) {
groupUuidsToDelete.add(groupUuid);
}
}
if (this.grouperFailsafeBean.shouldAbortDueToTooManyGroupListManagedGroupsBeingCleared(this.groupCountWithMembers, groupUuidsToDelete.size())) {
this.getGrouperProvisioner().getGcGrouperSyncLog().setStatus(GcGrouperSyncLogState.ERROR_FAILSAFE);
GrouperFailsafe.assignFailed(this.grouperFailsafeBean.getJobName());
this.grouperFailsafeBean.notifyEmailAboutFailsafe();
throw new OtherJobException(GrouperLoaderStatus.ERROR_FAILSAFE, "Can't clear out "
+ groupUuidsToDelete.size() + " groups (totalManagedGroupsWithMembersCount: "
+ this.groupCountWithMembers + ")"
+ " unless data problem is fixed, failsafe is approved, or failsafe settings changed" );
}
}
}
/**
* see if there is a failsafe issue and throw a failsafe error
*/
public void processFailsafesAtStart() {
String jobName = this.getGrouperProvisioner().getJobName();
if (StringUtils.isBlank(jobName)) {
return;
}
processFailsafesSetupBean();
processFailsafesFailIncrementalIfFullFailsafeIssue();
}
/**
*
*/
public void processFailsafesFailIncrementalIfFullFailsafeIssue() {
// if we are incremental, and there is a failsafe issue, then dont even try...
if (this.getGrouperProvisioner().retrieveGrouperProvisioningBehavior().getGrouperProvisioningType().isIncrementalSync()) {
for (String theJobName : GrouperUtil.nonNull(this.getGrouperProvisioner().getJobNames())) {
if (!GrouperFailsafe.isApproved(theJobName) && GrouperFailsafe.isFailsafeIssue(theJobName)) {
this.grouperFailsafeBean.setJobName(theJobName);
this.grouperFailsafeBean.notifyEmailAboutFailsafe();
throw new RuntimeException("Failsafe error from '" + theJobName + "' prevents the incremental from running");
}
}
}
}
/**
*
*/
private Map groupUuidToGroupMembershipCount = null;
/**
* @return group to membership count
*/
public Map getGroupUuidToGroupMembershipCount() {
return this.groupUuidToGroupMembershipCount;
}
/**
* only call this with groups that have removes... so call this after compare...
*/
public void processFailsafesSetupGroupTotals() {
if (this.groupUuidToGroupMembershipCount == null) {
this.groupUuidToGroupMembershipCount = new HashMap();
Map groupUuidToMembershipDeleteCount = this.getGrouperProvisioner().retrieveGrouperProvisioningCompare().getGroupUuidToMembershipDeleteCount();
if (GrouperUtil.length(groupUuidToMembershipDeleteCount) > 0) {
int batchSize = 900;
int numberOfBatches = GrouperUtil.batchNumberOfBatches(groupUuidToMembershipDeleteCount.size(), batchSize);
List uuids = new ArrayList(groupUuidToMembershipDeleteCount.keySet());
for (int i=0;i batchUuids = GrouperUtil.batchList(uuids, batchSize, i);
// we need to full count of the group... lets try to do that in few queries
GcDbAccess gcDbAccess = new GcDbAccess().sql("select gsg.group_id, count(*) from grouper_sync_group gsg, grouper_sync_membership gsm "
+ " where gsg.id = gsm.grouper_sync_group_id and gsm.in_target = 'T' and gsg.grouper_sync_id = ? and gsg.group_id in ("
+ GrouperClientUtils.appendQuestions(GrouperUtil.length(batchUuids)) + ") group by gsg.group_id ");
gcDbAccess.addBindVar(this.getGrouperProvisioner().getGcGrouperSync().getId());
for (String batchUuid : batchUuids) {
gcDbAccess.addBindVar(batchUuid);
}
List