Skip to content

Commit

Permalink
RMS-8495: Komprise Memory leak (#618)
Browse files Browse the repository at this point in the history
* ApacheHTTP enforce TLS1.2

* Fixed every instance the profiler found

* Fix cross-jdk issue

* remove dead code
  • Loading branch information
scribe committed Sep 15, 2023
1 parent 057295b commit bf93957
Show file tree
Hide file tree
Showing 413 changed files with 528 additions and 672 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public void restoreOSName() {
* @param lastModifiedTime modified time got from server
* @param lastAccessedTime last aceess time got from server
*/
private void setFileTimes(final String filePath,
final String creationTime,
final String lastModifiedTime,
final String lastAccessedTime)
private static void setFileTimes(final String filePath,
final String creationTime,
final String lastModifiedTime,
final String lastAccessedTime)
throws IOException
{
final BasicFileAttributeView attributes = Files.getFileAttributeView(Paths.get(filePath), BasicFileAttributeView.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void restoreFileTimes() throws IOException, InterruptedException {
* @param objectName path of the object where we need to restore
* @param creationTime creation time got from server
*/
private void restoreCreationTimeMAC(final String objectName, final String creationTime) throws IOException, InterruptedException {
private static void restoreCreationTimeMAC(final String objectName, final String creationTime) throws IOException, InterruptedException {
final ProcessBuilder processBuilder = new ProcessBuilder("touch", "-t", getDate(Long.parseLong(creationTime), "YYYYMMddHHmm"), objectName);
final Process process = processBuilder.start();
//Wait to get exit value
Expand All @@ -94,7 +94,7 @@ private void restoreCreationTimeMAC(final String objectName, final String creati
* @param objectName path of the object where we need to restore
* @param modifiedTime modified time need to restore
*/
private void restoreModifiedTimeMAC(final String objectName, final String modifiedTime) throws IOException, InterruptedException {
private static void restoreModifiedTimeMAC(final String objectName, final String modifiedTime) throws IOException, InterruptedException {
final ProcessBuilder processBuilder = new ProcessBuilder("touch", "-mt", getDate(Long.parseLong(modifiedTime), "YYYYMMddHHmm"), objectName);
final Process process = processBuilder.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public Map<String, String> getMetadataValue(final String filename) {
* @param file local path of file
* @return map builder containing the data to be stored on server
*/
private ImmutableMap<String, String> storeMetaData(final Path file) throws IOException {
private static ImmutableMap<String, String> storeMetaData(final Path file) throws IOException {
final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

//get metadata store based on os type
final MetadataStore metadataStore = new MetadataStoreFactory().getOsSpecificMetadataStore(builder);
final MetadataStore metadataStore = MetadataStoreFactory.getOsSpecificMetadataStore(builder);
metadataStore.saveOSMetaData(MetaDataUtil.getOS());

final BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public void metadataReceived(final String filename, final Metadata metadata) {
* @param objectName name of the file to be restored
* @param metadata metadata which needs to be set on local file
*/
private void restoreMetaData(final String objectName, final Metadata metadata) throws IOException, InterruptedException {
private static void restoreMetaData(final String objectName, final Metadata metadata) throws IOException, InterruptedException {

final ImmutableList.Builder<Throwable> exceptionBuilder = ImmutableList.builder();

//get metadatarestore on the basis of os
final MetadataRestore metadataRestore = new MetadataRestoreFactory().getOSSpecificMetadataRestore(metadata, objectName);
final MetadataRestore metadataRestore = MetadataRestoreFactory.getOSSpecificMetadataRestore(metadata, objectName);
//restore os name
metadataRestore.restoreOSName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


public class MetadataRestoreFactory {
public MetadataRestore getOSSpecificMetadataRestore(final Metadata metadata, final String filePath) {
public static MetadataRestore getOSSpecificMetadataRestore(final Metadata metadata, final String filePath) {
final String localOS = MetaDataUtil.getOS();

if (Platform.isWindows()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class MetadataStoreFactory
{
public MetadataStore getOsSpecificMetadataStore(final ImmutableMap.Builder<String, String> metadataMap) {
public static MetadataStore getOsSpecificMetadataStore(final ImmutableMap.Builder<String, String> metadataMap) {
if(MetaDataUtil.getOS().contains("Windows")) {
return new WindowsMetadataStore(metadataMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void setOwnerNGroupLnx(final String ownerName, final String groupName) t
* @param filePath path of the file
* @param permissions permissions got from the blackperl server
*/
private void setPermissionsLnx(final String filePath, final String permissions) throws IOException {
private static void setPermissionsLnx(final String filePath, final String permissions) throws IOException {
final Path file = Paths.get(filePath);
final Set<PosixFilePermission> perms =
PosixFilePermissions.fromString(permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void setPermissionsForWindows() throws IOException {
* @return map
*/

private Map<String,AclEntryPermission> defaultOrdinalPermission(){
private static Map<String,AclEntryPermission> defaultOrdinalPermission(){
final Map<String,AclEntryPermission> defaultOrdinalMap = new HashMap<>();
defaultOrdinalMap.put("0",AclEntryPermission.READ_DATA);
defaultOrdinalMap.put("1",AclEntryPermission.WRITE_DATA);
Expand All @@ -147,9 +147,9 @@ private Map<String,AclEntryPermission> defaultOrdinalPermission(){
return defaultOrdinalMap;
}

private void restorePermissionByUser(final String permission,
final String user,
final ImmutableList.Builder<AclEntry> aclEntryBuilder)
private static void restorePermissionByUser(final String permission,
final String user,
final ImmutableList.Builder<AclEntry> aclEntryBuilder)
throws IOException
{
final AclEntry.Builder builderWindow = AclEntry.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.AclEntry;
Expand Down Expand Up @@ -95,7 +96,7 @@ private void saveWindowsDescriptors(final Path path) throws IOException {
* @param acl acl got from jna
* @return dacl string
*/
private String getDaclString(final WinNT.ACL acl) {
private static String getDaclString(final WinNT.ACL acl) {
final WinNT.ACE_HEADER[] aceHeaders = acl.getACEs();
final StringBuilder daclStringBuffer = new StringBuilder();
for (final WinNT.ACE_HEADER aceHeader : aceHeaders) {
Expand Down Expand Up @@ -129,7 +130,7 @@ private String saveFlagMetaData(final Path file) throws IOException {
final ProcessBuilder processBuilder = new ProcessBuilder("attrib", file.toString());
final Process process = processBuilder.start();
try (final BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("UTF-8")))) {
new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
final String flagWindows = reader.readLine();
if (Guard.isStringNullOrEmpty(flagWindows)) {
LOG.error("The flagWindows string was null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void restoreFileTimesTest() throws Exception {
}


private Metadata genMetadata(final Header... headers) {
private static Metadata genMetadata(final Header... headers) {

final ImmutableMultimap.Builder<String, String> mapBuilder = ImmutableMultimap.builder();
for (final Header header : headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testGettingMetadata() throws IOException, InterruptedException {

// change permissions
if (Platform.isWindows()) {
Runtime.getRuntime().exec("attrib -A " + filePath.toString()).waitFor();
Runtime.getRuntime().exec("attrib -A " + filePath).waitFor();
} else {
final PosixFileAttributes attributes = Files.readAttributes(filePath, PosixFileAttributes.class);
final Set<PosixFilePermission> permissions = attributes.permissions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testThatRunningOnMacReturnsMacMetaDataRestore() {
final Metadata metadata = null;
final String filePath = ".";

final MetadataRestore metadataRestorer = new MetadataRestoreFactory().getOSSpecificMetadataRestore(metadata, filePath);
final MetadataRestore metadataRestorer = MetadataRestoreFactory.getOSSpecificMetadataRestore(metadata, filePath);

assertEquals(MACMetadataRestore.class, metadataRestorer.getClass());
}
Expand All @@ -43,7 +43,7 @@ public void testThatRunningOnWindowsReturnsWindowsMetaDataRestore() {
final Metadata metadata = null;
final String filePath = ".";

final MetadataRestore metadataRestorer = new MetadataRestoreFactory().getOSSpecificMetadataRestore(metadata, filePath);
final MetadataRestore metadataRestorer = MetadataRestoreFactory.getOSSpecificMetadataRestore(metadata, filePath);

assertEquals(WindowsMetadataRestore.class, metadataRestorer.getClass());
}
Expand All @@ -55,7 +55,7 @@ public void testThatRunningOnLinuxReturnsLinuxMetaDataRestore() {
final Metadata metadata = null;
final String filePath = ".";

final MetadataRestore metadataRestorer = new MetadataRestoreFactory().getOSSpecificMetadataRestore(metadata, filePath);
final MetadataRestore metadataRestorer = MetadataRestoreFactory.getOSSpecificMetadataRestore(metadata, filePath);

assertEquals(PosixMetadataRestore.class, metadataRestorer.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void restorePermissions() throws Exception{
Assert.assertEquals(getPermissionInOctal(PosixFilePermissions.toString(fileAttributesAfterRestore.permissions())), basicHeader[0].getValue());
}

private Metadata genMetadata(final Header... headers) {
private static Metadata genMetadata(final Header... headers) {

final ImmutableMultimap.Builder<String, String> mapBuilder = ImmutableMultimap.builder();
for (final Header header : headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void restorePermissionsTest() throws NoSuchMethodException, IOException,
windowsMetadataRestore.restorePermissions();
}

private Metadata genMetadata(final Header... headers) {
private static Metadata genMetadata(final Header... headers) {
final ImmutableMultimap.Builder<String, String> mapBuilder = ImmutableMultimap.builder();
for (final Header header : headers) {
mapBuilder.put(header.getName(), header.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -98,7 +99,7 @@ public void testObjectsFitBucketWithNonExistentBucket() {
maxNumObjectTransferAttempts);

final ObjectStorageSpaceVerificationResult result = ds3ClientHelpers.objectsFromBucketWillFitInDirectory(
"bad bucket name", Arrays.asList(new String[] {}), Paths.get("."));
"bad bucket name", Collections.emptyList(), Paths.get("."));

assertEquals(ObjectStorageSpaceVerificationResult.VerificationStatus.BucketDoesNotExist, result.getVerificationStatus());
assertEquals(0, result.getRequiredSpace());
Expand All @@ -119,7 +120,7 @@ public void testObjectsFitBucketWithPathNotDirectory() throws IOException {

try {
final ObjectStorageSpaceVerificationResult result = ds3ClientHelpers.objectsFromBucketWillFitInDirectory(
"bad bucket name", Arrays.asList(new String[]{}), textFile);
"bad bucket name", Collections.emptyList(), textFile);

assertEquals(ObjectStorageSpaceVerificationResult.VerificationStatus.PathIsNotADirectory, result.getVerificationStatus());
assertEquals(0, result.getRequiredSpace());
Expand All @@ -143,7 +144,7 @@ public void testObjectsFitBucketPathDoesNotExist() throws IOException {
FileUtils.deleteDirectory(directory.toFile());

final ObjectStorageSpaceVerificationResult result = ds3ClientHelpers.objectsFromBucketWillFitInDirectory(
"bad bucket name", Arrays.asList(new String[]{}), directory);
"bad bucket name", Collections.emptyList(), directory);

assertEquals(ObjectStorageSpaceVerificationResult.VerificationStatus.PathDoesNotExist, result.getVerificationStatus());
assertEquals(0, result.getRequiredSpace());
Expand All @@ -165,7 +166,7 @@ public void testObjectsFitBucketPathLacksAccess() throws IOException, Interrupte
// Deny write data access to everyone, making the directory unwritable
Runtime.getRuntime().exec("icacls dir /deny Everyone:(WD)").waitFor();
} else {
Runtime.getRuntime().exec("chmod -w " + directory.toString()).waitFor();
Runtime.getRuntime().exec("chmod -w " + directory).waitFor();
final Process lsProcess = Runtime.getRuntime().exec("ls -l");
lsProcess.waitFor();
try (final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(lsProcess.getInputStream()))) {
Expand All @@ -180,7 +181,7 @@ public void testObjectsFitBucketPathLacksAccess() throws IOException, Interrupte

try {
final ObjectStorageSpaceVerificationResult result = ds3ClientHelpers.objectsFromBucketWillFitInDirectory(
"bad bucket name", Arrays.asList(new String[]{}), directory);
"bad bucket name", Collections.emptyList(), directory);

LOG.info(result.toString());

Expand All @@ -194,7 +195,7 @@ public void testObjectsFitBucketPathLacksAccess() throws IOException, Interrupte
// Grant write data access to everyone, making the directory writable, so we can delete it.
Runtime.getRuntime().exec("icacls dir /grant Everyone:(WD)").waitFor();
} else {
Runtime.getRuntime().exec("chmod +w " + directory.toString()).waitFor();
Runtime.getRuntime().exec("chmod +w " + directory).waitFor();
}

FileUtils.deleteDirectory(directory.toFile());
Expand All @@ -221,8 +222,8 @@ private interface ResultVerifier {
void verifyResult(final ObjectStorageSpaceVerificationResult result, final long totalRequiredSize);
}

private void putObjectThenRunVerification(final FileSystemHelper fileSystemHelper,
final ResultVerifier resultVerifier)
private static void putObjectThenRunVerification(final FileSystemHelper fileSystemHelper,
final ResultVerifier resultVerifier)
throws IOException, URISyntaxException
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class RepeatStringObjectChannelBuilder implements Ds3ClientHelpers.ObjectChannelBuilder {
private final int bufferSize;
private final long sizeOfFiles;
private String inputDataHeader;
private final String inputDataHeader;

public RepeatStringObjectChannelBuilder(final String inputDataHeader, final int bufferSize, final long sizeOfFile) {
this.bufferSize = bufferSize;
Expand Down
Loading

0 comments on commit bf93957

Please sign in to comment.