Skip to content

Commit

Permalink
Fixes with use raw schema boolean variable in DeltaService
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Jul 20, 2016
1 parent 6597463 commit 35e2286
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Expand Up @@ -1076,7 +1076,7 @@ public ConfigurationSchemaDto getConfigurationSchema(@PathVariable String config
*/
@RequestMapping(value = "saveConfigurationSchema", method = RequestMethod.POST)
@ResponseBody
public ConfigurationSchemaDto createConfigurationSchema(@RequestBody ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException {
public ConfigurationSchemaDto saveConfigurationSchema(@RequestBody ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException {
return kaaAdminService.saveConfigurationSchema(configurationSchema);
}

Expand Down
Expand Up @@ -203,7 +203,8 @@ public ConfigurationCacheEntry compute(DeltaCacheKey deltaKey) {
try {
LOG.debug("[{}] Calculating delta for {}", endpointId, deltaKey);
ConfigurationCacheEntry deltaCache;
AbstractKaaData<?> kaaData;
String jsonData;
String schema;
ConfigurationSchemaDto latestConfigurationSchema = cacheService.getConfSchemaByAppAndVersion(deltaKey.getAppConfigVersionKey());

EndpointUserConfigurationDto userConfiguration = findLatestUserConfiguration(userId, deltaKey);
Expand All @@ -216,16 +217,23 @@ public ConfigurationCacheEntry compute(DeltaCacheKey deltaKey) {
BaseData mergedConfiguration = getMergedConfiguration(endpointId, userConfiguration, deltaKey, latestConfigurationSchema);

if(useConfigurationRawSchema) {
kaaData = mergedConfiguration;
} else {
// converting merged base schema to raw schema
String ctlSchema = cacheService.getFlatCtlSchemaById(latestConfigurationSchema.getCtlSchemaId());
kaaData = new RawData(new RawSchema(ctlSchema), mergedConfiguration.getRawData());
}
AbstractKaaData<?> kaaData = new RawData(new RawSchema(ctlSchema), mergedConfiguration.getRawData());
JsonNode json = new ObjectMapper().readTree(kaaData.getRawData());
AvroUtils.removeUuids(json);
jsonData = json.toString();
schema = kaaData.getSchema().getRawSchema();

LOG.trace("[{}] Merged configuration {}", endpointId, kaaData.getRawData());
} else {
AbstractKaaData<?> kaaData = mergedConfiguration;
jsonData = kaaData.getRawData();
schema = kaaData.getSchema().getRawSchema();

}

deltaCache = buildBaseResyncDelta(endpointId, kaaData, userConfigurationHash);
LOG.trace("[{}] Merged configuration {}", endpointId, jsonData);
deltaCache = buildBaseResyncDelta(endpointId, jsonData, schema, userConfigurationHash);

if (cacheService.getConfByHash(deltaCache.getHash()) == null) {
EndpointConfigurationDto newConfiguration = new EndpointConfigurationDto();
Expand Down Expand Up @@ -363,10 +371,8 @@ public BaseData compute(List<EndpointGroupStateDto> key) {
return mergedConfiguration;
}

private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, AbstractKaaData<?> mergedConf, EndpointObjectHash userConfigurationHash) throws IOException {
JsonNode json = new ObjectMapper().readTree(mergedConf.getRawData());
AvroUtils.removeUuids(json);
byte[] configuration = GenericAvroConverter.toRawData(json.toString(), mergedConf.getSchema().getRawSchema());
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 35e2286

Please sign in to comment.