zyxxoo commented on code in PR #2615: URL: https://github.com/apache/incubator-hugegraph/pull/2615#discussion_r1716234402
########## hugegraph-it/hg-it-minicluster/src/main/java/org/apache/hugegraph/it/node/AbstractNodeWrapper.java: ########## @@ -0,0 +1,174 @@ +/* + * 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.hugegraph.it.node; + +import static org.apache.hugegraph.it.base.ClusterConstant.IT_LOG_PATH; +import static org.apache.hugegraph.it.base.ClusterConstant.TARGET; +import static org.apache.hugegraph.it.base.ClusterConstant.TEMPLATE_NODE_DIR; +import static org.apache.hugegraph.it.base.ClusterConstant.USER_DIR; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Properties; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.file.PathUtils; +import org.apache.hugegraph.it.base.HGTestLogger; +import org.slf4j.Logger; + +public abstract class AbstractNodeWrapper implements BaseNodeWrapper { + + protected static final Logger LOG = HGTestLogger.LOG; + + protected final String host; + protected final int port; + protected final Properties properties = new Properties(); + protected final long startTime; + protected int clusterIndex; + protected String workPath; + protected String configPath; + protected Process instance; + protected int cnt; + + public AbstractNodeWrapper() { + this.startTime = System.currentTimeMillis(); + this.clusterIndex = 1; + this.host = "127.0.0.1"; + this.port = 8086; + } + + protected AbstractNodeWrapper(String host, int port, int clusterIndex, int cnt) { + this.host = host; + this.port = port; + this.clusterIndex = clusterIndex; + this.startTime = System.currentTimeMillis(); + this.cnt = cnt; + } + + /** + * Node Dir should be created before changing Config + */ + @Override + public void createNodeDir() { + String destDir = getNodePath(); + try { + try { + if (new File(destDir).exists()) { + PathUtils.delete(Paths.get(destDir)); + } + } catch (NoSuchFileException fileException) { + //no need to handle + } + // To avoid following symbolic links + try (Stream<Path> stream = Files.walk(Paths.get(TEMPLATE_NODE_DIR))) { + stream.forEach( + source -> { + Path destination = + Paths.get(destDir, + source.toString() + .substring(TEMPLATE_NODE_DIR.length())); + try { + Files.copy(source, + destination, + LinkOption.NOFOLLOW_LINKS, + StandardCopyOption.COPY_ATTRIBUTES); + } catch (IOException ioException) { + LOG.error("Fail to copy files to node dest dir", ioException); + throw new RuntimeException(ioException); + } + } + ); + } + } catch (IOException ioException) { + LOG.error("Got error copying files to node dest dir", ioException); + throw new AssertionError(); + } + } + + @Override + public void createLogDir() { + String logPath = getLogPath(); + try { + FileUtils.createParentDirectories(new File(logPath)); + } catch (IOException e) { + LOG.error("Create log dir failed", e); + throw new AssertionError(); + } + } + + public void deleteDir() { + try { + PathUtils.deleteDirectory(Paths.get(getNodePath())); + } catch (IOException ex) { + try { + TimeUnit.SECONDS.sleep(1); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + ex.printStackTrace(); + throw new AssertionError("Delete node dir failed. " + e); + } + } + } + + /** + * @return (user.dir).target.id + */ + public String getNodePath() { + return System.getProperty(USER_DIR) + File.separator + TARGET + File.separator + Review Comment: the method style should be dependency injection, as above talk, these config should come from clusterEnv ########## hugegraph-it/hg-it-minicluster/src/main/java/org/apache/hugegraph/it/env/AbstractEnv.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.hugegraph.it.env; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.hugegraph.it.base.HGTestLogger; +import org.apache.hugegraph.it.config.ClusterConf; +import org.apache.hugegraph.it.config.ClusterConfImpl; +import org.apache.hugegraph.it.node.PDNodeWrapper; +import org.apache.hugegraph.it.node.ServerNodeWrapper; +import org.apache.hugegraph.it.node.StoreNodeWrapper; +import org.slf4j.Logger; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public abstract class AbstractEnv implements BaseEnv { + + private static final Logger LOG = HGTestLogger.LOG; + private final ClusterConf clusterConf; + protected List<PDNodeWrapper> pdNodeWrappers; + protected List<ServerNodeWrapper> serverNodeWrappers; + protected List<StoreNodeWrapper> storeNodeWrappers; + protected int cluster_id = 0; + + public AbstractEnv() { + this.clusterConf = new ClusterConfImpl(); + this.pdNodeWrappers = new ArrayList<>(); + this.serverNodeWrappers = new ArrayList<>(); + this.storeNodeWrappers = new ArrayList<>(); + } + + protected void addPDNode(PDNodeWrapper pdNodeWrapper) { + this.pdNodeWrappers.add(pdNodeWrapper); + } + + protected void addStoreNode(StoreNodeWrapper storeNodeWrapper) { + this.storeNodeWrappers.add(storeNodeWrapper); + } + + protected void addServerNode(ServerNodeWrapper serverNodeWrapper) { + this.serverNodeWrappers.add(serverNodeWrapper); + } + + @Override + public void initCluster() { Review Comment: i am confuse for the method behavior, i understand the ClusterConf hold the config information, the clusterEnv hold the clusterConf and expose configuration lookup function, but I feel the pdNodeWraper or serverNodeWrapper should't place the class, they maybe place in like a HugeClusterFacade class, the main class have start method, and init method, the init method init the wrapper by clusterEnv params, and the start method call each start method of wrappers; ########## hugegraph-it/hg-it-minicluster/src/main/java/org/apache/hugegraph/it/node/BaseNodeWrapper.java: ########## @@ -0,0 +1,35 @@ +/* + * 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.hugegraph.it.node; + +public interface BaseNodeWrapper { + + void createNodeDir(); Review Comment: i can't think these method are needed sometimes, i am confused, what is the responsibility of the wrapper class's; if i can't understand wrong, i think the createNodeDir or createLogDir, deleteDir method are the spec impl logic, their should been call in the wrap inner in the different lifecycle. don't need expose for other class call ########## hugegraph-it/hg-it-minicluster/src/main/java/org/apache/hugegraph/it/node/AbstractNodeWrapper.java: ########## @@ -0,0 +1,174 @@ +/* + * 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.hugegraph.it.node; + +import static org.apache.hugegraph.it.base.ClusterConstant.IT_LOG_PATH; +import static org.apache.hugegraph.it.base.ClusterConstant.TARGET; +import static org.apache.hugegraph.it.base.ClusterConstant.TEMPLATE_NODE_DIR; +import static org.apache.hugegraph.it.base.ClusterConstant.USER_DIR; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Properties; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.file.PathUtils; +import org.apache.hugegraph.it.base.HGTestLogger; +import org.slf4j.Logger; + +public abstract class AbstractNodeWrapper implements BaseNodeWrapper { + + protected static final Logger LOG = HGTestLogger.LOG; + + protected final String host; + protected final int port; + protected final Properties properties = new Properties(); + protected final long startTime; + protected int clusterIndex; + protected String workPath; + protected String configPath; + protected Process instance; + protected int cnt; + + public AbstractNodeWrapper() { + this.startTime = System.currentTimeMillis(); Review Comment: maybe this place call this("127.0.0.1", 8086, 1, 1) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
