Skip to content

Commit

Permalink
Fix with deltaCacheKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Aug 3, 2016
1 parent c5aab2f commit 912b646
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 63 deletions.
Expand Up @@ -42,7 +42,7 @@ public final class DeltaCacheKey implements Serializable {
// indicates that client want to receive resync based on base schema
private final boolean resyncOnly;

private final boolean useRawSchema;
private final boolean useConfigurationRawSchema;

private final EndpointObjectHash userConfHash;

Expand All @@ -53,17 +53,17 @@ public DeltaCacheKey(AppVersionKey appConfigVersionKey, List<EndpointGroupStateD
}

public DeltaCacheKey(AppVersionKey appConfigVersionKey, List<EndpointGroupStateDto> endpointGroups, EndpointObjectHash userConfHash,
EndpointObjectHash endpointConfHash, boolean useRawSchema) {
this(appConfigVersionKey, endpointGroups, userConfHash, endpointConfHash, useRawSchema, false);
EndpointObjectHash endpointConfHash, boolean useConfigurationRawSchema) {
this(appConfigVersionKey, endpointGroups, userConfHash, endpointConfHash, useConfigurationRawSchema, false);
}

public DeltaCacheKey(AppVersionKey appConfigVersionKey, List<EndpointGroupStateDto> endpointGroups,
EndpointObjectHash userConfHash, EndpointObjectHash endpointConfHash, boolean useRawSchema, boolean resyncOnly) {
EndpointObjectHash userConfHash, EndpointObjectHash endpointConfHash, boolean useConfigurationRawSchema, boolean resyncOnly) {
this.appConfigVersionKey = appConfigVersionKey;
this.userConfHash = userConfHash;
this.endpointGroups = endpointGroups;
this.endpointConfHash = endpointConfHash;
this.useRawSchema = useRawSchema;
this.useConfigurationRawSchema = useConfigurationRawSchema;
this.resyncOnly = resyncOnly;

}
Expand Down Expand Up @@ -93,70 +93,42 @@ public boolean isResyncOnly() {
return resyncOnly;
}

public boolean isUseRawSchema() {
return useRawSchema;
public boolean isUseConfigurationRawSchema() {
return useConfigurationRawSchema;
}

public EndpointObjectHash getUserConfHash() {
return userConfHash;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((appConfigVersionKey == null) ? 0 : appConfigVersionKey.hashCode());
result = prime * result + ((endpointConfHash == null) ? 0 : endpointConfHash.hashCode());
result = prime * result + ((endpointGroups == null) ? 0 : endpointGroups.hashCode());
result = prime * result + (resyncOnly ? 1231 : 1237);
result = prime * result + ((userConfHash == null) ? 0 : userConfHash.hashCode());
return result;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
DeltaCacheKey other = (DeltaCacheKey) obj;
if (appConfigVersionKey == null) {
if (other.appConfigVersionKey != null) {
return false;
}
} else if (!appConfigVersionKey.equals(other.appConfigVersionKey)) {
return false;
}
if (endpointConfHash == null) {
if (other.endpointConfHash != null) {
return false;
}
} else if (!endpointConfHash.equals(other.endpointConfHash)) {
return false;
}
if (endpointGroups == null) {
if (other.endpointGroups != null) {
return false;
}
} else if (!endpointGroups.equals(other.endpointGroups)) {
DeltaCacheKey that = (DeltaCacheKey) o;

if (resyncOnly != that.resyncOnly) return false;
if (useConfigurationRawSchema != that.useConfigurationRawSchema) return false;
if (appConfigVersionKey != null ? !appConfigVersionKey.equals(that.appConfigVersionKey) : that.appConfigVersionKey != null)
return false;
}
if (resyncOnly != other.resyncOnly) {
if (endpointGroups != null ? !endpointGroups.equals(that.endpointGroups) : that.endpointGroups != null)
return false;
}
if (userConfHash == null) {
if (other.userConfHash != null) {
return false;
}
} else if (!userConfHash.equals(other.userConfHash)) {
if (endpointConfHash != null ? !endpointConfHash.equals(that.endpointConfHash) : that.endpointConfHash != null)
return false;
}
return true;
return userConfHash != null ? userConfHash.equals(that.userConfHash) : that.userConfHash == null;

}

@Override
public int hashCode() {
int result = appConfigVersionKey != null ? appConfigVersionKey.hashCode() : 0;
result = 31 * result + (endpointGroups != null ? endpointGroups.hashCode() : 0);
result = 31 * result + (endpointConfHash != null ? endpointConfHash.hashCode() : 0);
result = 31 * result + (resyncOnly ? 1 : 0);
result = 31 * result + (useConfigurationRawSchema ? 1 : 0);
result = 31 * result + (userConfHash != null ? userConfHash.hashCode() : 0);
return result;
}

@Override
Expand All @@ -170,6 +142,8 @@ public String toString() {
builder.append(endpointConfHash);
builder.append(", resyncOnly=");
builder.append(resyncOnly);
builder.append(", useRawSchema=");
builder.append(useConfigurationRawSchema);
builder.append(", userConfHash=");
builder.append(userConfHash);
builder.append("]");
Expand Down
Expand Up @@ -89,7 +89,7 @@ public class DefaultDeltaService implements DeltaService {
@Autowired
private EndpointService endpointService;

/** The configuration merger factory. */

@Autowired
private OverrideAlgorithmFactory configurationOverrideFactory;

Expand Down Expand Up @@ -120,7 +120,7 @@ public ConfigurationCacheEntry getConfiguration(String appToken, String endpoint
LOG.debug("[{}][{}] Calculating new configuration", appToken, endpointId);
AppVersionKey appConfigVersionKey = new AppVersionKey(appToken, profile.getConfigurationVersion());
DeltaCacheKey deltaKey = new DeltaCacheKey(appConfigVersionKey, profile.getGroupState(), EndpointObjectHash.fromBytes(profile
.getUserConfigurationHash()), null, true);
.getUserConfigurationHash()), null, profile.isUseConfigurationRawSchema(), true);
LOG.debug("[{}][{}] Built resync delta key {}", appToken, endpointId, deltaKey);
return getDelta(endpointId, profile.getEndpointUserId(), deltaKey, profile.isUseConfigurationRawSchema());
}
Expand Down Expand Up @@ -188,8 +188,14 @@ private ConfigurationCacheEntry getDelta(final String endpointId, final String u

final DeltaCacheKey newKey;
if (userConfiguration != null) {
newKey = new DeltaCacheKey(deltaKey.getAppConfigVersionKey(), deltaKey.getEndpointGroups(),
EndpointObjectHash.fromString(userConfiguration.getBody()), deltaKey.getEndpointConfHash(), deltaKey.isResyncOnly());
newKey = new DeltaCacheKey(
deltaKey.getAppConfigVersionKey(),
deltaKey.getEndpointGroups(),
EndpointObjectHash.fromString(userConfiguration.getBody()),
deltaKey.getEndpointConfHash(),
useConfigurationRawSchema,
deltaKey.isResyncOnly()
);
} else {
newKey = deltaKey;
}
Expand Down Expand Up @@ -373,7 +379,7 @@ public Pair<BaseData, RawData> compute(List<EndpointGroupStateDto> key) {
return mergedConfiguration;
}

private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, String jsonData, String schema, EndpointObjectHash userConfigurationHash) throws IOException {
private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, String jsonData, String schema, EndpointObjectHash userConfigurationHash) throws IOException {
byte[] configuration = GenericAvroConverter.toRawData(jsonData, schema);
return new ConfigurationCacheEntry(configuration, new BaseBinaryDelta(configuration), EndpointObjectHash.fromSHA1(configuration),
userConfigurationHash);
Expand Down

0 comments on commit 912b646

Please sign in to comment.