Skip to content
Merged

Hotfix #1808

Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion multiapps-controller-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-core-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<build>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-database-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<build>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-persistence-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<FileEntry> getFileEntriesWithoutContent(List<FileEntry> fileEntries)

@Override
protected boolean existsInObjectStore(FileEntry fileEntry) {
return blobStore.blobMetadata(container, fileEntry.getId()) != null;
return blobStore.blobExists(container, fileEntry.getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class JCloudsObjectStoreFileStorageTest {

Expand Down Expand Up @@ -368,4 +376,47 @@ protected void assertFileExists(boolean expectedFileExist, FileEntry actualFile)
assertEquals(expectedFileExist, blobExists);
}

@Test
void existsInObjectStoreWithMockedBlobStoreVerifiesBlobExistsCalled() {
BlobStore mockBlobStore = mock(BlobStore.class);
FileEntry fileEntry = createFileEntry();
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER);

when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(true);

boolean result = testFileStorage.existsInObjectStore(fileEntry);

verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId());
assertTrue(result);
}

@Test
void existsInObjectStoreWithMockedBlobStoreFileNotFound() {
BlobStore mockBlobStore = mock(BlobStore.class);
FileEntry fileEntry = createFileEntry();
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER);

when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(false);

boolean result = testFileStorage.existsInObjectStore(fileEntry);

verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId());
assertFalse(result);
}

@Test
void existsInObjectStoreWithMockedBlobStoreVerifiesCorrectContainer() {
BlobStore mockBlobStore = mock(BlobStore.class);
String testContainer = "test-container";
FileEntry fileEntry = createFileEntry();
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, testContainer);

when(mockBlobStore.blobExists(testContainer, fileEntry.getId())).thenReturn(true);

boolean result = testFileStorage.existsInObjectStore(fileEntry);

verify(mockBlobStore, times(1)).blobExists(testContainer, fileEntry.getId());
verify(mockBlobStore, never()).blobExists(eq("wrong-container"), any());
assertTrue(result);
}
}
2 changes: 1 addition & 1 deletion multiapps-controller-process/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<build>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-shutdown-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion multiapps-controller-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
</parent>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class Messages {

// WARN log messages

public static final String NO_OBJECTSTORE_PROVIDER_FOUND = "No ObjectStore provider found!";
public static final String NO_OBJECTSTORE_PROVIDER_FOUND_FOR_0 = "No ObjectStore provider found for {0}!";

// INFO log messages
public static final String ALM_SERVICE_ENV_INITIALIZED = "Deploy service environment initialized";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.cloudfoundry.multiapps.controller.persistence.util.EnvironmentServicesFinder;
import org.cloudfoundry.multiapps.controller.web.Constants;
import org.cloudfoundry.multiapps.controller.web.Messages;
import org.cloudfoundry.multiapps.controller.web.configuration.service.ImmutableObjectStoreServiceInfo;
import org.cloudfoundry.multiapps.controller.web.configuration.service.ObjectStoreServiceInfo;
import org.cloudfoundry.multiapps.controller.web.configuration.service.ObjectStoreServiceInfoCreator;
import org.jclouds.ContextBuilder;
Expand Down Expand Up @@ -92,11 +91,13 @@ public FileStorage createObjectStoreFromFirstReachableProvider(Map<String, Excep
private Optional<FileStorage> createObjectStoreBasedOnProvider(String objectStoreProviderName,
List<ObjectStoreServiceInfo> providersServiceInfo,
Map<String, Exception> exceptions) {
return switch (objectStoreProviderName) {
case Constants.AZURE -> tryToCreateSdkObjectStore(exceptions, Constants.AZUREBLOB);
case Constants.GCP -> tryToCreateSdkObjectStore(exceptions, Constants.GOOGLE_CLOUD_STORAGE);
default -> tryToCreateJCloudsObjectStore(objectStoreProviderName, providersServiceInfo, exceptions);
};
Optional<ObjectStoreServiceInfo> objectStoreServiceInfoOptional = getAppropriateProvider(objectStoreProviderName,
providersServiceInfo);
if (objectStoreServiceInfoOptional.isEmpty()) {
LOGGER.warn(MessageFormat.format(Messages.NO_OBJECTSTORE_PROVIDER_FOUND_FOR_0, objectStoreProviderName));
return Optional.empty();
}
return tryToCreateObjectStore(objectStoreServiceInfoOptional.get(), exceptions);
}

private Optional<ObjectStoreServiceInfo> getAppropriateProvider(String objectStoreProviderName,
Expand All @@ -107,25 +108,6 @@ private Optional<ObjectStoreServiceInfo> getAppropriateProvider(String objectSto
.findFirst();
}

private Optional<FileStorage> tryToCreateJCloudsObjectStore(String objectStoreProviderName,
List<ObjectStoreServiceInfo> providersServiceInfo,
Map<String, Exception> exceptions) {
Optional<ObjectStoreServiceInfo> objectStoreServiceInfoOptional = getAppropriateProvider(objectStoreProviderName,
providersServiceInfo);
if (objectStoreServiceInfoOptional.isPresent()) {
ObjectStoreServiceInfo objectStoreServiceInfo = objectStoreServiceInfoOptional.get();
return tryToCreateObjectStore(objectStoreServiceInfo, exceptions);
}
LOGGER.warn(Messages.NO_OBJECTSTORE_PROVIDER_FOUND);
return Optional.empty();
}

private Optional<FileStorage> tryToCreateSdkObjectStore(Map<String, Exception> exceptions, String providerName) {
return tryToCreateObjectStore(ImmutableObjectStoreServiceInfo.builder()
.provider(providerName)
.build(), exceptions);
}

private Optional<FileStorage> tryToCreateObjectStore(ObjectStoreServiceInfo objectStoreServiceInfo,
Map<String, Exception> exceptions) {
try {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cloudfoundry.multiapps</groupId>
<artifactId>multiapps-controller-parent</artifactId>
<version>2.44.1</version>
<version>2.44.2</version>
<packaging>pom</packaging>
<name>MultiApps Controller Parent</name>
<description>Multi-Target Application (MTA) deployment service for Cloud Foundry</description>
Expand Down
Loading