Skip to content

Commit f1d5b2d

Browse files
committed
Fixed comments
1 parent d856907 commit f1d5b2d

7 files changed

Lines changed: 33 additions & 28 deletions

File tree

multiapps-controller-persistence/src/main/java/org/cloudfoundry/multiapps/controller/persistence/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public final class Messages {
5555
// ERROR log messages:
5656
public static final String UPLOAD_STREAM_FAILED_TO_CLOSE = "Cannot close file upload stream";
5757
public static final String CANNOT_PARSE_CONTAINER_URI_OF_OBJECT_STORE = "Cannot parse container_uri of object store";
58+
public static final String MISSING_CONTAINER_URI_IN_THE_CREDENTIALS = "Missing container url in the credentials";
5859

5960
// WARN log messages:
6061
public static final String COULD_NOT_CLOSE_RESULT_SET = "Could not close result set.";

multiapps-controller-persistence/src/main/java/org/cloudfoundry/multiapps/controller/persistence/services/AzureObjectStoreFileStorage.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.net.MalformedURLException;
66
import java.net.URL;
77
import java.time.LocalDateTime;
8-
import java.util.ArrayList;
98
import java.util.List;
109
import java.util.Map;
1110
import java.util.Set;
@@ -155,7 +154,7 @@ protected BlobContainerClient createContainerClient(Map<String, Object> credenti
155154

156155
public String getContainerUriEndpoint(Map<String, Object> credentials) {
157156
if (!credentials.containsKey(CONTAINER_URI)) {
158-
return null;
157+
throw new IllegalStateException(Messages.MISSING_CONTAINER_URI_IN_THE_CREDENTIALS);
159158
}
160159
try {
161160
URL containerUri = new URL((String) credentials.get(CONTAINER_URI));
@@ -178,26 +177,24 @@ private RetryOptions createRetryOptions() {
178177

179178
private int removeBlobsByFilter(Predicate<? super BlobItem> filter) {
180179
Set<String> blobNames = getEntryNames(filter);
181-
List<Boolean> deletedBlobsResults = new ArrayList<>();
180+
int deletedBlobsResult = 0;
182181

183182
if (blobNames.isEmpty()) {
184-
return 0;
183+
return deletedBlobsResult;
185184
}
186185
for (String blobName : blobNames) {
187186
BlobClient blobClient = containerClient.getBlobClient(blobName);
188-
deletedBlobsResults.add(blobClient.deleteIfExists());
187+
if (blobClient.deleteIfExists()) {
188+
deletedBlobsResult++;
189+
}
189190
}
190191

191-
deletedBlobsResults.removeIf(Boolean.FALSE::equals);
192-
193-
return deletedBlobsResults.size();
192+
return deletedBlobsResult;
194193
}
195194

196195
protected Set<String> getEntryNames(Predicate<? super BlobItem> filter) {
197-
ListBlobsOptions listBlobsOptions = new ListBlobsOptions();
198-
BlobListDetails blobListDetails = new BlobListDetails();
199-
blobListDetails.setRetrieveMetadata(true);
200-
listBlobsOptions.setDetails(blobListDetails);
196+
BlobListDetails blobListDetails = new BlobListDetails().setRetrieveMetadata(true);
197+
ListBlobsOptions listBlobsOptions = new ListBlobsOptions().setDetails(blobListDetails);
201198

202199
return containerClient.listBlobs(listBlobsOptions, ObjectStoreConstants.OBJECT_STORE_TOTAL_TIMEOUT_CONFIG_IN_MINUTES)
203200
.stream()
@@ -207,7 +204,8 @@ protected Set<String> getEntryNames(Predicate<? super BlobItem> filter) {
207204
}
208205

209206
public Set<String> getAllEntriesNames() {
210-
return containerClient.listBlobs()
207+
ListBlobsOptions listOptions = new ListBlobsOptions();
208+
return containerClient.listBlobs(listOptions, ObjectStoreConstants.OBJECT_STORE_TOTAL_TIMEOUT_CONFIG_IN_MINUTES)
211209
.stream()
212210
.map(BlobItem::getName)
213211
.collect(Collectors.toSet());

multiapps-controller-persistence/src/test/java/org/cloudfoundry/multiapps/controller/persistence/services/AzureObjectStoreFileStorageTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.mockito.MockitoAnnotations;
2727

2828
import static org.junit.jupiter.api.Assertions.assertEquals;
29-
import static org.junit.jupiter.api.Assertions.assertNull;
3029
import static org.junit.jupiter.api.Assertions.assertThrows;
3130
import static org.mockito.ArgumentMatchers.any;
3231
import static org.mockito.ArgumentMatchers.anyString;
@@ -110,7 +109,7 @@ void testGetFileEntriesWithoutContentWithoutMatches() throws FileStorageExceptio
110109
List<FileEntry> fileEntries = fileStorage.getFileEntriesWithoutContent(List.of(fileEntry));
111110

112111
assertEquals(0, fileEntries.size());
113-
verify(blobContainerClient).listBlobs();
112+
verify(blobContainerClient).listBlobs(any(), any());
114113
}
115114

116115
@Test
@@ -125,7 +124,7 @@ void testGetFileEntriesWithoutContent() throws FileStorageException {
125124
assertEquals(TEST_SPACE_ID, fileEntries.get(0)
126125
.getSpace());
127126
assertEquals(1, fileEntries.size());
128-
verify(blobContainerClient).listBlobs();
127+
verify(blobContainerClient).listBlobs(any(), any());
129128
}
130129

131130
@Test
@@ -144,7 +143,7 @@ void testTestConnection() {
144143

145144
@Test
146145
void testGetContainerUriEndpointWithEmptyCredentials() {
147-
assertNull(fileStorage.getContainerUriEndpoint(Map.of()));
146+
assertThrows(IllegalStateException.class, () -> fileStorage.getContainerUriEndpoint(Map.of()));
148147
}
149148

150149
@Test
@@ -227,7 +226,7 @@ void testDeleteFilesModifiedBefore() throws FileStorageException {
227226
setupDeleteMethods(createFirstTestBlobItem(), createSecondTestBlobItem());
228227

229228
int deletedFiles = fileStorage.deleteFilesModifiedBefore(LocalDateTime.ofInstant(Instant.ofEpochMilli(currentMillis - oldFilesTtl),
230-
ZoneId.systemDefault()));
229+
getZoneId()));
231230

232231
assertEquals(2, deletedFiles);
233232
}
@@ -264,7 +263,6 @@ void testDeleteFilesByIds() throws FileStorageException {
264263
private void setupDeleteMethods(BlobItem... blobItems) {
265264
when(pagedIterable.stream()).thenReturn(Stream.of(blobItems));
266265
when(blobContainerClient.listBlobs(any(), any())).thenReturn(pagedIterable);
267-
when(blobContainerClient.listBlobs()).thenReturn(pagedIterable);
268266
when(blobClient.deleteIfExists()).thenReturn(true);
269267
}
270268

@@ -281,14 +279,18 @@ private BlobItem createFirstTestBlobItem() {
281279
long currentMillis = System.currentTimeMillis();
282280
long pastMoment = currentMillis - 1000 * 60 * 15; // before 15min
283281
return createBlobItem(TEST_ID, TEST_SPACE_ID, NAMESPACE,
284-
LocalDateTime.ofInstant(Instant.ofEpochMilli(pastMoment), ZoneId.systemDefault()));
282+
LocalDateTime.ofInstant(Instant.ofEpochMilli(pastMoment), getZoneId()));
285283
}
286284

287285
private BlobItem createSecondTestBlobItem() {
288286
long currentMillis = System.currentTimeMillis();
289287
long pastMoment = currentMillis - 1000 * 60 * 15; // before 15min
290288
return createBlobItem(TEST_ID_2, TEST_SPACE_ID_2, NAMESPACE_2,
291-
LocalDateTime.ofInstant(Instant.ofEpochMilli(pastMoment), ZoneId.systemDefault()));
289+
LocalDateTime.ofInstant(Instant.ofEpochMilli(pastMoment), getZoneId()));
290+
}
291+
292+
private ZoneId getZoneId() {
293+
return ZoneId.of("UTC");
292294
}
293295

294296
private BlobItem createBlobItem(String name, String spaceId, String namespace, LocalDateTime modificationTime) {

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public final class Messages {
5858

5959
// WARN log messages
6060

61+
public static final String NO_OBJECTSTORE_PROVIDER_FOUND = "No ObjectStore provider found!";
62+
6163
// INFO log messages
6264
public static final String ALM_SERVICE_ENV_INITIALIZED = "Deploy service environment initialized";
6365
public static final String STORING_TOKEN_FOR_USER_WITH_GUID_0_WHICH_EXPIRES_AT_1 = "Storing token for user with GUID \"{0}\" which expires at: {1}";

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/bean/factory/ObjectStoreFileStorageFactoryBean.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private Optional<FileStorage> tryToCreateJCloudsObjectStore(String objectStorePr
116116
ObjectStoreServiceInfo objectStoreServiceInfo = objectStoreServiceInfoOptional.get();
117117
return tryToCreateObjectStore(objectStoreServiceInfo, exceptions);
118118
}
119+
LOGGER.warn(Messages.NO_OBJECTSTORE_PROVIDER_FOUND);
119120
return Optional.empty();
120121
}
121122

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/service/ObjectStoreServiceInfoCreator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ private ObjectStoreServiceInfo createServiceInfoForCcee(Map<String, Object> cred
5959
}
6060

6161
private ObjectStoreServiceInfo createServiceInfoForAzure(Map<String, Object> credentials) {
62-
return ImmutableObjectStoreServiceInfo.builder()
63-
.provider(Constants.AZUREBLOB)
64-
.credentials(credentials)
65-
.build();
62+
return createObjectStoreServiceInfo(Constants.AZUREBLOB, credentials);
6663
}
6764

6865
private ObjectStoreServiceInfo createServiceInfoForGcp(Map<String, Object> credentials) {
66+
return createObjectStoreServiceInfo(Constants.GOOGLE_CLOUD_STORAGE, credentials);
67+
}
68+
69+
private ObjectStoreServiceInfo createObjectStoreServiceInfo(String provider, Map<String, Object> credentials) {
6970
return ImmutableObjectStoreServiceInfo.builder()
70-
.provider(Constants.GOOGLE_CLOUD_STORAGE)
71+
.provider(provider)
7172
.credentials(credentials)
7273
.build();
7374
}

multiapps-controller-web/src/test/java/org/cloudfoundry/multiapps/controller/web/configuration/service/ObjectStoreServiceInfoCreatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static Stream<Arguments> testDifferentProviders() {
3737
return Stream.of(Arguments.of(buildCfService(buildAliCloudCredentials()), buildAliCloudObjectStoreServiceInfo()),
3838
Arguments.of(buildCfService(buildAwsCredentials()), buildAwsObjectStoreServiceInfo()),
3939
Arguments.of(buildCfService(buildSdkCredentials()), buildAzureObjectStoreServiceInfo()),
40-
Arguments.of(buildCfService(buildSdkCredentials()), buildGcoObjectStoreServiceInfo()));
40+
Arguments.of(buildCfService(buildSdkCredentials()), buildGcpObjectStoreServiceInfo()));
4141
}
4242

4343
@ParameterizedTest
@@ -106,7 +106,7 @@ private static ObjectStoreServiceInfo buildAzureObjectStoreServiceInfo() {
106106
.build();
107107
}
108108

109-
private static ObjectStoreServiceInfo buildGcoObjectStoreServiceInfo() {
109+
private static ObjectStoreServiceInfo buildGcpObjectStoreServiceInfo() {
110110
return ImmutableObjectStoreServiceInfo.builder()
111111
.provider(Constants.GOOGLE_CLOUD_STORAGE)
112112
.credentials(CREDENTIALS)

0 commit comments

Comments
 (0)