Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void addCheckedConstraints(Map<PrivacyLevel,LongAdder> checkedCons
}

/**
* Add an occurence of the given privacy level to the loaded constraints log total.
* Add an occurrence of the given privacy level to the loaded constraints log total.
* @param level privacy level from loaded privacy constraint
*/
public static void addLoadedConstraint(PrivacyLevel level){
Expand Down Expand Up @@ -84,9 +84,9 @@ public static Map<PrivacyLevel, LongAdder> getLoadedConstraints(){
public static String display(){
StringBuilder sb = new StringBuilder();
sb.append("Checked Privacy Constraints:\n");
checkedConstraintsTotal.forEach((k,v)->sb.append("\t" + k + ": " + v + "\n"));
checkedConstraintsTotal.forEach((k,v)-> sb.append(String.format("\t%s: %s\n", k, v)));
sb.append("Loaded Privacy Constraints:\n");
loadedConstraintsTotal.forEach((k,v)->sb.append("\t" + k + ": " + v + "\n"));
loadedConstraintsTotal.forEach((k,v)->sb.append(String.format("\t%s: %s\n", k, v)));
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ else if ( hasFineGrainedConstraints() ){
/**
* Get privacy constraints and put them into JSON object.
* @param json JSON object in which the privacy constraints are put
* @return JSON object including the privacy constraints
* @throws JSONException in case of errors in creating JSON object
* @throws JSONException in case of errors in putting into JSON object
*/
public JSONObject toJson(JSONObject json) throws JSONException {
public void toJson(JSONObject json) throws JSONException {
if ( getPrivacyLevel() != null && getPrivacyLevel() != PrivacyLevel.None )
json.put(DataExpression.PRIVACY, getPrivacyLevel().name());
if ( hasFineGrainedConstraints() ) {
Expand All @@ -161,7 +160,6 @@ public JSONObject toJson(JSONObject json) throws JSONException {
rangesJson.put(PrivacyLevel.PrivateAggregation.name(), aggregateRangesJson);
json.put(DataExpression.FINE_GRAINED_PRIVACY, rangesJson);
}
return json;
}

private static JSONArray getJsonArray(DataRange[] ranges) throws JSONException {
Expand All @@ -185,7 +183,7 @@ public void readExternal(ObjectInput is) throws IOException {
int fineGrainedConstraintLength = is.readInt();
if ( fineGrainedConstraintLength > 0 ){
for (int i = 0; i < fineGrainedConstraintLength; i++){
Integer levelIndex = (Integer) is.readInt();
int levelIndex = is.readInt();
PrivacyLevel rangePrivacy = PrivacyLevel.values()[levelIndex];
DataRange dataRange = readExternalDataRangeObject(is);
fineGrainedPrivacy.put(dataRange, rangePrivacy);
Expand All @@ -198,9 +196,9 @@ public void writeExternal(ObjectOutput objectOutput) throws IOException {
objectOutput.writeInt(getPrivacyLevel().ordinal());

if (fineGrainedPrivacy != null && fineGrainedPrivacy.hasConstraints()){
List<Entry<DataRange,PrivacyLevel>> finegrainedConstraints = fineGrainedPrivacy.getAllConstraintsList();
objectOutput.writeInt(finegrainedConstraints.size());
for ( Entry<DataRange,PrivacyLevel> constraint : finegrainedConstraints ) {
List<Entry<DataRange,PrivacyLevel>> fineGrainedConstraints = fineGrainedPrivacy.getAllConstraintsList();
objectOutput.writeInt(fineGrainedConstraints.size());
for ( Entry<DataRange,PrivacyLevel> constraint : fineGrainedConstraints ) {
objectOutput.writeInt(constraint.getValue().ordinal());
DataRange dataRange = constraint.getKey();
objectOutput.writeInt(dataRange.getBeginDims().length);
Expand All @@ -217,7 +215,7 @@ public void writeExternal(ObjectOutput objectOutput) throws IOException {
* Reads a DataRange from ObjectInput.
* @param is ObjectInput from which the DataRange is read
* @return DataRange from ObjectInput
* @throws IOException
* @throws IOException if an I/O error occurs during read
*/
private static DataRange readExternalDataRangeObject(ObjectInput is) throws IOException {
int dimLength = is.readInt();
Expand All @@ -231,7 +229,7 @@ private static DataRange readExternalDataRangeObject(ObjectInput is) throws IOEx
* @param is ObjectInput from which the long array is read
* @param dimLength length of input long array
* @return the input array as a long array
* @throws IOException
* @throws IOException if an I/O error occurs during read
*/
private static long[] readExternalDataRangeDim(ObjectInput is, int dimLength) throws IOException {
long[] dims = new long[dimLength];
Expand All @@ -245,7 +243,7 @@ private static long[] readExternalDataRangeDim(ObjectInput is, int dimLength) th
* Write the long array to ObjectOutput.
* @param objectOutput ObjectOutput in which the long array is written.
* @param rangeDim long array to write in ObjectOutput.
* @throws IOException
* @throws IOException if an I/O error occurs during write
*/
private static void writeExternalRangeDim(ObjectOutput objectOutput, long[] rangeDim) throws IOException {
for ( long beginIndex : rangeDim ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class PrivacyMonitor
{
private static EnumMap<PrivacyLevel,LongAdder> checkedConstraints;
private static final EnumMap<PrivacyLevel,LongAdder> checkedConstraints;

private static boolean checkPrivacy = false;

Expand Down Expand Up @@ -71,6 +71,10 @@ private static void updateCheckedConstraintsLog(PrivacyConstraint privacyConstra
}
}

/**
* Clears all checked constraints.
* This is used to reset the counter of checked constraints for each PrivacyLevel.
*/
public static void clearCheckedConstraints(){
checkedConstraints.replaceAll((k,v)->new LongAdder());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import java.util.Arrays;

/**
* A DataRange instance marks a part of a CachableData data object.
* A DataRange instance marks a part of a CacheableData data object.
* The beginDims marks the beginning for all dimensions and
* the endDims marks the end for all dimensions.
* DataRange is very similar to org.apache.sysds.runtime.util.IndexRange,
* except that DataRange supports more than two dimensions.
*/
public class DataRange {

private long[] _beginDims;
private long[] _endDims;
private final long[] _beginDims;
private final long[] _endDims;

public DataRange(long[] beginDims, long[] endDims){
_beginDims = beginDims;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,60 @@ public interface FineGrainedPrivacy {
* @param dataRange representing the range for which the privacy is set
* @param privacyLevel the level of privacy for the given data range
*/
public void put(DataRange dataRange, PrivacyLevel privacyLevel);
void put(DataRange dataRange, PrivacyLevel privacyLevel);

public void putRow(int rowIndex, int rowLength, PrivacyLevel privacyLevel);
void putRow(int rowIndex, int rowLength, PrivacyLevel privacyLevel);

public void putCol(int colIndex, int colLength, PrivacyLevel privacyLevel);
void putCol(int colIndex, int colLength, PrivacyLevel privacyLevel);

public void putElement(int rowIndex, int colIndex, PrivacyLevel privacyLevel);
void putElement(int rowIndex, int colIndex, PrivacyLevel privacyLevel);

/**
* Get the data ranges and related privacy levels within given data search range.
* @param searchRange the range from which all privacy levels are retrieved
* @return all mappings from range to privacy level within the given search range
*/
public Map<DataRange,PrivacyLevel> getPrivacyLevel(DataRange searchRange);
Map<DataRange,PrivacyLevel> getPrivacyLevel(DataRange searchRange);

/**
* Get the data ranges and related privacy levels of the element with the given index.
* @param searchIndex index of element
* @return all mappings from range to privacy level for the given search element
*/
public Map<DataRange,PrivacyLevel> getPrivacyLevelOfElement(long[] searchIndex);
Map<DataRange,PrivacyLevel> getPrivacyLevelOfElement(long[] searchIndex);

/**
* Get all data ranges for the given privacy level.
* @param privacyLevel for which data ranges are found
* @return all data ranges with the given privacy level
*/
public DataRange[] getDataRangesOfPrivacyLevel(PrivacyLevel privacyLevel);
DataRange[] getDataRangesOfPrivacyLevel(PrivacyLevel privacyLevel);

/**
* Remove all fine-grained privacy constraints.
*/
public void removeAllConstraints();
void removeAllConstraints();

/**
* True if any fine-grained constraints has been set.
* @return true if any fine-grained constraint is set
*/
public boolean hasConstraints();
boolean hasConstraints();

/**
* Get all fine-grained constraints as a map from privacy level to
* an array of data ranges represented as two-dimensional long arrays.
* @return map from privacy level to array of data ranges
*/
public Map<String, long[][][]> getAllConstraints();
Map<String, long[][][]> getAllConstraints();

/**
* Return all fine-grained privacy constraints as an arraylist.
* @return all constraints
*/
public ArrayList<Map.Entry<DataRange, PrivacyLevel>> getAllConstraintsList();
ArrayList<Map.Entry<DataRange, PrivacyLevel>> getAllConstraintsList();

public PrivacyLevel[] getRowPrivacy(int numRows, int numCols);
PrivacyLevel[] getRowPrivacy(int numRows, int numCols);

public PrivacyLevel[] getColPrivacy(int numRows, int numCols);
PrivacyLevel[] getColPrivacy(int numRows, int numCols);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class FineGrainedPrivacyList implements FineGrainedPrivacy {

private ArrayList<Map.Entry<DataRange, PrivacyLevel>> constraintCollection = new ArrayList<>();
private final ArrayList<Map.Entry<DataRange, PrivacyLevel>> constraintCollection = new ArrayList<>();

@Override
public PrivacyLevel[] getRowPrivacy(int numRows, int numCols) {
Expand Down Expand Up @@ -142,7 +142,7 @@ else if ( constraint.getValue() == PrivacyLevel.PrivateAggregation )
});
Map<String, long[][][]> constraintMap = new HashMap<>();
constraintMap.put(PrivacyLevel.Private.name(), privateRanges.toArray(new long[0][][]));
constraintMap.put(PrivacyLevel.PrivateAggregation.name(), privateRanges.toArray(new long[0][][]));
constraintMap.put(PrivacyLevel.PrivateAggregation.name(), aggregateRanges.toArray(new long[0][][]));
return constraintMap;
}

Expand Down Expand Up @@ -177,9 +177,8 @@ private boolean listEquals(ArrayList<Map.Entry<DataRange,PrivacyLevel>> otherFGP
@Override
public String toString(){
StringBuilder stringBuilder = new StringBuilder();
for ( Map.Entry<DataRange,PrivacyLevel> entry : constraintCollection ){
stringBuilder.append(entry.getKey().toString() + " : " + entry.getValue().name());
}
for ( Map.Entry<DataRange,PrivacyLevel> entry : constraintCollection )
stringBuilder.append(String.format("%s : %s",entry.getKey().toString(), entry.getValue().name()));
return stringBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class FineGrainedPrivacyMap implements FineGrainedPrivacy {

private Map<DataRange, PrivacyLevel> constraintCollection = new LinkedHashMap<>();
private final Map<DataRange, PrivacyLevel> constraintCollection = new LinkedHashMap<>();

@Override
public void put(DataRange dataRange, PrivacyLevel privacyLevel) {
Expand Down Expand Up @@ -96,15 +96,15 @@ public boolean hasConstraints() {
public Map<String, long[][][]> getAllConstraints() {
ArrayList<long[][]> privateRanges = new ArrayList<>();
ArrayList<long[][]> aggregateRanges = new ArrayList<>();
constraintCollection.forEach((range, privacylevel) -> {
if (privacylevel == PrivacyLevel.Private)
constraintCollection.forEach((range, privacyLevel) -> {
if (privacyLevel == PrivacyLevel.Private)
privateRanges.add(new long[][] { range.getBeginDims(), range.getEndDims() });
else if (privacylevel == PrivacyLevel.PrivateAggregation)
else if (privacyLevel == PrivacyLevel.PrivateAggregation)
aggregateRanges.add(new long[][] { range.getBeginDims(), range.getEndDims() });
});
Map<String, long[][][]> constraintMap = new LinkedHashMap<>();
constraintMap.put(PrivacyLevel.Private.name(), privateRanges.toArray(new long[0][][]));
constraintMap.put(PrivacyLevel.PrivateAggregation.name(), privateRanges.toArray(new long[0][][]));
constraintMap.put(PrivacyLevel.PrivateAggregation.name(), aggregateRanges.toArray(new long[0][][]));
return constraintMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private static Instruction preprocessAppendCPInstruction(AppendCPInstruction ins
else {
MatrixBlock input1 = ec.getMatrixInput(inst.input1.getName());
MatrixBlock input2 = ec.getMatrixInput(inst.input2.getName());
Propagator propagator = null;
Propagator propagator;
if ( inst.getAppendType() == AppendCPInstruction.AppendType.RBIND )
propagator = new RBindPropagator(input1, privacyConstraints[0], input2, privacyConstraints[1]);
else if ( inst.getAppendType() == AppendCPInstruction.AppendType.CBIND )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void addCheckedConstraintsEmpty(){
public void addCheckedConstraintsSingleValue(){
EnumMap<PrivacyLevel,LongAdder> checked = getMap(PrivacyLevel.Private, 300);
CheckedConstraintsLog.addCheckedConstraints(checked);
assertTrue(CheckedConstraintsLog.getCheckedConstraints().get(PrivacyLevel.Private).longValue() == 300);
assertEquals(300, CheckedConstraintsLog.getCheckedConstraints().get(PrivacyLevel.Private).longValue());
}

@Test
Expand All @@ -64,7 +64,7 @@ public void addCheckedConstraintsTwoValues(){
CheckedConstraintsLog.addCheckedConstraints(checked);
EnumMap<PrivacyLevel,LongAdder> checked2 = getMap(PrivacyLevel.Private, 150);
CheckedConstraintsLog.addCheckedConstraints(checked2);
assertTrue(CheckedConstraintsLog.getCheckedConstraints().get(PrivacyLevel.Private).longValue() == 450);
assertEquals(450, CheckedConstraintsLog.getCheckedConstraints().get(PrivacyLevel.Private).longValue());
}

@Test
Expand All @@ -89,9 +89,9 @@ private static EnumMap<PrivacyLevel,LongAdder> getMap(PrivacyLevel level, long v

@Test
public void addLoadedConstraintsSingleValue(){
Integer n = 12;
int n = 12;
for (int i = 0; i < n; i++)
CheckedConstraintsLog.addLoadedConstraint(PrivacyLevel.Private);
assertEquals(n.longValue(), CheckedConstraintsLog.getLoadedConstraints().get(PrivacyLevel.Private).longValue());
assertEquals(n, CheckedConstraintsLog.getLoadedConstraints().get(PrivacyLevel.Private).longValue());
}
}