Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-24014 Introduce a way to have key-value entries in configuration #4997

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions examples/config/ignite-config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ignite {
]
}
nodeAttributes.nodeAttributes {
region.attribute = US
storage.attribute = SSD
region = US
storage = SSD
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ItLogicalTopologyTest extends ClusterPerTestIntegrationTest {
+ " port: {},\n"
+ " nodeFinder.netClusterNodes: [ {} ]\n"
+ " },\n"
+ " nodeAttributes.nodeAttributes: {region.attribute = US, storage.attribute = SSD},\n"
+ " nodeAttributes.nodeAttributes: {region = US, storage = SSD},\n"
+ " storage.profiles: {lru_rocks.engine = rocksdb, segmented_aipersist.engine = aipersist},\n"
+ " clientConnector.port: {},\n"
+ " rest.port: {},\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.apache.ignite.configuration.annotation.Config;
import org.apache.ignite.configuration.annotation.InjectedName;
import org.apache.ignite.configuration.annotation.Value;
import org.apache.ignite.configuration.annotation.InjectedValue;

/**
* Node's attribute configuration schema. User can specify any number of pairs (key, attribute) for a node through the local configuration
Expand All @@ -35,6 +35,6 @@ public class NodeAttributeConfigurationSchema {
public String name;

/** Node attribute field. */
@Value(hasDefault = true)
@InjectedValue(hasDefault = true)
ibessonov marked this conversation as resolved.
Show resolved Hide resolved
public String attribute = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,66 @@ void testSuccessfulCodeGenerationAbstractConfigurationAndItsDescendants() {
configRootConfigurationInterfaceContent.contains("extends " + getConfigurationInterfaceName(abstractRootConfigSchema).simpleName());
}

@Test
void testSuccessInjectedValueFieldCodeGeneration() {
String packageName = "org.apache.ignite.internal.configuration.processor.injectedvalue";

ClassName cls0 = ClassName.get(packageName, "ValidConfigurationSchema");

BatchCompilation batchCompile = batchCompile(cls0);

assertThat(batchCompile.getCompilationStatus()).succeededWithoutWarnings();

assertEquals(3, batchCompile.generated().size());

assertTrue(batchCompile.getBySchema(cls0).allGenerated());
}

@Test
void testMultipleInjectedValuesUnsuccessfulGeneration() {
String packageName = "org.apache.ignite.internal.configuration.processor.injectedvalue";

ClassName cls0 = ClassName.get(packageName, "MultipleInjectedValuesConfigurationSchema");

assertThrowsEx(
IllegalStateException.class,
() -> batchCompile(cls0),
"Field marked as @InjectedValue must be the only \"value\" field in the schema "
+ "org.apache.ignite.internal.configuration.processor.injectedvalue.MultipleInjectedValuesConfigurationSchema, "
+ "found: [firstValue, secondValue]"
);
}

@Test
void testValuesAndInjectedValueUnsuccessfulGeneration() {
String packageName = "org.apache.ignite.internal.configuration.processor.injectedvalue";

ClassName cls0 = ClassName.get(packageName, "ValueAndInjectedValueConfigurationSchema");

assertThrowsEx(
IllegalStateException.class,
() -> batchCompile(cls0),
"Field marked as @InjectedValue must be the only \"value\" field in the schema "
+ "org.apache.ignite.internal.configuration.processor.injectedvalue.ValueAndInjectedValueConfigurationSchema, "
+ "found: [secondValue, firstValue, thirdValue]"
);
}

@Test
void testUnsupportedFieldTypeUnsuccessfulGeneration() {
String packageName = "org.apache.ignite.internal.configuration.processor.injectedvalue";

ClassName cls0 = ClassName.get(packageName, "UnsupportedFieldTypeConfigurationSchema");

assertThrowsEx(
IllegalStateException.class,
() -> batchCompile(cls0),
"org.apache.ignite.internal.configuration.processor.injectedvalue.UnsupportedFieldTypeConfigurationSchema.firstValue "
+ "field must have one of the following types: boolean, int, long, double, String, UUID "
+ "or an array of aforementioned type."
);
}

/**
* Compile set of classes.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.configuration.processor.injectedvalue;

import org.apache.ignite.configuration.annotation.Config;
import org.apache.ignite.configuration.annotation.InjectedValue;

@Config
public class MultipleInjectedValuesConfigurationSchema {
@InjectedValue
public String firstValue;

@InjectedValue
public String secondValue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.configuration.processor.injectedvalue;

import org.apache.ignite.configuration.annotation.Config;
import org.apache.ignite.configuration.annotation.InjectedValue;

@Config
public class UnsupportedFieldTypeConfigurationSchema {
@InjectedValue
public Object firstValue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.configuration.processor.injectedvalue;

import org.apache.ignite.configuration.annotation.Config;
import org.apache.ignite.configuration.annotation.InjectedName;
import org.apache.ignite.configuration.annotation.InjectedValue;

@Config
public class ValidConfigurationSchema {
@InjectedName
public String name;

@InjectedValue
public String someValue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.configuration.processor.injectedvalue;

import org.apache.ignite.configuration.annotation.Config;
import org.apache.ignite.configuration.annotation.InjectedValue;
import org.apache.ignite.configuration.annotation.Value;

@Config
public class ValueAndInjectedValueConfigurationSchema {
@Value
public String firstValue;

@InjectedValue
public String secondValue;

@Value
public String thirdValue;
}
Loading