Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Dec 8, 2024
1 parent e05399c commit ce3350c
Show file tree
Hide file tree
Showing 37 changed files with 236 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,19 @@ public void process() throws BackupPeriodRetrievalFailureException {
contentRetrievalProviderUnit.getLocation(), content));
}

try {
workspaceFacade.addBackupFile(
workspaceUnitKey,
workspaceFacade.createFileUnitKey(properties.getWorkspaceContentBackupUnit()),
folderContentUnits);
} catch (FileCreationFailureException e) {
StateService.getBackupProcessorGuard().unlock();
if (!folderContentUnits.isEmpty()) {
try {
workspaceFacade.addBackupFile(
workspaceUnitKey,
workspaceFacade.createFileUnitKey(properties.getWorkspaceContentBackupUnit()),
folderContentUnits);
} catch (FileCreationFailureException e) {
StateService.getBackupProcessorGuard().unlock();

logger.error(e.getMessage());
logger.error(e.getMessage());

return;
return;
}
}

telemetryService.increaseCurrentBackupsAmount();
Expand Down
2 changes: 1 addition & 1 deletion api-server/src/main/openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ paths:
application/zip:
schema:
type: string
format: binary
format: byte
400:
description: Content object was not retrieved
/v1/content/backup/download:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class SelectedProviderToContentProviderConverter {
*/
public static Provider convert(String selectedProvider) {
return Provider.valueOf(
Arrays.stream(
ConfigEntity.Service.Provider.values())
Arrays.stream(ConfigEntity.Service.Provider.values())
.toList()
.stream()
.filter(element -> Objects.equals(element.toString(), selectedProvider))
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/com/objectstorage/entity/ConfigEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static class Credentials {
@NotNull
public Integer id;

@Pattern(regexp = "^(((./)?)|((~/.)?)|((/?))?)([a-zA-Z/]*)((\\.([a-z]+))?)$")
@NotNull
@Pattern(regexp = "^(~|\\.|\\/)?([a-zA-Z0-9_\\-/\\.]+)?$")
public String file;

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public class PropertiesEntity {
@Value(value = "${progress.visualization.health-check-response}")
private String progressVisualizationHealthCheckResponseLabel;

@Value(value = "${progress.visualization.secrets-acquire-request}")
private String progressVisualizationSecretsAcquireRequestLabel;

@Value(value = "${progress.visualization.secrets-acquire-response}")
private String progressVisualizationSecretsAcquireResponseLabel;

@Value(value = "${logging.state.frequency}")
private Integer loggingStateFrequency;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.objectstorage.exception;

import java.io.IOException;
import java.util.Arrays;
import java.util.Formatter;

/** Represents exception, when given provider is not valid. */
public class ProviderIsNotValidException extends IOException {
public ProviderIsNotValidException() {
this("");
}

public ProviderIsNotValidException(Object... message) {
super(
new Formatter()
.format(
"Given provider is not valid: %s",
Arrays.stream(message).toArray())
.toString());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.objectstorage.exception;

import java.io.IOException;
import java.util.Arrays;
import java.util.Formatter;

/** Represents exception, when provided file to be uploaded is not valid. */
public class UploadFileIsNotValidException extends IOException {
public UploadFileIsNotValidException() {
this("");
}

public UploadFileIsNotValidException(Object... message) {
super(
new Formatter()
.format(
"Provided file to be uploaded is not valid: %s",
Arrays.stream(message).toArray())
.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.objectstorage.service.client.common.helper;

/**
* Represents client configuration helper.
*/
public class ClientConfigurationHelper {
/**
* Converts given raw token value to a wrapped format.
*
* @param token given raw token value.
* @return wrapped token.
*/
public static String getWrappedToken(String token) {
return String.format("Bearer: %s", token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.model.ContentRetrievalResult;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
Expand Down Expand Up @@ -35,7 +35,10 @@ public ContentClientService(String host) {
@Override
public ContentRetrievalResult process(String authorization) throws ApiServerOperationFailureException {
try {
return contentResourceApi.v1ContentGet(authorization).block();
return contentResourceApi
.v1ContentGet(
ClientConfigurationHelper.getWrappedToken(authorization))
.block();
} catch (WebClientResponseException e) {
throw new ApiServerOperationFailureException(e.getResponseBodyAsString());
} catch (WebClientRequestException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import com.objectstorage.dto.ContentApplicationRequestDto;
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import com.objectstorage.service.config.ConfigService;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import com.objectstorage.model.ContentApplication;
import reactor.netty.http.client.HttpClient;

/**
Expand Down Expand Up @@ -43,7 +39,7 @@ public Void process(ContentApplicationRequestDto input)
try {
return contentResourceApi
.v1ContentApplyPost(
input.getAuthorization(),
ClientConfigurationHelper.getWrappedToken(input.getAuthorization()),
input.getContentApplication())
.block();
} catch (WebClientResponseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.objectstorage.api.ContentResourceApi;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down Expand Up @@ -32,7 +33,7 @@ public CleanAllContentClientService(String host) {
public Void process(String authorization) throws ApiServerOperationFailureException {
try {
return contentResourceApi
.v1ContentCleanAllDelete(authorization)
.v1ContentCleanAllDelete(ClientConfigurationHelper.getWrappedToken(authorization))
.block();
} catch (WebClientResponseException e) {
throw new ApiServerOperationFailureException(e.getResponseBodyAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.objectstorage.dto.ContentCleanupRequestDto;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down Expand Up @@ -35,7 +36,7 @@ public Void process(ContentCleanupRequestDto input)
try {
return contentResourceApi
.v1ContentObjectCleanDelete(
input.getAuthorization(),
ClientConfigurationHelper.getWrappedToken(input.getAuthorization()),
input.getContentCleanup())
.block();
} catch (WebClientResponseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.objectstorage.dto.ContentDownloadBackupRequestDto;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
Expand Down Expand Up @@ -43,7 +44,7 @@ public File process(ContentDownloadBackupRequestDto input) throws ApiServerOpera
try {
return contentResourceApi
.v1ContentBackupDownloadPost(
input.getAuthorization(),
ClientConfigurationHelper.getWrappedToken(input.getAuthorization()),
input.getContentBackupDownload())
.block();
} catch (WebClientResponseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.objectstorage.dto.ContentDownloadObjectRequestDto;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
Expand All @@ -18,7 +19,7 @@
/**
* Represents implementation for v1ContentObjectDownloadPost endpoint of ContentResourceApi.
*/
public class DownloadContentObjectClientService implements IClient<File, ContentDownloadObjectRequestDto> {
public class DownloadContentObjectClientService implements IClient<byte[], ContentDownloadObjectRequestDto> {
private final ContentResourceApi contentResourceApi;

public DownloadContentObjectClientService(String host) {
Expand All @@ -39,11 +40,11 @@ public DownloadContentObjectClientService(String host) {
* @see IClient
*/
@Override
public File process(ContentDownloadObjectRequestDto input) throws ApiServerOperationFailureException {
public byte[] process(ContentDownloadObjectRequestDto input) throws ApiServerOperationFailureException {
try {
return contentResourceApi
.v1ContentObjectDownloadPost(
input.getAuthorization(),
ClientConfigurationHelper.getWrappedToken(input.getAuthorization()),
input.getContentObjectDownload())
.block();
} catch (WebClientResponseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.objectstorage.dto.ContentUploadObjectRequestDto;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
Expand Down Expand Up @@ -41,7 +42,7 @@ public Void process(ContentUploadObjectRequestDto input) throws ApiServerOperati
try {
return contentResourceApi
.v1ContentObjectUploadPost(
input.getAuthorization(),
ClientConfigurationHelper.getWrappedToken(input.getAuthorization()),
input.getLocation(),
input.getFile())
.block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.objectstorage.api.ContentResourceApi;
import com.objectstorage.exception.ApiServerNotAvailableException;
import com.objectstorage.exception.ApiServerOperationFailureException;
import com.objectstorage.service.client.common.helper.ClientConfigurationHelper;
import com.objectstorage.service.client.common.IClient;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down Expand Up @@ -33,7 +34,10 @@ public WithdrawContentClientService(String host) {
@Override
public Void process(String authorization) throws ApiServerOperationFailureException {
try {
return contentResourceApi.v1ContentWithdrawDelete(authorization).block();
return contentResourceApi
.v1ContentWithdrawDelete(
ClientConfigurationHelper.getWrappedToken(authorization))
.block();
} catch (WebClientResponseException e) {
throw new ApiServerOperationFailureException(e.getResponseBodyAsString());
} catch (WebClientRequestException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.objectstorage.dto.UploadObjectExternalCommandDto;
import com.objectstorage.entity.PropertiesEntity;
import com.objectstorage.exception.*;
import com.objectstorage.service.command.common.helper.CommandConfigurationHelper;
import com.objectstorage.service.command.external.apply.ApplyExternalCommandService;
import com.objectstorage.service.command.external.clean.object.CleanObjectExternalCommandService;
import com.objectstorage.service.command.external.cleanall.CleanAllExternalCommandService;
Expand Down Expand Up @@ -416,6 +417,12 @@ private void downloadObject(
configLocation = properties.getConfigDefaultLocation();
}

if (!CommandConfigurationHelper.isProviderValid(provider)) {
logger.fatal(new ProviderIsNotValidException().getMessage());

return;
}

visualizationState.setLabel(downloadCommandVisualizationLabel);

visualizationService.process();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.objectstorage.service.command.common.helper;

import com.objectstorage.entity.ConfigEntity;

import java.util.Arrays;
import java.util.Objects;

/**
* Represents command configuration helper.
*/
public class CommandConfigurationHelper {
/**
* Checks if given provider is valid.
*
* @param provider given provider value.
* @return result of the check.
*/
public static Boolean isProviderValid(String provider) {
return !Arrays.stream(ConfigEntity.Service.Provider.values())
.toList()
.stream()
.filter(element -> Objects.equals(element.toString(), provider))
.map(Enum::name)
.toList()
.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public void process(ConfigEntity config) throws ApiServerOperationFailureExcepti
ValidationSecretsApplicationResult validationSecretsApplicationResult =
acquireSecretsClientService.process(validationSecretsApplication);

visualizationState.getLabel().pushNext();

visualizationState.getLabel().pushNext();

ApplyContentClientService applyContentClientService =
new ApplyContentClientService(config.getApiServer().getHost());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public void process(CleanExternalCommandDto cleanExternalCommand) throws ApiServ
ValidationSecretsApplicationResult validationSecretsApplicationResult =
acquireSecretsClientService.process(validationSecretsApplication);

visualizationState.getLabel().pushNext();

visualizationState.getLabel().pushNext();

CleanContentObjectClientService cleanContentClientService =
new CleanContentObjectClientService(cleanExternalCommand.getConfig().getApiServer().getHost());

Expand Down
Loading

0 comments on commit ce3350c

Please sign in to comment.