Skip to content

Commit ec47d0a

Browse files
authored
[AINode] Enable CI related to Timer (apache#16192)
1 parent db461ca commit ec47d0a

File tree

2 files changed

+58
-21
lines changed

2 files changed

+58
-21
lines changed

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/AINodeWrapper.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@
2222
import org.apache.iotdb.it.env.cluster.config.MppJVMConfig;
2323
import org.apache.iotdb.it.framework.IoTDBTestLogger;
2424

25+
import org.apache.commons.io.file.PathUtils;
2526
import org.slf4j.Logger;
2627

2728
import java.io.BufferedWriter;
2829
import java.io.File;
2930
import java.io.FileWriter;
3031
import java.io.IOException;
32+
import java.nio.file.Files;
33+
import java.nio.file.LinkOption;
34+
import java.nio.file.NoSuchFileException;
35+
import java.nio.file.Path;
3136
import java.nio.file.Paths;
37+
import java.nio.file.StandardCopyOption;
3238
import java.util.ArrayList;
3339
import java.util.List;
40+
import java.util.stream.Stream;
3441

3542
import static org.apache.iotdb.it.env.cluster.ClusterConstant.AI_NODE_NAME;
3643
import static org.apache.iotdb.it.env.cluster.ClusterConstant.TARGET;
@@ -51,6 +58,8 @@ public class AINodeWrapper extends AbstractNodeWrapper {
5158
private static final String PROPERTIES_FILE = "iotdb-ainode.properties";
5259
public static final String CONFIG_PATH = "conf";
5360
public static final String SCRIPT_PATH = "sbin";
61+
public static final String BUILT_IN_MODEL_PATH = "data/ainode/models/weights";
62+
public static final String CACHE_BUILT_IN_MODEL_PATH = "/tmp/data/ainode/models/weights";
5463

5564
private void replaceAttribute(String[] keys, String[] values, String filePath) {
5665
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true))) {
@@ -115,6 +124,39 @@ public void start() {
115124
},
116125
propertiesFile);
117126

127+
// copy built-in LTSM
128+
String builtInModelPath = filePrefix + File.separator + BUILT_IN_MODEL_PATH;
129+
new File(builtInModelPath).mkdirs();
130+
try {
131+
if (new File(builtInModelPath).exists()) {
132+
PathUtils.deleteDirectory(Paths.get(builtInModelPath));
133+
}
134+
} catch (NoSuchFileException e) {
135+
// ignored
136+
}
137+
try (Stream<Path> s = Files.walk(Paths.get(CACHE_BUILT_IN_MODEL_PATH))) {
138+
s.forEach(
139+
source -> {
140+
Path destination =
141+
Paths.get(
142+
builtInModelPath,
143+
source.toString().substring(CACHE_BUILT_IN_MODEL_PATH.length()));
144+
logger.info("AINode copying model weights from {} to {}", source, destination);
145+
try {
146+
Files.copy(
147+
source,
148+
destination,
149+
LinkOption.NOFOLLOW_LINKS,
150+
StandardCopyOption.COPY_ATTRIBUTES);
151+
} catch (IOException e) {
152+
logger.error("AINode got error copying model weights", e);
153+
throw new RuntimeException(e);
154+
}
155+
});
156+
} catch (Exception e) {
157+
logger.error("AINode got error copying model weights", e);
158+
}
159+
118160
// start AINode
119161
List<String> startCommand = new ArrayList<>();
120162
startCommand.add(SHELL_COMMAND);

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeModelManageIT.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
@Category({AIClusterIT.class})
5555
public class AINodeModelManageIT {
5656

57-
private static final Map<String, FakeModelInfo> BUILT_IN_MACHINE_LEARNING_MODEL_MAP =
57+
private static final Map<String, FakeModelInfo> BUILT_IN_MODEL_MAP =
5858
Stream.of(
5959
new AbstractMap.SimpleEntry<>(
6060
"arima", new FakeModelInfo("arima", "Arima", "BUILT-IN", "ACTIVE")),
@@ -77,13 +77,11 @@ public class AINodeModelManageIT {
7777
new AbstractMap.SimpleEntry<>(
7878
"gmm_hmm", new FakeModelInfo("gmm_hmm", "GmmHmm", "BUILT-IN", "ACTIVE")),
7979
new AbstractMap.SimpleEntry<>(
80-
"stray", new FakeModelInfo("stray", "Stray", "BUILT-IN", "ACTIVE")))
81-
// new AbstractMap.SimpleEntry<>(
82-
// "sundial", new FakeModelInfo("sundial", "Timer-Sundial", "BUILT-IN",
83-
// "ACTIVE")),
84-
// new AbstractMap.SimpleEntry<>(
85-
// "timer_xl", new FakeModelInfo("timer_xl", "Timer-XL", "BUILT-IN",
86-
// "ACTIVE")))
80+
"stray", new FakeModelInfo("stray", "Stray", "BUILT-IN", "ACTIVE")),
81+
new AbstractMap.SimpleEntry<>(
82+
"sundial", new FakeModelInfo("sundial", "Timer-Sundial", "BUILT-IN", "ACTIVE")),
83+
new AbstractMap.SimpleEntry<>(
84+
"timer_xl", new FakeModelInfo("timer_xl", "Timer-XL", "BUILT-IN", "ACTIVE")))
8785
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
8886

8987
@BeforeClass
@@ -203,20 +201,17 @@ private void showBuiltInModelTest(Statement statement) throws SQLException {
203201
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
204202
checkHeader(resultSetMetaData, "ModelId,ModelType,Category,State");
205203
while (resultSet.next()) {
206-
String modelId = resultSet.getString(1);
207-
if (!modelId.equals("sundial") && !modelId.equals("timer_xl")) {
208-
built_in_model_count++;
209-
FakeModelInfo modelInfo =
210-
new FakeModelInfo(
211-
resultSet.getString(1),
212-
resultSet.getString(2),
213-
resultSet.getString(3),
214-
resultSet.getString(4));
215-
assertTrue(BUILT_IN_MACHINE_LEARNING_MODEL_MAP.containsKey(modelInfo.getModelId()));
216-
assertEquals(BUILT_IN_MACHINE_LEARNING_MODEL_MAP.get(modelInfo.getModelId()), modelInfo);
217-
}
204+
built_in_model_count++;
205+
FakeModelInfo modelInfo =
206+
new FakeModelInfo(
207+
resultSet.getString(1),
208+
resultSet.getString(2),
209+
resultSet.getString(3),
210+
resultSet.getString(4));
211+
assertTrue(BUILT_IN_MODEL_MAP.containsKey(modelInfo.getModelId()));
212+
assertEquals(BUILT_IN_MODEL_MAP.get(modelInfo.getModelId()), modelInfo);
218213
}
219214
}
220-
assertEquals(BUILT_IN_MACHINE_LEARNING_MODEL_MAP.size(), built_in_model_count);
215+
assertEquals(BUILT_IN_MODEL_MAP.size(), built_in_model_count);
221216
}
222217
}

0 commit comments

Comments
 (0)