Skip to content

Commit

Permalink
KAA-1279: Fixed about 50 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sashadidukh committed Sep 29, 2016
1 parent f773096 commit 7ad3702
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 80 deletions.
Expand Up @@ -45,7 +45,7 @@ private AvroUtils() {
* *
* @return list of generated bytes. * @return list of generated bytes.
*/ */
public static byte[] generateUUIDBytes() { public static byte[] generateUuidBytes() {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();


ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[UUID_SIZE]); ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[UUID_SIZE]);
Expand All @@ -57,7 +57,7 @@ public static byte[] generateUUIDBytes() {


public static GenericData.Fixed generateUuidObject() { public static GenericData.Fixed generateUuidObject() {
Schema avroSchema = Schema.createFixed(UUID_TYPE, null, KAA_NAMESPACE, UUID_SIZE); Schema avroSchema = Schema.createFixed(UUID_TYPE, null, KAA_NAMESPACE, UUID_SIZE);
return new GenericData.Fixed(avroSchema, generateUUIDBytes()); return new GenericData.Fixed(avroSchema, generateUuidBytes());
} }


public static Schema getSchemaByType(Schema schema, Schema.Type type) { public static Schema getSchemaByType(Schema schema, Schema.Type type) {
Expand Down Expand Up @@ -122,7 +122,8 @@ private static JsonNode injectUuidsFromJsonNodes(JsonNode json, Schema schema) {
.filter(f -> !f.name().equals(UUID_FIELD)) .filter(f -> !f.name().equals(UUID_FIELD))
.forEach(f -> injectUuidsFromJsonNodes(json.get(f.name()), f.schema())); .forEach(f -> injectUuidsFromJsonNodes(json.get(f.name()), f.schema()));


boolean addressable = schema.getFields().stream().filter(f -> f.name().equals(UUID_FIELD)).findFirst().isPresent(); boolean addressable = schema.getFields().stream().filter(f -> f.name().equals(
UUID_FIELD)).findFirst().isPresent();
if (addressable) { if (addressable) {
((ObjectNode) json).put(UUID_FIELD, (Integer) null); ((ObjectNode) json).put(UUID_FIELD, (Integer) null);
} }
Expand All @@ -132,7 +133,7 @@ private static JsonNode injectUuidsFromJsonNodes(JsonNode json, Schema schema) {
.forEach(s -> injectUuidsFromJsonNodes(json.get(s.getName()), s)); .forEach(s -> injectUuidsFromJsonNodes(json.get(s.getName()), s));
break; break;
case ARRAY: case ARRAY:
json.getElements().forEachRemaining((e) -> injectUuids(e, schema.getElementType())); json.getElements().forEachRemaining((elem) -> injectUuids(elem, schema.getElementType()));
break; break;
default: default:
return json; return json;
Expand All @@ -151,8 +152,9 @@ public static void removeUuids(JsonNode json) {
} }


for (JsonNode node : json) { for (JsonNode node : json) {
if (node.isContainerNode()) if (node.isContainerNode()) {
removeUuids(node); removeUuids(node);
}
} }
} }
} }
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException; import java.io.IOException;


/** /**
* Simple container for resync delta encoded using base schema * Simple container for resync delta encoded using base schema.
* *
* @author Andrew Shvayka * @author Andrew Shvayka
*/ */
Expand Down
Expand Up @@ -27,10 +27,12 @@
public class DefaultDeltaCalculatorFactory implements DeltaCalculatorFactory { public class DefaultDeltaCalculatorFactory implements DeltaCalculatorFactory {


/* (non-Javadoc) /* (non-Javadoc)
* @see org.kaaproject.kaa.server.operations.service.delta.DeltaCalculatorFactory#createDeltaCalculator(java.lang.String) * @see org.kaaproject.kaa.server.operations.service.delta.DeltaCalculatorFactory
* #createDeltaCalculator(java.lang.String)
*/ */
@Override @Override
public DeltaCalculationAlgorithm createDeltaCalculator(ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema) { public DeltaCalculationAlgorithm createDeltaCalculator(
ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema) {
Schema protocolSchema = new Schema.Parser().parse(protocolSchemaBody.getRawSchema()); Schema protocolSchema = new Schema.Parser().parse(protocolSchemaBody.getRawSchema());
Schema baseSchema = new Schema.Parser().parse(baseDataSchema.getRawSchema()); Schema baseSchema = new Schema.Parser().parse(baseDataSchema.getRawSchema());
return new DefaultDeltaCalculationAlgorithm(protocolSchema, baseSchema); return new DefaultDeltaCalculationAlgorithm(protocolSchema, baseSchema);
Expand Down
Expand Up @@ -30,7 +30,7 @@ public interface DeltaCalculationAlgorithm {
/** /**
* Calculates delta merging new and old configurations. * Calculates delta merging new and old configurations.
* *
* @param oldConfiguration old configuration data (binary) * @param endpointConfiguration old configuration data (binary)
* @param newConfigurationBody the new configuration body (binary) * @param newConfigurationBody the new configuration body (binary)
* @return the raw binary delta * @return the raw binary delta
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
Expand All @@ -47,5 +47,6 @@ RawBinaryDelta calculate(BaseData endpointConfiguration, BaseData newConfigurati
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
* @throws DeltaCalculatorException the delta calculator exception * @throws DeltaCalculatorException the delta calculator exception
*/ */
RawBinaryDelta calculate(BaseData newConfigurationBody) throws IOException, DeltaCalculatorException; RawBinaryDelta calculate(BaseData newConfigurationBody)
throws IOException, DeltaCalculatorException;
} }
Expand Up @@ -32,6 +32,7 @@ public interface DeltaCalculatorFactory {
* @param baseDataSchema base the schema body * @param baseDataSchema base the schema body
* @return the delta calculator * @return the delta calculator
*/ */
DeltaCalculationAlgorithm createDeltaCalculator(ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema); DeltaCalculationAlgorithm createDeltaCalculator(
ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema);


} }
Expand Up @@ -46,7 +46,6 @@ public ConfigurationGenerationException(String message) {


/** /**
* Constructs a new configuration processing exception. * Constructs a new configuration processing exception.
* <p>
* Note that the detail message associated with {@code cause} is <i>not</i> * Note that the detail message associated with {@code cause} is <i>not</i>
* automatically incorporated in this exception's detail message. * automatically incorporated in this exception's detail message.
* *
Expand Down
Expand Up @@ -52,5 +52,6 @@ public interface DefaultRecordGenerationAlgorithm<T extends KaaData> {
* @return the configuration by name * @return the configuration by name
* @throws ConfigurationGenerationException the configuration processing exception * @throws ConfigurationGenerationException the configuration processing exception
*/ */
GenericRecord getConfigurationByName(String name, String namespace) throws ConfigurationGenerationException; GenericRecord getConfigurationByName(String name, String namespace)
throws ConfigurationGenerationException;
} }
Expand Up @@ -43,14 +43,17 @@


/** /**
* Default implementation of * Default implementation of
* {@link org.kaaproject.kaa.server.common.dao.configuration.DefaultRecordGenerationAlgorithm} * {@link
* org.kaaproject.kaa.server.common.core.algorithms.generation.DefaultRecordGenerationAlgorithm}
*/ */
public class DefaultRecordGenerationAlgorithmImpl<U extends KaaSchema, T extends KaaData<U>> implements DefaultRecordGenerationAlgorithm<T> { public class DefaultRecordGenerationAlgorithmImpl<U extends KaaSchema, T extends KaaData<U>>
implements DefaultRecordGenerationAlgorithm<T> {


/** /**
* The Constant LOG. * The Constant LOG.
*/ */
private static final Logger LOG = LoggerFactory.getLogger(DefaultRecordGenerationAlgorithmImpl.class); private static final Logger LOG = LoggerFactory.getLogger(
DefaultRecordGenerationAlgorithmImpl.class);


/** /**
* The processed types. * The processed types.
Expand Down Expand Up @@ -83,8 +86,10 @@ public class DefaultRecordGenerationAlgorithmImpl<U extends KaaSchema, T extends
* @param kaaSchema the base schema * @param kaaSchema the base schema
* @throws ConfigurationGenerationException the configuration processing exception * @throws ConfigurationGenerationException the configuration processing exception
*/ */
public DefaultRecordGenerationAlgorithmImpl(U kaaSchema, KaaDataFactory<U, T> factory) throws ConfigurationGenerationException { public DefaultRecordGenerationAlgorithmImpl(U kaaSchema, KaaDataFactory<U, T> factory)
LOG.debug("Generating default configuration for configuration schema: " + kaaSchema.getRawSchema()); throws ConfigurationGenerationException {
LOG.debug("Generating default configuration for configuration schema: "
+ kaaSchema.getRawSchema());


this.rootSchema = kaaSchema; this.rootSchema = kaaSchema;
this.dataFactory = factory; this.dataFactory = factory;
Expand All @@ -101,7 +106,8 @@ public DefaultRecordGenerationAlgorithmImpl(U kaaSchema, KaaDataFactory<U, T> fa
* @return generated value. * @return generated value.
* @throws ConfigurationGenerationException the configuration processing exception. * @throws ConfigurationGenerationException the configuration processing exception.
*/ */
private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault) throws ConfigurationGenerationException { private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault)
throws ConfigurationGenerationException {
if (byDefault.isArray() && AvroUtils.getSchemaByType(schemaNode, Type.BYTES) != null) { if (byDefault.isArray() && AvroUtils.getSchemaByType(schemaNode, Type.BYTES) != null) {
// if this is a 'bytes' type then convert json bytes array to // if this is a 'bytes' type then convert json bytes array to
// avro 'bytes' representation or // avro 'bytes' representation or
Expand Down Expand Up @@ -142,7 +148,8 @@ private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault) throws C
return byDefault.asText(); return byDefault.asText();
} }
} }
throw new ConfigurationGenerationException("Default value " + byDefault.toString() + " is not applicable for the field"); throw new ConfigurationGenerationException("Default value " + byDefault.toString()
+ " is not applicable for the field");
} }


/** /**
Expand All @@ -153,7 +160,8 @@ private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault) throws C
* @return generated value for input type. * @return generated value for input type.
* @throws ConfigurationGenerationException configuration processing exception * @throws ConfigurationGenerationException configuration processing exception
*/ */
private Object processType(Schema schemaNode, JsonNode byDefault) throws ConfigurationGenerationException { private Object processType(Schema schemaNode, JsonNode byDefault)
throws ConfigurationGenerationException {
if (byDefault != null && !byDefault.isNull()) { if (byDefault != null && !byDefault.isNull()) {
return applyDefaultValue(schemaNode, byDefault); return applyDefaultValue(schemaNode, byDefault);
} }
Expand Down Expand Up @@ -239,7 +247,8 @@ private Object processArray() {
* @return generated value for input enum type. * @return generated value for input enum type.
*/ */
private Object processEnum(Schema schemaNode) { private Object processEnum(Schema schemaNode) {
GenericEnumSymbol result = new GenericData.EnumSymbol(schemaNode, schemaNode.getEnumSymbols().get(0)); GenericEnumSymbol result = new GenericData.EnumSymbol(schemaNode,
schemaNode.getEnumSymbols().get(0));
return result; return result;
} }


Expand Down Expand Up @@ -279,32 +288,31 @@ private Object processField(Field fieldDefinition) throws ConfigurationGeneratio
} }


/* (non-Javadoc) /* (non-Javadoc)
* @see org.kaaproject.kaa.server.common.dao.configuration.ConfigurationProcessor#getRootConfiguration()
*/ */
@Override @Override
public final GenericRecord getRootConfiguration() throws ConfigurationGenerationException { public final GenericRecord getRootConfiguration() throws ConfigurationGenerationException {
return getConfigurationByName(avroBaseSchema.getName(), avroBaseSchema.getNamespace()); return getConfigurationByName(avroBaseSchema.getName(), avroBaseSchema.getNamespace());
} }


/* (non-Javadoc) /* (non-Javadoc)
* @see org.kaaproject.kaa.server.common.dao.configuration.ConfigurationProcessor#getRootJsonConfiguration()
*/ */
@Override @Override
public final T getRootData() throws IOException, ConfigurationGenerationException { public final T getRootData() throws IOException, ConfigurationGenerationException {
GenericRecord root = getRootConfiguration(); GenericRecord root = getRootConfiguration();
GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(root.getSchema()); GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(root.getSchema());
try { try {
return dataFactory.createData(rootSchema, converter.encodeToJson(root)); return dataFactory.createData(rootSchema, converter.encodeToJson(root));
} catch (RuntimeException e) { } catch (RuntimeException ex) {
// NPE is thrown if "null" was written into a field that is not nullable // NPE is thrown if "null" was written into a field that is not nullable
// CGE is thrown if value of wrong type was written into a field // CGE is thrown if value of wrong type was written into a field
LOG.error("Unexpected exception occurred while generating configuration.", e); LOG.error("Unexpected exception occurred while generating configuration.", ex);
throw new ConfigurationGenerationException(e); throw new ConfigurationGenerationException(ex);
} }
} }


@Override @Override
public final GenericRecord getConfigurationByName(String name, String namespace) throws ConfigurationGenerationException { public final GenericRecord getConfigurationByName(String name, String namespace)
throws ConfigurationGenerationException {
if (name == null || namespace == null) { if (name == null || namespace == null) {
return null; return null;
} }
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class ArrayOverrideStrategyResolver {
/** /**
* Instantiates a new array merge strategy resolver. * Instantiates a new array merge strategy resolver.
* *
* @param configurationSchema the configuration schema * @param types the configuration schema types
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
public ArrayOverrideStrategyResolver(Map<String, Schema> types) throws IOException { public ArrayOverrideStrategyResolver(Map<String, Schema> types) throws IOException {
Expand All @@ -52,15 +52,18 @@ public ArrayOverrideStrategyResolver(Map<String, Schema> types) throws IOExcepti
/** /**
* Resolve. * Resolve.
* *
* @param parent the parent * @param name the parent name
* @param childName the child name * @param namespace the namespace
* @param childName the child name
* @return the array merge strategy * @return the array merge strategy
* @throws OverrideException the merge exception * @throws OverrideException the merge exception
*/ */
public ArrayOverrideStrategy resolve(String name, String namespace, String childName) throws OverrideException { public ArrayOverrideStrategy resolve(String name, String namespace, String childName)
throws OverrideException {
Schema schemaForParent = schemaTypes.get(namespace + "." + name); Schema schemaForParent = schemaTypes.get(namespace + "." + name);
if (schemaForParent == null) { if (schemaForParent == null) {
throw new OverrideException(MessageFormat.format("Failed to find Schema with Name ''{0}'' and namespace ''{1}''", name, namespace)); throw new OverrideException(MessageFormat.format(
"Failed to find Schema with Name ''{0}'' and namespace ''{1}''", name, namespace));
} }
String mergeStrategyName = findMergeStrategy(schemaForParent, childName); String mergeStrategyName = findMergeStrategy(schemaForParent, childName);


Expand Down

0 comments on commit 7ad3702

Please sign in to comment.