Skip to content

Commit

Permalink
Merge a2c96fd into 6f5cd4a
Browse files Browse the repository at this point in the history
  • Loading branch information
RongtongJin committed Jul 13, 2022
2 parents 6f5cd4a + a2c96fd commit b48fae6
Show file tree
Hide file tree
Showing 600 changed files with 56,439 additions and 7,480 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -7,7 +7,7 @@ notifications:
if: branch = develop OR branch = master
on_success: change
on_failure: always


language: java

Expand Down Expand Up @@ -48,7 +48,7 @@ before_script:
- ulimit -c unlimited

script:
- mvn -B verify -DskipTests
- mvn verify -DskipTests
- travis_retry mvn -B clean apache-rat:check
- travis_retry mvn -B install jacoco:report coveralls:report
- travis_retry mvn -B clean install -pl test -Pit-test
Expand Down
2 changes: 1 addition & 1 deletion acl/pom.xml
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-all</artifactId>
<version>4.9.5-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>rocketmq-acl</artifactId>
<name>rocketmq-acl ${project.version}</name>
Expand Down
39 changes: 39 additions & 0 deletions acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
Expand Up @@ -20,9 +20,11 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.channels.FileChannel;
import java.util.Map;
import java.util.SortedMap;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -274,6 +276,43 @@ public static boolean writeDataObject(String path, Map<String, Object> dataMap)
return true;
}

public static boolean copyFile(String from, String to) {
FileChannel input = null;
FileChannel output = null;
try {
input = new FileInputStream(new File(from)).getChannel();
output = new FileOutputStream(new File(to)).getChannel();
output.transferFrom(input, 0, input.size());
return true;
} catch (Exception e) {
log.error("file copy error. from={}, to={}", from, to, e);
} finally {
closeFileChannel(input);
closeFileChannel(output);
}
return false;
}

public static boolean moveFile(String from, String to) {
try {
File file = new File(from);
return file.renameTo(new File(to));
} catch (Exception e) {
log.error("file move error. from={}, to={}", from, to, e);
}
return false;
}

private static void closeFileChannel(FileChannel fileChannel) {
if (fileChannel != null) {
try {
fileChannel.close();
} catch (IOException e) {
log.error("Close file channel error.", e);
}
}
}

public static RPCHook getAclRPCHook(String fileName) {
JSONObject yamlDataObject = null;
try {
Expand Down
21 changes: 21 additions & 0 deletions acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
Expand Up @@ -311,4 +311,25 @@ public void getAclRPCHookTest() {
Assert.assertNull(incompleteContRPCHook);
}

@Test
public void testCopyAndMoveFile() {
String path = "src/test/resources/conf/plain_acl.yml";
String backupPath = "src/test/resources/conf/plain_acl.yml_backup";
Map<String, Object> aclYamlData = AclUtils.getYamlDataObject(path, Map.class);

AclUtils.copyFile(path, backupPath);
Assert.assertEquals(aclYamlData, AclUtils.getYamlDataObject(backupPath, Map.class));

Map<String, Object> aclYamlMap = new HashMap<String, Object>();
List<String> globalWhiteRemoteAddrs = new ArrayList<String>();
globalWhiteRemoteAddrs.add("10.10.103.*");
globalWhiteRemoteAddrs.add("192.168.0.*");
aclYamlMap.put("globalWhiteRemoteAddrs", globalWhiteRemoteAddrs);
AclUtils.writeDataObject(path, aclYamlMap);
Assert.assertNotEquals(aclYamlData, AclUtils.getYamlDataObject(path, Map.class));

AclUtils.moveFile(backupPath, path);
Assert.assertEquals(aclYamlData, AclUtils.getYamlDataObject(path, Map.class));
}

}
5 changes: 0 additions & 5 deletions acl/src/test/resources/conf/plain_acl.yml
Expand Up @@ -18,7 +18,6 @@
globalWhiteRemoteAddresses:
- 10.10.103.*
- 192.168.0.*

accounts:
- accessKey: RocketMQ
secretKey: 12345678
Expand All @@ -31,14 +30,10 @@ accounts:
- topicB=PUB|SUB
- topicC=SUB
groupPerms:
# the group should convert to retry topic
- groupA=DENY
- groupB=SUB
- groupC=SUB

- accessKey: rocketmq2
secretKey: 12345678
whiteRemoteAddress: 192.168.1.*
# if it is admin, it could access all resources
admin: true

10 changes: 9 additions & 1 deletion broker/pom.xml
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-all</artifactId>
<version>4.9.5-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -50,6 +50,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>rocketmq-acl</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand All @@ -70,6 +74,10 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.concurrentlinkedhashmap</groupId>
<artifactId>concurrentlinkedhashmap-lru</artifactId>
</dependency>
</dependencies>

<build>
Expand Down

0 comments on commit b48fae6

Please sign in to comment.