diff --git a/README.md b/README.md index 2b6c80f..ca3866d 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,11 @@ ## General Information -An object storage with support of **S3** and without vendor limitations. +An object storage with support of **S3** and **GCS** without vendor limitations. Features: * Has easy-to-use well-designed API -* Ignores **S3** limitations(**file size** and **performance**) making interaction with storage vendors seamless +* Ignores **S3** and **GCS** limitations(**file size** and **performance**) making interaction with storage vendors seamless * Provides opportunity to work with different vendors using the same **ObjectStorage** instance * Has integrated data processing optimizations and excessive monitoring opportunities * Provides configurable data backups per vendor in the same workspace diff --git a/api-server/src/main/java/com/objectstorage/service/integration/backup/BackupService.java b/api-server/src/main/java/com/objectstorage/service/integration/backup/BackupService.java index 1eb6e40..42bfd85 100644 --- a/api-server/src/main/java/com/objectstorage/service/integration/backup/BackupService.java +++ b/api-server/src/main/java/com/objectstorage/service/integration/backup/BackupService.java @@ -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(); diff --git a/api-server/src/main/openapi/openapi.yml b/api-server/src/main/openapi/openapi.yml index f6092e3..8937c2d 100644 --- a/api-server/src/main/openapi/openapi.yml +++ b/api-server/src/main/openapi/openapi.yml @@ -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: @@ -154,7 +154,7 @@ paths: application/zip: schema: type: string - format: binary + format: byte 400: description: Content backup was not retrieved /v1/content/object/clean: diff --git a/cli/pom.xml b/cli/pom.xml index 6e4f05f..f2d5167 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -196,7 +196,7 @@ false binary=byte[] - file=byte[] + file=File @lombok.Data @lombok.AllArgsConstructor(staticName = "of") diff --git a/cli/src/main/java/com/objectstorage/App.java b/cli/src/main/java/com/objectstorage/App.java index 280dd18..3da3bea 100644 --- a/cli/src/main/java/com/objectstorage/App.java +++ b/cli/src/main/java/com/objectstorage/App.java @@ -1,26 +1,26 @@ package com.objectstorage; import com.objectstorage.entity.PropertiesEntity; -import com.objectstorage.service.client.content.download.DownloadContentClientService; -import com.objectstorage.service.client.info.version.VersionInfoClientService; import com.objectstorage.service.command.BaseCommandService; -import com.objectstorage.service.command.external.clean.CleanExternalCommandService; +import com.objectstorage.service.command.external.clean.object.CleanObjectExternalCommandService; import com.objectstorage.service.command.external.cleanall.CleanAllExternalCommandService; import com.objectstorage.service.command.external.content.ContentExternalCommandService; -import com.objectstorage.service.command.external.download.DownloadExternalCommandService; +import com.objectstorage.service.command.external.download.backup.DownloadBackupExternalCommandService; +import com.objectstorage.service.command.external.download.object.DownloadObjectExternalCommandService; import com.objectstorage.service.command.external.apply.ApplyExternalCommandService; -import com.objectstorage.service.command.external.topology.TopologyExternalCommandService; +import com.objectstorage.service.command.external.upload.object.UploadObjectExternalCommandService; import com.objectstorage.service.command.external.withdraw.WithdrawExternalCommandService; import com.objectstorage.service.command.external.version.VersionExternalCommandService; import com.objectstorage.service.command.internal.health.HealthCheckInternalCommandService; import com.objectstorage.service.config.ConfigService; import com.objectstorage.service.visualization.VisualizationService; import com.objectstorage.service.visualization.label.apply.ApplyCommandVisualizationLabel; -import com.objectstorage.service.visualization.label.clean.CleanCommandVisualizationLabel; +import com.objectstorage.service.visualization.label.clean.object.CleanObjectCommandVisualizationLabel; import com.objectstorage.service.visualization.label.cleanall.CleanAllCommandVisualizationLabel; import com.objectstorage.service.visualization.label.content.ContentCommandVisualizationLabel; -import com.objectstorage.service.visualization.label.download.DownloadCommandVisualizationLabel; -import com.objectstorage.service.visualization.label.topology.TopologyCommandVisualizationLabel; +import com.objectstorage.service.visualization.label.download.backup.DownloadBackupCommandVisualizationLabel; +import com.objectstorage.service.visualization.label.download.object.DownloadObjectCommandVisualizationLabel; +import com.objectstorage.service.visualization.label.upload.object.UploadObjectCommandVisualizationLabel; import com.objectstorage.service.visualization.label.withdraw.WithdrawCommandVisualizationLabel; import com.objectstorage.service.visualization.label.version.VersionCommandVisualizationLabel; import com.objectstorage.service.visualization.state.VisualizationState; @@ -41,11 +41,12 @@ BaseCommandService.class, ApplyExternalCommandService.class, WithdrawExternalCommandService.class, - CleanExternalCommandService.class, + CleanObjectExternalCommandService.class, CleanAllExternalCommandService.class, ContentExternalCommandService.class, - DownloadExternalCommandService.class, - TopologyExternalCommandService.class, + DownloadObjectExternalCommandService.class, + DownloadBackupExternalCommandService.class, + UploadObjectExternalCommandService.class, VersionExternalCommandService.class, VersionExternalCommandService.class, HealthCheckInternalCommandService.class, @@ -56,11 +57,12 @@ ConfigService.class, ApplyCommandVisualizationLabel.class, WithdrawCommandVisualizationLabel.class, - CleanCommandVisualizationLabel.class, + CleanObjectCommandVisualizationLabel.class, CleanAllCommandVisualizationLabel.class, ContentCommandVisualizationLabel.class, - DownloadCommandVisualizationLabel.class, - TopologyCommandVisualizationLabel.class, + DownloadObjectCommandVisualizationLabel.class, + DownloadBackupCommandVisualizationLabel.class, + UploadObjectCommandVisualizationLabel.class, VersionCommandVisualizationLabel.class, VisualizationService.class, VisualizationState.class diff --git a/cli/src/main/java/com/objectstorage/converter/ConfigCredentialsToContentCredentialsConverter.java b/cli/src/main/java/com/objectstorage/converter/ConfigCredentialsToContentCredentialsConverter.java index d347014..77ce0ef 100644 --- a/cli/src/main/java/com/objectstorage/converter/ConfigCredentialsToContentCredentialsConverter.java +++ b/cli/src/main/java/com/objectstorage/converter/ConfigCredentialsToContentCredentialsConverter.java @@ -1,5 +1,6 @@ package com.objectstorage.converter; +import com.objectstorage.dto.ProcessedCredentialsDto; import com.objectstorage.entity.ConfigEntity; import com.objectstorage.model.CredentialsFieldsExternal; import com.objectstorage.model.CredentialsFieldsFull; @@ -9,7 +10,7 @@ /** * Represents config credentials to ObjectStorage API Server content credentials converter. */ -public class ConfigCredentialsToContentCredentialsConverter { +public class ConfigCredentialsToContentCredentialsConverter { /** * Converts given config credentials to context exporter. @@ -19,12 +20,15 @@ public class ConfigCredentialsToContentCredentialsConverter { * @return converted context exporter. */ public static CredentialsFieldsFull convert( - ConfigEntity.Service.Provider provider, ConfigEntity.Service.Credentials configCredentials) { + ConfigEntity.Service.Provider provider, ProcessedCredentialsDto configCredentials) { return switch (provider) { - case EXPORTER -> null; - case GIT_GITHUB -> CredentialsFieldsFull.of( + case S3 -> CredentialsFieldsFull.of( CredentialsFieldsInternal.of(configCredentials.getId()), - CredentialsFieldsExternal.of(configCredentials.getToken())); + CredentialsFieldsExternal.of( + configCredentials.getFile(), configCredentials.getRegion())); + case GCS -> CredentialsFieldsFull.of( + CredentialsFieldsInternal.of(configCredentials.getId()), + CredentialsFieldsExternal.of(configCredentials.getFile(), null)); }; } } \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/converter/ConfigExporterToContentExporterConverter.java b/cli/src/main/java/com/objectstorage/converter/ConfigExporterToContentExporterConverter.java deleted file mode 100644 index 81cc4de..0000000 --- a/cli/src/main/java/com/objectstorage/converter/ConfigExporterToContentExporterConverter.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.objectstorage.converter; - -import com.objectstorage.entity.ConfigEntity; -import com.objectstorage.model.Exporter; - -/** - * Represents config exporter to ObjectStorage API Server content exporter converter. - */ -public class ConfigExporterToContentExporterConverter { - - /** - * Converts given config exporter to content exporter. - * - * @param provider given config provider. - * @param exporter given config exporter to be converted. - * @return converted content exporter. - */ - public static Exporter convert(ConfigEntity.Service.Provider provider, ConfigEntity.Service.Exporter exporter) { - return switch (provider) { - case EXPORTER -> Exporter.of(exporter.getHost()); - case GIT_GITHUB -> null; - }; - } -} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/converter/ConfigLocationsToContentLocationsConverter.java b/cli/src/main/java/com/objectstorage/converter/ConfigLocationsToContentLocationsConverter.java deleted file mode 100644 index 8a8d528..0000000 --- a/cli/src/main/java/com/objectstorage/converter/ConfigLocationsToContentLocationsConverter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.objectstorage.converter; - -import com.objectstorage.entity.ConfigEntity; -import com.objectstorage.model.ContentUnit; -import com.objectstorage.model.LocationsUnit; - -import java.util.List; - -/** - * Represents config locations to ObjectStorage API Server content locations converter. - */ -public class ConfigLocationsToContentLocationsConverter { - - /** - * Converts given config locations to content locations. - * - * @param configLocations given config locations to be converted. - * @return converted content locations. - */ - public static ContentUnit convert(List configLocations) { - return ContentUnit.of(configLocations - .stream() - .map(element -> LocationsUnit.of( - element.getName(), element.getAdditional())) - .toList()); - } -} diff --git a/cli/src/main/java/com/objectstorage/converter/ConfigProviderToContentProviderConverter.java b/cli/src/main/java/com/objectstorage/converter/ConfigProviderToContentProviderConverter.java index b2c30bb..b495ada 100644 --- a/cli/src/main/java/com/objectstorage/converter/ConfigProviderToContentProviderConverter.java +++ b/cli/src/main/java/com/objectstorage/converter/ConfigProviderToContentProviderConverter.java @@ -26,6 +26,6 @@ public static Provider convert(ConfigEntity.Service.Provider configProvider) { .filter(element -> Objects.equals(element.toString(), configProvider.toString())) .map(Enum::name) .toList() - .get(0)); + .getFirst()); } } diff --git a/cli/src/main/java/com/objectstorage/converter/SelectedProviderToContentProviderConverter.java b/cli/src/main/java/com/objectstorage/converter/SelectedProviderToContentProviderConverter.java new file mode 100644 index 0000000..1da0db1 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/converter/SelectedProviderToContentProviderConverter.java @@ -0,0 +1,30 @@ +package com.objectstorage.converter; + +import com.objectstorage.entity.ConfigEntity; +import com.objectstorage.model.Provider; + +import java.util.Arrays; +import java.util.Objects; + +/** + * Represents selected provider to ObjectStorage API Server content provider converter. + */ +public class SelectedProviderToContentProviderConverter { + + /** + * Converts given config provider to content provider. + * + * @param selectedProvider given selected provider to be converted. + * @return converted content provider. + */ + public static Provider convert(String selectedProvider) { + return Provider.valueOf( + Arrays.stream(ConfigEntity.Service.Provider.values()) + .toList() + .stream() + .filter(element -> Objects.equals(element.toString(), selectedProvider)) + .map(Enum::name) + .toList() + .getFirst()); + } +} diff --git a/cli/src/main/java/com/objectstorage/dto/CleanExternalCommandDto.java b/cli/src/main/java/com/objectstorage/dto/CleanExternalCommandDto.java index e1749bb..3b13615 100644 --- a/cli/src/main/java/com/objectstorage/dto/CleanExternalCommandDto.java +++ b/cli/src/main/java/com/objectstorage/dto/CleanExternalCommandDto.java @@ -3,6 +3,7 @@ import com.objectstorage.entity.ConfigEntity; import lombok.AllArgsConstructor; import lombok.Getter; + /** * Represents input for clean external command. */ diff --git a/cli/src/main/java/com/objectstorage/dto/ContentApplicationRequestDto.java b/cli/src/main/java/com/objectstorage/dto/ContentApplicationRequestDto.java new file mode 100644 index 0000000..afde7b5 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/ContentApplicationRequestDto.java @@ -0,0 +1,16 @@ +package com.objectstorage.dto; + +import com.objectstorage.model.ContentApplication; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents content application request details. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class ContentApplicationRequestDto { + private String authorization; + + private ContentApplication contentApplication; +} diff --git a/cli/src/main/java/com/objectstorage/dto/ContentCleanupRequestDto.java b/cli/src/main/java/com/objectstorage/dto/ContentCleanupRequestDto.java new file mode 100644 index 0000000..7b47806 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/ContentCleanupRequestDto.java @@ -0,0 +1,16 @@ +package com.objectstorage.dto; + +import com.objectstorage.model.ContentCleanup; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents content cleanup request details. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class ContentCleanupRequestDto { + private String authorization; + + private ContentCleanup contentCleanup; +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/dto/ContentDownloadBackupRequestDto.java b/cli/src/main/java/com/objectstorage/dto/ContentDownloadBackupRequestDto.java new file mode 100644 index 0000000..9f16b7b --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/ContentDownloadBackupRequestDto.java @@ -0,0 +1,17 @@ +package com.objectstorage.dto; + +import com.objectstorage.model.ContentBackupDownload; +import com.objectstorage.model.ContentObjectDownload; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents content download backup request details. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class ContentDownloadBackupRequestDto { + private String authorization; + + private ContentBackupDownload contentBackupDownload; +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/dto/ContentDownloadObjectRequestDto.java b/cli/src/main/java/com/objectstorage/dto/ContentDownloadObjectRequestDto.java new file mode 100644 index 0000000..c791ba5 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/ContentDownloadObjectRequestDto.java @@ -0,0 +1,17 @@ +package com.objectstorage.dto; + +import com.objectstorage.model.ContentCleanup; +import com.objectstorage.model.ContentObjectDownload; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents content download object request details. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class ContentDownloadObjectRequestDto { + private String authorization; + + private ContentObjectDownload contentObjectDownload; +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/dto/ContentUploadObjectRequestDto.java b/cli/src/main/java/com/objectstorage/dto/ContentUploadObjectRequestDto.java new file mode 100644 index 0000000..648e079 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/ContentUploadObjectRequestDto.java @@ -0,0 +1,19 @@ +package com.objectstorage.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.io.File; + +/** + * Represents content upload object request details. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class ContentUploadObjectRequestDto { + private String authorization; + + private String location; + + private File file; +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/dto/DownloadExternalCommandDto.java b/cli/src/main/java/com/objectstorage/dto/DownloadBackupExternalCommandDto.java similarity index 73% rename from cli/src/main/java/com/objectstorage/dto/DownloadExternalCommandDto.java rename to cli/src/main/java/com/objectstorage/dto/DownloadBackupExternalCommandDto.java index 2c9de16..b204e10 100644 --- a/cli/src/main/java/com/objectstorage/dto/DownloadExternalCommandDto.java +++ b/cli/src/main/java/com/objectstorage/dto/DownloadBackupExternalCommandDto.java @@ -5,11 +5,11 @@ import lombok.Getter; /** - * Represents input for download external command. + * Represents input for download backup external command. */ @Getter @AllArgsConstructor(staticName = "of") -public class DownloadExternalCommandDto { +public class DownloadBackupExternalCommandDto { private ConfigEntity config; private String outputLocation; diff --git a/cli/src/main/java/com/objectstorage/dto/DownloadObjectExternalCommandDto.java b/cli/src/main/java/com/objectstorage/dto/DownloadObjectExternalCommandDto.java new file mode 100644 index 0000000..434d7bb --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/DownloadObjectExternalCommandDto.java @@ -0,0 +1,20 @@ +package com.objectstorage.dto; + +import com.objectstorage.entity.ConfigEntity; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents input for download object external command. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class DownloadObjectExternalCommandDto { + private ConfigEntity config; + + private String provider; + + private String outputLocation; + + private String location; +} diff --git a/cli/src/main/java/com/objectstorage/dto/ProcessedCredentialsDto.java b/cli/src/main/java/com/objectstorage/dto/ProcessedCredentialsDto.java new file mode 100644 index 0000000..e191949 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/ProcessedCredentialsDto.java @@ -0,0 +1,17 @@ +package com.objectstorage.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents processed credentials details. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class ProcessedCredentialsDto { + private Integer id; + + private String file; + + private String region; +} diff --git a/cli/src/main/java/com/objectstorage/dto/UploadObjectExternalCommandDto.java b/cli/src/main/java/com/objectstorage/dto/UploadObjectExternalCommandDto.java new file mode 100644 index 0000000..2ca4491 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/dto/UploadObjectExternalCommandDto.java @@ -0,0 +1,18 @@ +package com.objectstorage.dto; + +import com.objectstorage.entity.ConfigEntity; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents input for upload object external command. + */ +@Getter +@AllArgsConstructor(staticName = "of") +public class UploadObjectExternalCommandDto { + private ConfigEntity config; + + private String location; + + private String file; +} diff --git a/cli/src/main/java/com/objectstorage/entity/ConfigEntity.java b/cli/src/main/java/com/objectstorage/entity/ConfigEntity.java index 457e85b..ec69c52 100644 --- a/cli/src/main/java/com/objectstorage/entity/ConfigEntity.java +++ b/cli/src/main/java/com/objectstorage/entity/ConfigEntity.java @@ -1,6 +1,7 @@ package com.objectstorage.entity; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.annotation.Nullable; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -41,7 +42,10 @@ public static class Service { */ public enum Provider { @JsonProperty("s3") - S3("s3"); + S3("s3"), + + @JsonProperty("gcs") + GCS("gcs"); private final String value; @@ -54,24 +58,32 @@ public String toString() { } } + @Valid + @NotNull @JsonProperty("provider") public Provider provider; /** - * Represents credentials used for service provider authentication. + * Represents credentials used for selected provider authentication. */ @Getter @NoArgsConstructor - public static class AWSCredentials { - @Pattern(regexp = "^(((./)?)|((~/.)?)|((/?))?)([a-zA-Z/]*)((\\.([a-z]+))?)$") + public static class Credentials { + @NotNull + public Integer id; + + @NotNull + @Pattern(regexp = "^(~|\\.|\\/)?([a-zA-Z0-9_\\-/\\.]+)?$") public String file; - @NotBlank + @Nullable public String region; } + @Valid @NotNull - public Object credentials; + @JsonProperty("credentials") + public Credentials credentials; } @Valid diff --git a/cli/src/main/java/com/objectstorage/entity/PropertiesEntity.java b/cli/src/main/java/com/objectstorage/entity/PropertiesEntity.java index 2d120db..ab604d8 100644 --- a/cli/src/main/java/com/objectstorage/entity/PropertiesEntity.java +++ b/cli/src/main/java/com/objectstorage/entity/PropertiesEntity.java @@ -38,11 +38,11 @@ public class PropertiesEntity { @Value(value = "${progress.visualization.withdraw-response}") private String progressVisualizationWithdrawResponseLabel; - @Value(value = "${progress.visualization.clean-request}") - private String progressVisualizationCleanRequestLabel; + @Value(value = "${progress.visualization.clean-object-request}") + private String progressVisualizationCleanObjectRequestLabel; - @Value(value = "${progress.visualization.clean-response}") - private String progressVisualizationCleanResponseLabel; + @Value(value = "${progress.visualization.clean-object-response}") + private String progressVisualizationCleanObjectResponseLabel; @Value(value = "${progress.visualization.clean-all-request}") private String progressVisualizationCleanAllRequestLabel; @@ -55,18 +55,24 @@ public class PropertiesEntity { @Value(value = "${progress.visualization.content-response}") private String progressVisualizationContentResponseLabel; - - @Value(value = "${progress.visualization.upload-request}") - private String progressVisualizationUploadRequestLabel; - @Value(value = "${progress.visualization.upload-response}") - private String progressVisualizationUploadResponseLabel; + @Value(value = "${progress.visualization.download-object-request}") + private String progressVisualizationDownloadObjectRequestLabel; - @Value(value = "${progress.visualization.download-request}") - private String progressVisualizationDownloadRequestLabel; + @Value(value = "${progress.visualization.download-object-response}") + private String progressVisualizationDownloadObjectResponseLabel; - @Value(value = "${progress.visualization.download-response}") - private String progressVisualizationDownloadResponseLabel; + @Value(value = "${progress.visualization.download-backup-request}") + private String progressVisualizationDownloadBackupRequestLabel; + + @Value(value = "${progress.visualization.download-backup-response}") + private String progressVisualizationDownloadBackupResponseLabel; + + @Value(value = "${progress.visualization.upload-object-request}") + private String progressVisualizationUploadObjectRequestLabel; + + @Value(value = "${progress.visualization.upload-object-response}") + private String progressVisualizationUploadObjectResponseLabel; @Value(value = "${progress.visualization.version-request}") private String progressVisualizationVersionRequestLabel; @@ -80,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; diff --git a/cli/src/main/java/com/objectstorage/exception/CloudCredentialsFileNotFoundException.java b/cli/src/main/java/com/objectstorage/exception/CloudCredentialsFileNotFoundException.java new file mode 100644 index 0000000..43429ac --- /dev/null +++ b/cli/src/main/java/com/objectstorage/exception/CloudCredentialsFileNotFoundException.java @@ -0,0 +1,22 @@ +package com.objectstorage.exception; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Formatter; + +/** + * Represents exception used when given cloud credentials file is not found. + */ +public class CloudCredentialsFileNotFoundException extends IOException { + public CloudCredentialsFileNotFoundException() { + this(""); + } + + public CloudCredentialsFileNotFoundException(Object... message) { + super( + new Formatter() + .format( + "Given cloud credentials file is not found: %s", Arrays.stream(message).toArray()) + .toString()); + } +} diff --git a/cli/src/main/java/com/objectstorage/exception/CloudCredentialsValidationException.java b/cli/src/main/java/com/objectstorage/exception/CloudCredentialsValidationException.java new file mode 100644 index 0000000..dbfb9ff --- /dev/null +++ b/cli/src/main/java/com/objectstorage/exception/CloudCredentialsValidationException.java @@ -0,0 +1,21 @@ +package com.objectstorage.exception; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Formatter; + +/** + * Represents exception used when given cloud credentials are not valid. + */ +public class CloudCredentialsValidationException extends IOException { + public CloudCredentialsValidationException() { + this(""); + } + + public CloudCredentialsValidationException(Object... message) { + super( + new Formatter() + .format("Given cloud credentials are not valid: %s", Arrays.stream(message).toArray()) + .toString()); + } +} diff --git a/cli/src/main/java/com/objectstorage/exception/ProviderIsNotValidException.java b/cli/src/main/java/com/objectstorage/exception/ProviderIsNotValidException.java new file mode 100644 index 0000000..ea8b0f5 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/exception/ProviderIsNotValidException.java @@ -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()); + } +} diff --git a/cli/src/main/java/com/objectstorage/exception/UploadFileIsNotValidException.java b/cli/src/main/java/com/objectstorage/exception/UploadFileIsNotValidException.java new file mode 100644 index 0000000..a1e9f5a --- /dev/null +++ b/cli/src/main/java/com/objectstorage/exception/UploadFileIsNotValidException.java @@ -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()); + } +} diff --git a/cli/src/main/java/com/objectstorage/exception/UploadFileNotFoundException.java b/cli/src/main/java/com/objectstorage/exception/UploadFileNotFoundException.java new file mode 100644 index 0000000..8659b75 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/exception/UploadFileNotFoundException.java @@ -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 found. */ +public class UploadFileNotFoundException extends IOException { + public UploadFileNotFoundException() { + this(""); + } + + public UploadFileNotFoundException(Object... message) { + super( + new Formatter() + .format( + "Provided file to be uploaded is not found: %s", + Arrays.stream(message).toArray()) + .toString()); + } +} diff --git a/cli/src/main/java/com/objectstorage/logging/FatalAppender.java b/cli/src/main/java/com/objectstorage/logging/FatalAppender.java index 93c541b..903728c 100644 --- a/cli/src/main/java/com/objectstorage/logging/FatalAppender.java +++ b/cli/src/main/java/com/objectstorage/logging/FatalAppender.java @@ -23,7 +23,7 @@ /** * Service used for logging fatal level application state changes. */ -@Plugin(name = "fatalappender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) +@Plugin(name = "FatalAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) public class FatalAppender extends AbstractAppender { protected FatalAppender(String name, Filter filter) { super(name, filter, null, false, null); diff --git a/cli/src/main/java/com/objectstorage/service/client/common/helper/ClientConfigurationHelper.java b/cli/src/main/java/com/objectstorage/service/client/common/helper/ClientConfigurationHelper.java new file mode 100644 index 0000000..e25cb65 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/client/common/helper/ClientConfigurationHelper.java @@ -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); + } +} diff --git a/cli/src/main/java/com/objectstorage/service/client/content/ContentClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/ContentClientService.java index 19b2dd3..b5c5ebe 100644 --- a/cli/src/main/java/com/objectstorage/service/client/content/ContentClientService.java +++ b/cli/src/main/java/com/objectstorage/service/client/content/ContentClientService.java @@ -4,23 +4,19 @@ import com.objectstorage.api.ContentResourceApi; import com.objectstorage.exception.ApiServerOperationFailureException; import com.objectstorage.exception.ApiServerNotAvailableException; -import com.objectstorage.model.ContentRetrievalApplication; import com.objectstorage.model.ContentRetrievalResult; +import com.objectstorage.service.client.common.helper.ClientConfigurationHelper; import com.objectstorage.service.client.common.IClient; -import com.objectstorage.service.config.ConfigService; -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 reactor.netty.http.client.HttpClient; /** - * Represents implementation for v1ContentPost endpoint of ContentResourceApi. + * Represents implementation for v1ContentGet endpoint of ContentResourceApi. */ -public class ContentClientService implements IClient< - ContentRetrievalResult, ContentRetrievalApplication> { +public class ContentClientService implements IClient { private final ContentResourceApi contentResourceApi; public ContentClientService(String host) { @@ -37,9 +33,12 @@ public ContentClientService(String host) { * @see IClient */ @Override - public ContentRetrievalResult process(ContentRetrievalApplication input) throws ApiServerOperationFailureException { + public ContentRetrievalResult process(String authorization) throws ApiServerOperationFailureException { try { - return contentResourceApi.v1ContentPost(input).block(); + return contentResourceApi + .v1ContentGet( + ClientConfigurationHelper.getWrappedToken(authorization)) + .block(); } catch (WebClientResponseException e) { throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); } catch (WebClientRequestException e) { diff --git a/cli/src/main/java/com/objectstorage/service/client/content/apply/ApplyContentClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/apply/ApplyContentClientService.java index cca6406..bf8f10a 100644 --- a/cli/src/main/java/com/objectstorage/service/client/content/apply/ApplyContentClientService.java +++ b/cli/src/main/java/com/objectstorage/service/client/content/apply/ApplyContentClientService.java @@ -2,25 +2,22 @@ import com.objectstorage.ApiClient; import com.objectstorage.api.ContentResourceApi; +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; /** * Represents implementation for v1ContentApplyPost endpoint of ContentResourceApi. */ -public class ApplyContentClientService implements IClient { +public class ApplyContentClientService implements IClient { private final ContentResourceApi contentResourceApi; public ApplyContentClientService(String host) { @@ -37,10 +34,14 @@ public ApplyContentClientService(String host) { * @see IClient */ @Override - public Void process(ContentApplication input) + public Void process(ContentApplicationRequestDto input) throws ApiServerOperationFailureException { try { - return contentResourceApi.v1ContentApplyPost(input).block(); + return contentResourceApi + .v1ContentApplyPost( + ClientConfigurationHelper.getWrappedToken(input.getAuthorization()), + input.getContentApplication()) + .block(); } catch (WebClientResponseException e) { throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); } catch (WebClientRequestException e) { diff --git a/cli/src/main/java/com/objectstorage/service/client/content/clean/all/CleanAllContentClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/clean/all/CleanAllContentClientService.java index 2002b65..e6b2e12 100644 --- a/cli/src/main/java/com/objectstorage/service/client/content/clean/all/CleanAllContentClientService.java +++ b/cli/src/main/java/com/objectstorage/service/client/content/clean/all/CleanAllContentClientService.java @@ -4,21 +4,16 @@ import com.objectstorage.api.ContentResourceApi; import com.objectstorage.exception.ApiServerNotAvailableException; import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.model.ContentCleanup; -import com.objectstorage.model.ContentCleanupAll; +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 reactor.netty.http.client.HttpClient; /** Represents implementation for v1ContentCleanAllDelete endpoint of ContentResourceApi. */ -public class CleanAllContentClientService implements IClient { +public class CleanAllContentClientService implements IClient { private final ContentResourceApi contentResourceApi; public CleanAllContentClientService(String host) { @@ -35,11 +30,10 @@ public CleanAllContentClientService(String host) { * @see IClient */ @Override - public Void process(ContentCleanupAll input) - throws ApiServerOperationFailureException { + public Void process(String authorization) throws ApiServerOperationFailureException { try { return contentResourceApi - .v1ContentCleanAllDelete(input) + .v1ContentCleanAllDelete(ClientConfigurationHelper.getWrappedToken(authorization)) .block(); } catch (WebClientResponseException e) { throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); diff --git a/cli/src/main/java/com/objectstorage/service/client/content/clean/CleanContentClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/clean/object/CleanContentObjectClientService.java similarity index 68% rename from cli/src/main/java/com/objectstorage/service/client/content/clean/CleanContentClientService.java rename to cli/src/main/java/com/objectstorage/service/client/content/clean/object/CleanContentObjectClientService.java index 5941bb8..0303565 100644 --- a/cli/src/main/java/com/objectstorage/service/client/content/clean/CleanContentClientService.java +++ b/cli/src/main/java/com/objectstorage/service/client/content/clean/object/CleanContentObjectClientService.java @@ -1,26 +1,23 @@ -package com.objectstorage.service.client.content.clean; +package com.objectstorage.service.client.content.clean.object; import com.objectstorage.ApiClient; import com.objectstorage.api.ContentResourceApi; +import com.objectstorage.dto.ContentCleanupRequestDto; import com.objectstorage.exception.ApiServerNotAvailableException; import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.model.ContentCleanup; +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 reactor.netty.http.client.HttpClient; -/** Represents implementation for v1ContentCleanDelete endpoint of ContentResourceApi. */ -public class CleanContentClientService implements IClient { +/** Represents implementation for v1ContentObjectCleanDelete endpoint of ContentResourceApi. */ +public class CleanContentObjectClientService implements IClient { private final ContentResourceApi contentResourceApi; - public CleanContentClientService(String host) { + public CleanContentObjectClientService(String host) { ApiClient apiClient = new ApiClient(WebClient.builder() .clientConnector(new ReactorClientHttpConnector( HttpClient.create().followRedirect(true))) @@ -34,11 +31,13 @@ public CleanContentClientService(String host) { * @see IClient */ @Override - public Void process(ContentCleanup input) + public Void process(ContentCleanupRequestDto input) throws ApiServerOperationFailureException { try { return contentResourceApi - .v1ContentCleanDelete(input) + .v1ContentObjectCleanDelete( + ClientConfigurationHelper.getWrappedToken(input.getAuthorization()), + input.getContentCleanup()) .block(); } catch (WebClientResponseException e) { throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); diff --git a/cli/src/main/java/com/objectstorage/service/client/content/download/backup/DownloadContentBackupClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/download/backup/DownloadContentBackupClientService.java new file mode 100644 index 0000000..1e9f767 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/client/content/download/backup/DownloadContentBackupClientService.java @@ -0,0 +1,54 @@ +package com.objectstorage.service.client.content.download.backup; + +import com.objectstorage.ApiClient; +import com.objectstorage.api.ContentResourceApi; +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; +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 reactor.netty.http.client.HttpClient; + +/** + * Represents implementation for v1ContentBackupDownloadPost endpoint of ContentResourceApi. + */ +public class DownloadContentBackupClientService implements IClient { + private final ContentResourceApi contentResourceApi; + + public DownloadContentBackupClientService(String host) { + ApiClient apiClient = new ApiClient(WebClient.builder() + .exchangeStrategies(ExchangeStrategies.builder() + .codecs(codecs -> codecs.defaultCodecs() + .maxInMemorySize(-1)) + .build()) + .clientConnector(new ReactorClientHttpConnector( + HttpClient.create().followRedirect(true))) + .build()) + .setBasePath(host); + + this.contentResourceApi = new ContentResourceApi(apiClient); + } + + /** + * @see IClient + */ + @Override + public byte[] process(ContentDownloadBackupRequestDto input) throws ApiServerOperationFailureException { + try { + return contentResourceApi + .v1ContentBackupDownloadPost( + ClientConfigurationHelper.getWrappedToken(input.getAuthorization()), + input.getContentBackupDownload()) + .block(); + } catch (WebClientResponseException e) { + throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); + } catch (WebClientRequestException e) { + throw new ApiServerOperationFailureException(new ApiServerNotAvailableException(e.getMessage()).getMessage()); + } + } +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/client/content/download/DownloadContentClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/download/object/DownloadContentObjectClientService.java similarity index 69% rename from cli/src/main/java/com/objectstorage/service/client/content/download/DownloadContentClientService.java rename to cli/src/main/java/com/objectstorage/service/client/content/download/object/DownloadContentObjectClientService.java index 48cb011..2a9443e 100644 --- a/cli/src/main/java/com/objectstorage/service/client/content/download/DownloadContentClientService.java +++ b/cli/src/main/java/com/objectstorage/service/client/content/download/object/DownloadContentObjectClientService.java @@ -1,13 +1,12 @@ -package com.objectstorage.service.client.content.download; +package com.objectstorage.service.client.content.download.object; import com.objectstorage.ApiClient; import com.objectstorage.api.ContentResourceApi; +import com.objectstorage.dto.ContentDownloadObjectRequestDto; import com.objectstorage.exception.ApiServerNotAvailableException; import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.model.ContentDownload; -import com.objectstorage.model.ContentWithdrawal; +import com.objectstorage.service.client.common.helper.ClientConfigurationHelper; import com.objectstorage.service.client.common.IClient; -import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; @@ -18,12 +17,12 @@ import java.io.File; /** - * Represents implementation for v1ContentDownloadPost endpoint of ContentResourceApi. + * Represents implementation for v1ContentObjectDownloadPost endpoint of ContentResourceApi. */ -public class DownloadContentClientService implements IClient { +public class DownloadContentObjectClientService implements IClient { private final ContentResourceApi contentResourceApi; - public DownloadContentClientService(String host) { + public DownloadContentObjectClientService(String host) { ApiClient apiClient = new ApiClient(WebClient.builder() .exchangeStrategies(ExchangeStrategies.builder() .codecs(codecs -> codecs.defaultCodecs() @@ -41,10 +40,12 @@ public DownloadContentClientService(String host) { * @see IClient */ @Override - public byte[] process(ContentDownload input) throws ApiServerOperationFailureException { + public byte[] process(ContentDownloadObjectRequestDto input) throws ApiServerOperationFailureException { try { return contentResourceApi - .v1ContentDownloadPost(input) + .v1ContentObjectDownloadPost( + ClientConfigurationHelper.getWrappedToken(input.getAuthorization()), + input.getContentObjectDownload()) .block(); } catch (WebClientResponseException e) { throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); diff --git a/cli/src/main/java/com/objectstorage/service/client/content/upload/object/UploadContentObjectClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/upload/object/UploadContentObjectClientService.java new file mode 100644 index 0000000..15472c4 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/client/content/upload/object/UploadContentObjectClientService.java @@ -0,0 +1,55 @@ +package com.objectstorage.service.client.content.upload.object; + +import com.objectstorage.ApiClient; +import com.objectstorage.api.ContentResourceApi; +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; +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 reactor.netty.http.client.HttpClient; + +/** + * Represents implementation for v1ContentObjectUploadPost endpoint of ContentResourceApi. + */ +public class UploadContentObjectClientService implements IClient { + private final ContentResourceApi contentResourceApi; + + public UploadContentObjectClientService(String host) { + ApiClient apiClient = new ApiClient(WebClient.builder() + .exchangeStrategies(ExchangeStrategies.builder() + .codecs(codecs -> codecs.defaultCodecs() + .maxInMemorySize(-1)) + .build()) + .clientConnector(new ReactorClientHttpConnector( + HttpClient.create().followRedirect(true))) + .build()) + .setBasePath(host); + + this.contentResourceApi = new ContentResourceApi(apiClient); + } + + /** + * @see IClient + */ + @Override + public Void process(ContentUploadObjectRequestDto input) throws ApiServerOperationFailureException { + try { + return contentResourceApi + .v1ContentObjectUploadPost( + ClientConfigurationHelper.getWrappedToken(input.getAuthorization()), + input.getLocation(), + input.getFile()) + .block(); + } catch (WebClientResponseException e) { + throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); + } catch (WebClientRequestException e) { + throw new ApiServerOperationFailureException(new ApiServerNotAvailableException(e.getMessage()).getMessage()); + } + } +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/client/content/withdraw/WithdrawContentClientService.java b/cli/src/main/java/com/objectstorage/service/client/content/withdraw/WithdrawContentClientService.java index 136806c..49331a4 100644 --- a/cli/src/main/java/com/objectstorage/service/client/content/withdraw/WithdrawContentClientService.java +++ b/cli/src/main/java/com/objectstorage/service/client/content/withdraw/WithdrawContentClientService.java @@ -4,9 +4,7 @@ import com.objectstorage.api.ContentResourceApi; import com.objectstorage.exception.ApiServerNotAvailableException; import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.model.ContentRetrievalApplication; -import com.objectstorage.model.ContentRetrievalResult; -import com.objectstorage.model.ContentWithdrawal; +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; @@ -15,9 +13,9 @@ import reactor.netty.http.client.HttpClient; /** - * Represents implementation for v1ContentPost endpoint of ContentResourceApi. + * Represents implementation for v1ContentWithdrawDelete endpoint of ContentResourceApi. */ -public class WithdrawContentClientService implements IClient { +public class WithdrawContentClientService implements IClient { private final ContentResourceApi contentResourceApi; public WithdrawContentClientService(String host) { @@ -34,9 +32,12 @@ public WithdrawContentClientService(String host) { * @see IClient */ @Override - public Void process(ContentWithdrawal input) throws ApiServerOperationFailureException { + public Void process(String authorization) throws ApiServerOperationFailureException { try { - return contentResourceApi.v1ContentWithdrawDelete(input).block(); + return contentResourceApi + .v1ContentWithdrawDelete( + ClientConfigurationHelper.getWrappedToken(authorization)) + .block(); } catch (WebClientResponseException e) { throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); } catch (WebClientRequestException e) { diff --git a/cli/src/main/java/com/objectstorage/service/client/info/topology/TopologyInfoClientService.java b/cli/src/main/java/com/objectstorage/service/client/validation/AcquireSecretsClientService.java similarity index 56% rename from cli/src/main/java/com/objectstorage/service/client/info/topology/TopologyInfoClientService.java rename to cli/src/main/java/com/objectstorage/service/client/validation/AcquireSecretsClientService.java index 8a2cc96..8a34051 100644 --- a/cli/src/main/java/com/objectstorage/service/client/info/topology/TopologyInfoClientService.java +++ b/cli/src/main/java/com/objectstorage/service/client/validation/AcquireSecretsClientService.java @@ -1,11 +1,11 @@ -package com.objectstorage.service.client.info.topology; +package com.objectstorage.service.client.validation; import com.objectstorage.ApiClient; -import com.objectstorage.api.InfoResourceApi; +import com.objectstorage.api.ValidationResourceApi; import com.objectstorage.exception.ApiServerNotAvailableException; import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.model.TopologyInfoApplication; -import com.objectstorage.model.TopologyInfoUnit; +import com.objectstorage.model.ValidationSecretsApplication; +import com.objectstorage.model.ValidationSecretsApplicationResult; import com.objectstorage.service.client.common.IClient; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.reactive.function.client.WebClient; @@ -13,28 +13,31 @@ import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.netty.http.client.HttpClient; -import java.util.List; +/** + * Represents implementation for v1SecretsAcquirePost endpoint of ContentResourceApi. + */ +public class AcquireSecretsClientService implements IClient< + ValidationSecretsApplicationResult, ValidationSecretsApplication> { + private final ValidationResourceApi validationResourceApi; -/** Represents implementation for v1InfoTopologyPost endpoint of InfoResourceApi. */ -public class TopologyInfoClientService implements IClient, TopologyInfoApplication> { - private final InfoResourceApi infoResourceApi; - - public TopologyInfoClientService(String host) { + public AcquireSecretsClientService(String host) { ApiClient apiClient = new ApiClient(WebClient.builder() .clientConnector(new ReactorClientHttpConnector( HttpClient.create().followRedirect(true))) .build()) .setBasePath(host); - this.infoResourceApi = new InfoResourceApi(apiClient); + this.validationResourceApi = new ValidationResourceApi(apiClient); } /** * @see IClient */ - public List process(TopologyInfoApplication input) throws ApiServerOperationFailureException { + @Override + public ValidationSecretsApplicationResult process(ValidationSecretsApplication validationSecretsApplication) + throws ApiServerOperationFailureException { try { - return infoResourceApi.v1InfoTopologyPost(input).collectList().block(); + return validationResourceApi.v1SecretsAcquirePost(validationSecretsApplication).block(); } catch (WebClientResponseException e) { throw new ApiServerOperationFailureException(e.getResponseBodyAsString()); } catch (WebClientRequestException e) { diff --git a/cli/src/main/java/com/objectstorage/service/command/BaseCommandService.java b/cli/src/main/java/com/objectstorage/service/command/BaseCommandService.java index 3f0c126..0bf73c7 100644 --- a/cli/src/main/java/com/objectstorage/service/command/BaseCommandService.java +++ b/cli/src/main/java/com/objectstorage/service/command/BaseCommandService.java @@ -1,26 +1,30 @@ package com.objectstorage.service.command; import com.objectstorage.dto.CleanExternalCommandDto; -import com.objectstorage.dto.DownloadExternalCommandDto; +import com.objectstorage.dto.DownloadBackupExternalCommandDto; +import com.objectstorage.dto.DownloadObjectExternalCommandDto; +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.CleanExternalCommandService; +import com.objectstorage.service.command.external.clean.object.CleanObjectExternalCommandService; import com.objectstorage.service.command.external.cleanall.CleanAllExternalCommandService; import com.objectstorage.service.command.external.content.ContentExternalCommandService; -import com.objectstorage.service.command.external.download.DownloadExternalCommandService; -import com.objectstorage.service.command.external.topology.TopologyExternalCommandService; +import com.objectstorage.service.command.external.download.backup.DownloadBackupExternalCommandService; +import com.objectstorage.service.command.external.download.object.DownloadObjectExternalCommandService; +import com.objectstorage.service.command.external.upload.object.UploadObjectExternalCommandService; import com.objectstorage.service.command.external.version.VersionExternalCommandService; import com.objectstorage.service.command.external.withdraw.WithdrawExternalCommandService; import com.objectstorage.service.command.internal.health.HealthCheckInternalCommandService; import com.objectstorage.service.config.ConfigService; import com.objectstorage.service.visualization.VisualizationService; import com.objectstorage.service.visualization.label.apply.ApplyCommandVisualizationLabel; -import com.objectstorage.service.visualization.label.clean.CleanCommandVisualizationLabel; +import com.objectstorage.service.visualization.label.clean.object.CleanObjectCommandVisualizationLabel; import com.objectstorage.service.visualization.label.cleanall.CleanAllCommandVisualizationLabel; import com.objectstorage.service.visualization.label.content.ContentCommandVisualizationLabel; -import com.objectstorage.service.visualization.label.download.DownloadCommandVisualizationLabel; -import com.objectstorage.service.visualization.label.topology.TopologyCommandVisualizationLabel; +import com.objectstorage.service.visualization.label.download.object.DownloadObjectCommandVisualizationLabel; +import com.objectstorage.service.visualization.label.upload.object.UploadObjectCommandVisualizationLabel; import com.objectstorage.service.visualization.label.withdraw.WithdrawCommandVisualizationLabel; import com.objectstorage.service.visualization.label.version.VersionCommandVisualizationLabel; import com.objectstorage.service.visualization.state.VisualizationState; @@ -58,7 +62,7 @@ public class BaseCommandService { private WithdrawExternalCommandService withdrawExternalCommandService; @Autowired - private CleanExternalCommandService cleanExternalCommandService; + private CleanObjectExternalCommandService cleanExternalCommandService; @Autowired private CleanAllExternalCommandService cleanAllExternalCommandService; @@ -67,10 +71,13 @@ public class BaseCommandService { private ContentExternalCommandService contentExternalCommandService; @Autowired - private DownloadExternalCommandService downloadExternalCommandService; + private DownloadObjectExternalCommandService downloadObjectExternalCommandService; @Autowired - private TopologyExternalCommandService topologyExternalCommandService; + private DownloadBackupExternalCommandService downloadBackupExternalCommandService; + + @Autowired + private UploadObjectExternalCommandService uploadObjectExternalCommandService; @Autowired private VersionExternalCommandService versionExternalCommandService; @@ -85,7 +92,7 @@ public class BaseCommandService { private WithdrawCommandVisualizationLabel withdrawCommandVisualizationLabel; @Autowired - private CleanCommandVisualizationLabel cleanCommandVisualizationLabel; + private CleanObjectCommandVisualizationLabel cleanCommandVisualizationLabel; @Autowired private CleanAllCommandVisualizationLabel cleanAllCommandVisualizationLabel; @@ -94,10 +101,10 @@ public class BaseCommandService { private ContentCommandVisualizationLabel contentCommandVisualizationLabel; @Autowired - private DownloadCommandVisualizationLabel downloadCommandVisualizationLabel; + private DownloadObjectCommandVisualizationLabel downloadCommandVisualizationLabel; @Autowired - private TopologyCommandVisualizationLabel topologyCommandVisualizationLabel; + private UploadObjectCommandVisualizationLabel uploadObjectCommandVisualizationLabel; @Autowired private VersionCommandVisualizationLabel versionCommandVisualizationLabel; @@ -202,13 +209,13 @@ private void withdraw( * Provides access to clean command service. * * @param configLocation given custom configuration file location. - * @param location given remote content location name. + * @param location given uploaded content location name. */ - @Command(description = "Clean remote content") - private void clean( + @Command(description = "Clean uploaded content object") + private void cleanObject( @Option(names = {"--config"}, description = "A location of configuration file", defaultValue = "null") String configLocation, - @Option(names = {"--location"}, description = "A name of remote content location", required = true) + @Option(names = {"--location"}, description = "A name of uploaded content location", required = true) String location) { if (Objects.equals(configLocation, "null")) { configLocation = properties.getConfigDefaultLocation(); @@ -251,7 +258,7 @@ private void clean( * * @param configLocation given custom configuration file location. */ - @Command(description = "Clean all remote content") + @Command(description = "Clean all object and backup content") private void cleanAll( @Option(names = {"--config"}, description = "A location of configuration file", defaultValue = "null") String configLocation) { @@ -337,23 +344,85 @@ private void content( } /** - * Provides access to download command service. + * Provides access to upload object command service. + * + * @param configLocation given custom configuration file location. + * @param location given object content object location name. + * @param file given input file location. + */ + @Command(description = "Upload selected content object") + private void uploadObject( + @Option(names = {"--config"}, description = "A location of configuration file", defaultValue = "null") + String configLocation, + @Option(names = {"--location"}, description = "A name of object content location", required = true) + String location, + @Option(names = {"--file"}, description = "A path for the file to be upload", required = true) + String file) { + if (Objects.equals(configLocation, "null")) { + configLocation = properties.getConfigDefaultLocation(); + } + + visualizationState.setLabel(uploadObjectCommandVisualizationLabel); + + visualizationService.process(); + + try { + configService.configure(configLocation); + } catch (ConfigFileNotFoundException | ConfigFileReadingFailureException | ConfigValidationException | + ConfigFileClosureFailureException e) { + logger.fatal(new ApiServerOperationFailureException(e.getMessage()).getMessage()); + + return; + } + + try { + healthCheckInternalCommandService.process(configService.getConfig()); + } catch (ApiServerOperationFailureException e) { + logger.fatal(e.getMessage()); + + return; + } + + try { + uploadObjectExternalCommandService.process(UploadObjectExternalCommandDto.of( + configService.getConfig(), + location, + file)); + } catch (ApiServerOperationFailureException e) { + logger.fatal(e.getMessage()); + + return; + } + + visualizationService.await(); + } + + /** + * Provides access to download object command service. * * @param configLocation given custom configuration file location. - * @param location given remote content location name. + * @param provider given selected provider name. * @param outputLocation given output file location. + * @param location given object content object location name. */ - @Command(description = "Retrieve remote content state") - private void download( + @Command(description = "Download selected content object") + private void downloadObject( @Option(names = {"--config"}, description = "A location of configuration file", defaultValue = "null") String configLocation, - @Option(names = {"--output"}, description = "", required = true) String outputLocation, - @Option(names = {"--location"}, description = "A name of remote content location", required = true) + @Option(names = {"--provider"}, description = "A name of selected provider", required = true) String provider, + @Option(names = {"--output"}, description = "A path for the file to be downloaded", required = true) String outputLocation, + @Option(names = {"--location"}, description = "A name of object content location", required = true) String location) { if (Objects.equals(configLocation, "null")) { configLocation = properties.getConfigDefaultLocation(); } + if (!CommandConfigurationHelper.isProviderValid(provider)) { + logger.fatal(new ProviderIsNotValidException().getMessage()); + + return; + } + visualizationState.setLabel(downloadCommandVisualizationLabel); visualizationService.process(); @@ -376,7 +445,11 @@ private void download( } try { - downloadExternalCommandService.process(DownloadExternalCommandDto.of(configService.getConfig(), outputLocation, location)); + downloadObjectExternalCommandService.process(DownloadObjectExternalCommandDto.of( + configService.getConfig(), + provider, + outputLocation, + location)); } catch (ApiServerOperationFailureException e) { logger.fatal(e.getMessage()); @@ -387,19 +460,24 @@ private void download( } /** - * Provides access to topology command service. + * Provides access to download backup command service. * * @param configLocation given custom configuration file location. + * @param outputLocation given output file location. + * @param location given backup content backup location name. */ - @Command(description = "Retrieve topology configuration)") - private void topology( + @Command(description = "Download selected content backup") + private void downloadBackup( @Option(names = {"--config"}, description = "A location of configuration file", defaultValue = "null") - String configLocation) { + String configLocation, + @Option(names = {"--output"}, description = "A path for the file to be downloaded", required = true) String outputLocation, + @Option(names = {"--location"}, description = "A name of backup content location", required = true) + String location) { if (Objects.equals(configLocation, "null")) { configLocation = properties.getConfigDefaultLocation(); } - visualizationState.setLabel(topologyCommandVisualizationLabel); + visualizationState.setLabel(downloadCommandVisualizationLabel); visualizationService.process(); @@ -421,7 +499,10 @@ private void topology( } try { - topologyExternalCommandService.process(configService.getConfig()); + downloadBackupExternalCommandService.process(DownloadBackupExternalCommandDto.of( + configService.getConfig(), + outputLocation, + location)); } catch (ApiServerOperationFailureException e) { logger.fatal(e.getMessage()); @@ -436,7 +517,7 @@ private void topology( * * @param configLocation given custom configuration file location. */ - @Command(description = "Retrieve versions of infrastructure)") + @Command(description = "Retrieve versions of the infrastructure)") private void version( @Option(names = {"--config"}, description = "A location of configuration file", defaultValue = "null") String configLocation) { diff --git a/cli/src/main/java/com/objectstorage/service/command/common/helper/CommandConfigurationHelper.java b/cli/src/main/java/com/objectstorage/service/command/common/helper/CommandConfigurationHelper.java new file mode 100644 index 0000000..2b02390 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/command/common/helper/CommandConfigurationHelper.java @@ -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(); + } +} diff --git a/cli/src/main/java/com/objectstorage/service/command/external/apply/ApplyExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/apply/ApplyExternalCommandService.java index d41db58..d37ba79 100644 --- a/cli/src/main/java/com/objectstorage/service/command/external/apply/ApplyExternalCommandService.java +++ b/cli/src/main/java/com/objectstorage/service/command/external/apply/ApplyExternalCommandService.java @@ -1,17 +1,30 @@ package com.objectstorage.service.command.external.apply; -import com.objectstorage.converter.*; +import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; +import com.objectstorage.converter.ConfigProviderToContentProviderConverter; +import com.objectstorage.converter.CredentialsConverter; +import com.objectstorage.dto.ContentApplicationRequestDto; +import com.objectstorage.dto.ProcessedCredentialsDto; import com.objectstorage.entity.ConfigEntity; import com.objectstorage.entity.PropertiesEntity; import com.objectstorage.exception.*; import com.objectstorage.model.*; import com.objectstorage.service.client.content.apply.ApplyContentClientService; import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; import com.objectstorage.service.command.common.ICommand; import com.objectstorage.service.visualization.state.VisualizationState; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + /** Represents apply external command service. */ @Service public class ApplyExternalCommandService implements ICommand { @@ -39,17 +52,64 @@ public void process(ConfigEntity config) throws ApiServerOperationFailureExcepti visualizationState.getLabel().pushNext(); + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + config.getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : config.getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + ApplyContentClientService applyContentClientService = new ApplyContentClientService(config.getApiServer().getHost()); - ContentApplication request = ContentApplication.of( - ConfigLocationsToContentLocationsConverter.convert( - config.getContent().getLocations()), - ConfigProviderToContentProviderConverter.convert( - config.getService().getProvider()), - ConfigCredentialsToContentCredentialsConverter.convert( - config.getService().getProvider(), - config.getService().getCredentials())); + ContentApplicationRequestDto request = ContentApplicationRequestDto.of( + validationSecretsApplicationResult.getToken(), + ContentApplication.of( + config.getContent().getRoot())); applyContentClientService.process(request); diff --git a/cli/src/main/java/com/objectstorage/service/command/external/clean/CleanExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/clean/CleanExternalCommandService.java deleted file mode 100644 index ce1bd75..0000000 --- a/cli/src/main/java/com/objectstorage/service/command/external/clean/CleanExternalCommandService.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.objectstorage.service.command.external.clean; - -import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; -import com.objectstorage.converter.ConfigProviderToContentProviderConverter; -import com.objectstorage.dto.CleanExternalCommandDto; -import com.objectstorage.entity.PropertiesEntity; -import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.exception.VersionMismatchException; -import com.objectstorage.model.ContentCleanup; -import com.objectstorage.model.VersionInfoResult; -import com.objectstorage.service.client.content.clean.CleanContentClientService; -import com.objectstorage.service.client.info.version.VersionInfoClientService; -import com.objectstorage.service.command.common.ICommand; -import com.objectstorage.service.visualization.state.VisualizationState; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** Represents clean external command service. */ -@Service -public class CleanExternalCommandService implements ICommand { - @Autowired - private PropertiesEntity properties; - - @Autowired private VisualizationState visualizationState; - - /** - * @see ICommand - */ - @Override - public void process(CleanExternalCommandDto cleanExternalCommand) throws ApiServerOperationFailureException { - visualizationState.getLabel().pushNext(); - - VersionInfoClientService versionInfoClientService = - new VersionInfoClientService(cleanExternalCommand.getConfig().getApiServer().getHost()); - - VersionInfoResult versionInfoResult = versionInfoClientService.process(null); - - if (!versionInfoResult.getExternalApi().getHash().equals(properties.getGitCommitId())) { - throw new ApiServerOperationFailureException(new VersionMismatchException().getMessage()); - } - - visualizationState.getLabel().pushNext(); - - visualizationState.getLabel().pushNext(); - - CleanContentClientService cleanContentClientService = - new CleanContentClientService(cleanExternalCommand.getConfig().getApiServer().getHost()); - - ContentCleanup request = ContentCleanup.of( - cleanExternalCommand.getLocation(), - ConfigProviderToContentProviderConverter.convert( - cleanExternalCommand.getConfig().getService().getProvider()), - ConfigCredentialsToContentCredentialsConverter.convert( - cleanExternalCommand.getConfig().getService().getProvider(), - cleanExternalCommand.getConfig().getService().getCredentials())); - - cleanContentClientService.process(request); - - visualizationState.getLabel().pushNext(); - } -} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/command/external/clean/object/CleanObjectExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/clean/object/CleanObjectExternalCommandService.java new file mode 100644 index 0000000..edb77ef --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/command/external/clean/object/CleanObjectExternalCommandService.java @@ -0,0 +1,123 @@ +package com.objectstorage.service.command.external.clean.object; + +import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; +import com.objectstorage.converter.ConfigProviderToContentProviderConverter; +import com.objectstorage.converter.CredentialsConverter; +import com.objectstorage.dto.CleanExternalCommandDto; +import com.objectstorage.dto.ContentCleanupRequestDto; +import com.objectstorage.dto.ProcessedCredentialsDto; +import com.objectstorage.entity.ConfigEntity; +import com.objectstorage.entity.PropertiesEntity; +import com.objectstorage.exception.ApiServerOperationFailureException; +import com.objectstorage.exception.CloudCredentialsFileNotFoundException; +import com.objectstorage.exception.CloudCredentialsValidationException; +import com.objectstorage.exception.VersionMismatchException; +import com.objectstorage.model.*; +import com.objectstorage.service.client.content.clean.object.CleanContentObjectClientService; +import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; +import com.objectstorage.service.command.common.ICommand; +import com.objectstorage.service.visualization.state.VisualizationState; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** Represents clean external command service. */ +@Service +public class CleanObjectExternalCommandService implements ICommand { + @Autowired + private PropertiesEntity properties; + + @Autowired private VisualizationState visualizationState; + + /** + * @see ICommand + */ + @Override + public void process(CleanExternalCommandDto cleanExternalCommand) throws ApiServerOperationFailureException { + visualizationState.getLabel().pushNext(); + + VersionInfoClientService versionInfoClientService = + new VersionInfoClientService(cleanExternalCommand.getConfig().getApiServer().getHost()); + + VersionInfoResult versionInfoResult = versionInfoClientService.process(null); + + if (!versionInfoResult.getExternalApi().getHash().equals(properties.getGitCommitId())) { + throw new ApiServerOperationFailureException(new VersionMismatchException().getMessage()); + } + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + cleanExternalCommand.getConfig().getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : cleanExternalCommand.getConfig().getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + CleanContentObjectClientService cleanContentClientService = + new CleanContentObjectClientService(cleanExternalCommand.getConfig().getApiServer().getHost()); + + ContentCleanupRequestDto request = ContentCleanupRequestDto.of( + validationSecretsApplicationResult.getToken(), + ContentCleanup.of( + cleanExternalCommand.getLocation())); + + cleanContentClientService.process(request); + + visualizationState.getLabel().pushNext(); + } +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/command/external/cleanall/CleanAllExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/cleanall/CleanAllExternalCommandService.java index 6d101b7..3499b58 100644 --- a/cli/src/main/java/com/objectstorage/service/command/external/cleanall/CleanAllExternalCommandService.java +++ b/cli/src/main/java/com/objectstorage/service/command/external/cleanall/CleanAllExternalCommandService.java @@ -2,22 +2,34 @@ import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; import com.objectstorage.converter.ConfigProviderToContentProviderConverter; -import com.objectstorage.dto.CleanExternalCommandDto; +import com.objectstorage.converter.CredentialsConverter; +import com.objectstorage.dto.ProcessedCredentialsDto; import com.objectstorage.entity.ConfigEntity; import com.objectstorage.entity.PropertiesEntity; import com.objectstorage.exception.ApiServerOperationFailureException; +import com.objectstorage.exception.CloudCredentialsFileNotFoundException; +import com.objectstorage.exception.CloudCredentialsValidationException; import com.objectstorage.exception.VersionMismatchException; -import com.objectstorage.model.ContentCleanup; -import com.objectstorage.model.ContentCleanupAll; +import com.objectstorage.model.ValidationSecretsApplication; +import com.objectstorage.model.ValidationSecretsApplicationResult; +import com.objectstorage.model.ValidationSecretsUnit; import com.objectstorage.model.VersionInfoResult; -import com.objectstorage.service.client.content.clean.CleanContentClientService; import com.objectstorage.service.client.content.clean.all.CleanAllContentClientService; import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; import com.objectstorage.service.command.common.ICommand; import com.objectstorage.service.visualization.state.VisualizationState; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + /** Represents cleanall external command service. */ @Service public class CleanAllExternalCommandService implements ICommand { @@ -46,17 +58,61 @@ public void process(ConfigEntity config) throws ApiServerOperationFailureExcepti visualizationState.getLabel().pushNext(); + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + config.getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : config.getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + CleanAllContentClientService cleanAllContentClientService = new CleanAllContentClientService(config.getApiServer().getHost()); - ContentCleanupAll request = ContentCleanupAll.of( - ConfigProviderToContentProviderConverter.convert( - config.getService().getProvider()), - ConfigCredentialsToContentCredentialsConverter.convert( - config.getService().getProvider(), - config.getService().getCredentials())); - - cleanAllContentClientService.process(request); + cleanAllContentClientService.process(validationSecretsApplicationResult.getToken()); visualizationState.getLabel().pushNext(); } diff --git a/cli/src/main/java/com/objectstorage/service/command/external/content/ContentExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/content/ContentExternalCommandService.java index 1d8f6a6..e1e5323 100644 --- a/cli/src/main/java/com/objectstorage/service/command/external/content/ContentExternalCommandService.java +++ b/cli/src/main/java/com/objectstorage/service/command/external/content/ContentExternalCommandService.java @@ -3,21 +3,32 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; import com.objectstorage.converter.ConfigProviderToContentProviderConverter; +import com.objectstorage.converter.CredentialsConverter; import com.objectstorage.converter.OutputToVisualizationConverter; +import com.objectstorage.dto.ProcessedCredentialsDto; import com.objectstorage.entity.ConfigEntity; import com.objectstorage.entity.PropertiesEntity; import com.objectstorage.exception.ApiServerOperationFailureException; +import com.objectstorage.exception.CloudCredentialsFileNotFoundException; +import com.objectstorage.exception.CloudCredentialsValidationException; import com.objectstorage.exception.VersionMismatchException; -import com.objectstorage.model.ContentRetrievalApplication; -import com.objectstorage.model.ContentRetrievalResult; -import com.objectstorage.model.VersionInfoResult; +import com.objectstorage.model.*; import com.objectstorage.service.client.content.ContentClientService; import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; import com.objectstorage.service.command.common.ICommand; import com.objectstorage.service.visualization.state.VisualizationState; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + /** Represents content external command service. */ @Service public class ContentExternalCommandService implements ICommand { @@ -46,16 +57,61 @@ public void process(ConfigEntity config) throws ApiServerOperationFailureExcepti visualizationState.getLabel().pushNext(); - ContentClientService contentClientService = new ContentClientService(config.getApiServer().getHost()); + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + config.getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : config.getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); - ContentRetrievalApplication request = ContentRetrievalApplication.of( - ConfigProviderToContentProviderConverter.convert( - config.getService().getProvider()), - ConfigCredentialsToContentCredentialsConverter.convert( - config.getService().getProvider(), - config.getService().getCredentials())); + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + ContentClientService contentClientService = new ContentClientService(config.getApiServer().getHost()); - ContentRetrievalResult contentRetrievalResult = contentClientService.process(request); + ContentRetrievalResult contentRetrievalResult = contentClientService.process( + validationSecretsApplicationResult.getToken()); try { visualizationState.addResult(OutputToVisualizationConverter.convert(contentRetrievalResult)); diff --git a/cli/src/main/java/com/objectstorage/service/command/external/download/DownloadExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/download/DownloadExternalCommandService.java deleted file mode 100644 index b540c55..0000000 --- a/cli/src/main/java/com/objectstorage/service/command/external/download/DownloadExternalCommandService.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.objectstorage.service.command.external.download; - -import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; -import com.objectstorage.converter.ConfigProviderToContentProviderConverter; -import com.objectstorage.dto.DownloadExternalCommandDto; -import com.objectstorage.entity.PropertiesEntity; -import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.exception.VersionMismatchException; -import com.objectstorage.model.ContentDownload; -import com.objectstorage.model.VersionInfoResult; -import com.objectstorage.service.client.content.download.DownloadContentClientService; -import com.objectstorage.service.client.info.version.VersionInfoClientService; -import com.objectstorage.service.command.common.ICommand; -import com.objectstorage.service.visualization.state.VisualizationState; -import org.apache.commons.io.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.stereotype.Service; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * Represents download external command service. - */ -@Service -public class DownloadExternalCommandService implements ICommand { - @Autowired - private PropertiesEntity properties; - - @Autowired - private VisualizationState visualizationState; - - /** - * @see ICommand - */ - @Override - public void process(DownloadExternalCommandDto downloadExternalCommand) throws ApiServerOperationFailureException { - visualizationState.getLabel().pushNext(); - - VersionInfoClientService versionInfoClientService = - new VersionInfoClientService(downloadExternalCommand.getConfig().getApiServer().getHost()); - - VersionInfoResult versionInfoResult = versionInfoClientService.process(null); - - if (!versionInfoResult.getExternalApi().getHash().equals(properties.getGitCommitId())) { - throw new ApiServerOperationFailureException(new VersionMismatchException().getMessage()); - } - - visualizationState.getLabel().pushNext(); - - visualizationState.getLabel().pushNext(); - - DownloadContentClientService downloadContentClientService = - new DownloadContentClientService(downloadExternalCommand.getConfig().getApiServer().getHost()); - - ContentDownload request = ContentDownload.of( - downloadExternalCommand.getLocation(), - ConfigProviderToContentProviderConverter.convert( - downloadExternalCommand.getConfig().getService().getProvider()), - ConfigCredentialsToContentCredentialsConverter.convert( - downloadExternalCommand.getConfig().getService().getProvider(), - downloadExternalCommand.getConfig().getService().getCredentials())); - - byte[] contentDownloadResult = downloadContentClientService.process(request); - - try { - FileUtils.writeByteArrayToFile(new File(downloadExternalCommand.getOutputLocation()), contentDownloadResult); - } catch (IOException e) { - throw new ApiServerOperationFailureException(e.getMessage()); - } - - visualizationState.getLabel().pushNext(); - } -} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/command/external/download/backup/DownloadBackupExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/download/backup/DownloadBackupExternalCommandService.java new file mode 100644 index 0000000..800dfe9 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/command/external/download/backup/DownloadBackupExternalCommandService.java @@ -0,0 +1,135 @@ +package com.objectstorage.service.command.external.download.backup; + +import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; +import com.objectstorage.converter.ConfigProviderToContentProviderConverter; +import com.objectstorage.converter.CredentialsConverter; +import com.objectstorage.dto.ContentDownloadBackupRequestDto; +import com.objectstorage.dto.DownloadBackupExternalCommandDto; +import com.objectstorage.dto.ProcessedCredentialsDto; +import com.objectstorage.entity.ConfigEntity; +import com.objectstorage.entity.PropertiesEntity; +import com.objectstorage.exception.ApiServerOperationFailureException; +import com.objectstorage.exception.CloudCredentialsFileNotFoundException; +import com.objectstorage.exception.CloudCredentialsValidationException; +import com.objectstorage.exception.VersionMismatchException; +import com.objectstorage.model.*; +import com.objectstorage.service.client.content.download.backup.DownloadContentBackupClientService; +import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; +import com.objectstorage.service.command.common.ICommand; +import com.objectstorage.service.visualization.state.VisualizationState; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * Represents download backup external command service. + */ +@Service +public class DownloadBackupExternalCommandService implements ICommand { + @Autowired + private PropertiesEntity properties; + + @Autowired + private VisualizationState visualizationState; + + /** + * @see ICommand + */ + @Override + public void process(DownloadBackupExternalCommandDto downloadBackupExternalCommand) + throws ApiServerOperationFailureException { + visualizationState.getLabel().pushNext(); + + VersionInfoClientService versionInfoClientService = + new VersionInfoClientService(downloadBackupExternalCommand.getConfig().getApiServer().getHost()); + + VersionInfoResult versionInfoResult = versionInfoClientService.process(null); + + if (!versionInfoResult.getExternalApi().getHash().equals(properties.getGitCommitId())) { + throw new ApiServerOperationFailureException(new VersionMismatchException().getMessage()); + } + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + downloadBackupExternalCommand.getConfig().getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : downloadBackupExternalCommand.getConfig().getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + DownloadContentBackupClientService downloadContentBackupClientService = + new DownloadContentBackupClientService(downloadBackupExternalCommand.getConfig().getApiServer().getHost()); + + ContentDownloadBackupRequestDto request = ContentDownloadBackupRequestDto.of( + validationSecretsApplicationResult.getToken(), + ContentBackupDownload.of(downloadBackupExternalCommand.getLocation())); + + byte[] contentBackupDownloadResult = downloadContentBackupClientService.process(request); + + try { + FileUtils.writeByteArrayToFile( + new File(downloadBackupExternalCommand.getOutputLocation()), contentBackupDownloadResult); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + visualizationState.getLabel().pushNext(); + } +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/command/external/download/object/DownloadObjectExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/download/object/DownloadObjectExternalCommandService.java new file mode 100644 index 0000000..b7de169 --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/command/external/download/object/DownloadObjectExternalCommandService.java @@ -0,0 +1,140 @@ +package com.objectstorage.service.command.external.download.object; + +import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; +import com.objectstorage.converter.ConfigProviderToContentProviderConverter; +import com.objectstorage.converter.CredentialsConverter; +import com.objectstorage.converter.SelectedProviderToContentProviderConverter; +import com.objectstorage.dto.ContentDownloadObjectRequestDto; +import com.objectstorage.dto.DownloadObjectExternalCommandDto; +import com.objectstorage.dto.ProcessedCredentialsDto; +import com.objectstorage.entity.ConfigEntity; +import com.objectstorage.entity.PropertiesEntity; +import com.objectstorage.exception.ApiServerOperationFailureException; +import com.objectstorage.exception.CloudCredentialsFileNotFoundException; +import com.objectstorage.exception.CloudCredentialsValidationException; +import com.objectstorage.exception.VersionMismatchException; +import com.objectstorage.model.*; +import com.objectstorage.service.client.content.download.object.DownloadContentObjectClientService; +import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; +import com.objectstorage.service.command.common.ICommand; +import com.objectstorage.service.visualization.state.VisualizationState; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * Represents download object external command service. + */ +@Service +public class DownloadObjectExternalCommandService implements ICommand { + @Autowired + private PropertiesEntity properties; + + @Autowired + private VisualizationState visualizationState; + + /** + * @see ICommand + */ + @Override + public void process(DownloadObjectExternalCommandDto downloadObjectExternalCommand) + throws ApiServerOperationFailureException { + visualizationState.getLabel().pushNext(); + + VersionInfoClientService versionInfoClientService = + new VersionInfoClientService(downloadObjectExternalCommand.getConfig().getApiServer().getHost()); + + VersionInfoResult versionInfoResult = versionInfoClientService.process(null); + + if (!versionInfoResult.getExternalApi().getHash().equals(properties.getGitCommitId())) { + throw new ApiServerOperationFailureException(new VersionMismatchException().getMessage()); + } + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + downloadObjectExternalCommand.getConfig().getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : downloadObjectExternalCommand.getConfig().getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + DownloadContentObjectClientService downloadContentObjectClientService = + new DownloadContentObjectClientService(downloadObjectExternalCommand.getConfig().getApiServer().getHost()); + + ContentDownloadObjectRequestDto request = ContentDownloadObjectRequestDto.of( + validationSecretsApplicationResult.getToken(), + ContentObjectDownload.of( + downloadObjectExternalCommand.getLocation(), + SelectedProviderToContentProviderConverter.convert( + downloadObjectExternalCommand.getProvider()))); + + byte[] contentObjectDownloadResult = downloadContentObjectClientService.process(request); + + try { + FileUtils.writeByteArrayToFile( + new File( + downloadObjectExternalCommand.getOutputLocation()), contentObjectDownloadResult); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + visualizationState.getLabel().pushNext(); + } +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/command/external/upload/UploadExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/upload/UploadExternalCommandService.java deleted file mode 100644 index c7a4164..0000000 --- a/cli/src/main/java/com/objectstorage/service/command/external/upload/UploadExternalCommandService.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.objectstorage.service.command.external.download; - -import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; -import com.objectstorage.converter.ConfigProviderToContentProviderConverter; -import com.objectstorage.dto.DownloadExternalCommandDto; -import com.objectstorage.entity.PropertiesEntity; -import com.objectstorage.exception.ApiServerOperationFailureException; -import com.objectstorage.exception.VersionMismatchException; -import com.objectstorage.model.ContentDownload; -import com.objectstorage.model.VersionInfoResult; -import com.objectstorage.service.client.content.download.DownloadContentClientService; -import com.objectstorage.service.client.info.version.VersionInfoClientService; -import com.objectstorage.service.command.common.ICommand; -import com.objectstorage.service.visualization.state.VisualizationState; -import org.apache.commons.io.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.stereotype.Service; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * Represents upload external command service. - */ -@Service -public class UploadExternalCommandService implements ICommand { - @Autowired - private PropertiesEntity properties; - - @Autowired - private VisualizationState visualizationState; - - /** - * @see ICommand - */ - @Override - public void process(UploadExternalCommandDto uploadExternalCommand) throws ApiServerOperationFailureException { - visualizationState.getLabel().pushNext(); - - VersionInfoClientService versionInfoClientService = - new VersionInfoClientService(uploadExternalCommand.getConfig().getApiServer().getHost()); - - VersionInfoResult versionInfoResult = versionInfoClientService.process(null); - - if (!versionInfoResult.getExternalApi().getHash().equals(properties.getGitCommitId())) { - throw new ApiServerOperationFailureException(new VersionMismatchException().getMessage()); - } - - visualizationState.getLabel().pushNext(); - - visualizationState.getLabel().pushNext(); - - UploadContentClientService uploadContentClientService = - new UploadContentClientService(uploadExternalCommand.getConfig().getApiServer().getHost()); - - uploadContentClientService.process(null); - - visualizationState.getLabel().pushNext(); - } -} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/command/external/upload/object/UploadObjectExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/upload/object/UploadObjectExternalCommandService.java new file mode 100644 index 0000000..8f8b65c --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/command/external/upload/object/UploadObjectExternalCommandService.java @@ -0,0 +1,135 @@ +package com.objectstorage.service.command.external.upload.object; + +import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; +import com.objectstorage.converter.ConfigProviderToContentProviderConverter; +import com.objectstorage.converter.CredentialsConverter; +import com.objectstorage.converter.SelectedProviderToContentProviderConverter; +import com.objectstorage.dto.ContentDownloadObjectRequestDto; +import com.objectstorage.dto.ContentUploadObjectRequestDto; +import com.objectstorage.dto.ProcessedCredentialsDto; +import com.objectstorage.dto.UploadObjectExternalCommandDto; +import com.objectstorage.entity.ConfigEntity; +import com.objectstorage.entity.PropertiesEntity; +import com.objectstorage.exception.*; +import com.objectstorage.model.*; +import com.objectstorage.service.client.content.upload.object.UploadContentObjectClientService; +import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; +import com.objectstorage.service.command.common.ICommand; +import com.objectstorage.service.visualization.state.VisualizationState; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * Represents upload external command service. + */ +@Service +public class UploadObjectExternalCommandService implements ICommand { + @Autowired + private PropertiesEntity properties; + + @Autowired + private VisualizationState visualizationState; + + /** + * @see ICommand + */ + @Override + public void process(UploadObjectExternalCommandDto uploadObjectExternalCommand) + throws ApiServerOperationFailureException { + visualizationState.getLabel().pushNext(); + + VersionInfoClientService versionInfoClientService = + new VersionInfoClientService(uploadObjectExternalCommand.getConfig().getApiServer().getHost()); + + VersionInfoResult versionInfoResult = versionInfoClientService.process(null); + + if (!versionInfoResult.getExternalApi().getHash().equals(properties.getGitCommitId())) { + throw new ApiServerOperationFailureException(new VersionMismatchException().getMessage()); + } + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + uploadObjectExternalCommand.getConfig().getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : uploadObjectExternalCommand.getConfig().getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + + UploadContentObjectClientService uploadContentObjectClientService = + new UploadContentObjectClientService( + uploadObjectExternalCommand.getConfig().getApiServer().getHost()); + + Path filePath = Paths.get(uploadObjectExternalCommand.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new UploadFileNotFoundException().getMessage()); + } + + ContentUploadObjectRequestDto request = ContentUploadObjectRequestDto.of( + validationSecretsApplicationResult.getToken(), + uploadObjectExternalCommand.getLocation(), + new File(uploadObjectExternalCommand.getFile())); + + uploadContentObjectClientService.process(request); + + visualizationState.getLabel().pushNext(); + } +} \ No newline at end of file diff --git a/cli/src/main/java/com/objectstorage/service/command/external/withdraw/WithdrawExternalCommandService.java b/cli/src/main/java/com/objectstorage/service/command/external/withdraw/WithdrawExternalCommandService.java index 7de9faa..dedb205 100644 --- a/cli/src/main/java/com/objectstorage/service/command/external/withdraw/WithdrawExternalCommandService.java +++ b/cli/src/main/java/com/objectstorage/service/command/external/withdraw/WithdrawExternalCommandService.java @@ -1,19 +1,32 @@ package com.objectstorage.service.command.external.withdraw; -import com.objectstorage.converter.*; +import com.objectstorage.converter.ConfigCredentialsToContentCredentialsConverter; +import com.objectstorage.converter.ConfigProviderToContentProviderConverter; +import com.objectstorage.converter.CredentialsConverter; +import com.objectstorage.dto.ProcessedCredentialsDto; import com.objectstorage.entity.ConfigEntity; import com.objectstorage.entity.PropertiesEntity; import com.objectstorage.exception.*; -import com.objectstorage.model.ContentWithdrawal; +import com.objectstorage.model.ValidationSecretsApplication; +import com.objectstorage.model.ValidationSecretsApplicationResult; +import com.objectstorage.model.ValidationSecretsUnit; import com.objectstorage.model.VersionInfoResult; import com.objectstorage.service.client.content.withdraw.WithdrawContentClientService; import com.objectstorage.service.client.info.version.VersionInfoClientService; +import com.objectstorage.service.client.validation.AcquireSecretsClientService; import com.objectstorage.service.command.common.ICommand; -import com.objectstorage.service.config.ConfigService; import com.objectstorage.service.visualization.state.VisualizationState; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + /** Represents withdraw external command service. */ @Service public class WithdrawExternalCommandService implements ICommand { @@ -41,17 +54,61 @@ public void process(ConfigEntity config) throws ApiServerOperationFailureExcepti visualizationState.getLabel().pushNext(); + AcquireSecretsClientService acquireSecretsClientService = + new AcquireSecretsClientService( + config.getApiServer().getHost()); + + List validationSecretsUnits = new ArrayList<>(); + + for (ConfigEntity.Service service : config.getService()) { + ConfigEntity.Service.Credentials credentials = + CredentialsConverter.convert( + service.getCredentials(), + ConfigEntity.Service.Credentials.class); + if (Objects.isNull(credentials)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsValidationException().getMessage()); + } + + Path filePath = Paths.get(credentials.getFile()); + + if (Files.notExists(filePath)) { + throw new ApiServerOperationFailureException( + new CloudCredentialsFileNotFoundException().getMessage()); + } + + String content; + + try { + content = Files.readString(filePath); + } catch (IOException e) { + throw new ApiServerOperationFailureException(e.getMessage()); + } + + validationSecretsUnits.add(ValidationSecretsUnit.of( + ConfigProviderToContentProviderConverter.convert(service.getProvider()), + ConfigCredentialsToContentCredentialsConverter.convert( + service.getProvider(), + ProcessedCredentialsDto.of( + credentials.getId(), + content, + credentials.getRegion())))); + } + + ValidationSecretsApplication validationSecretsApplication = + ValidationSecretsApplication.of(validationSecretsUnits); + + ValidationSecretsApplicationResult validationSecretsApplicationResult = + acquireSecretsClientService.process(validationSecretsApplication); + + visualizationState.getLabel().pushNext(); + + visualizationState.getLabel().pushNext(); + WithdrawContentClientService withdrawContentClientService = new WithdrawContentClientService(config.getApiServer().getHost()); - ContentWithdrawal request = ContentWithdrawal.of( - ConfigProviderToContentProviderConverter.convert( - config.getService().getProvider()), - ConfigCredentialsToContentCredentialsConverter.convert( - config.getService().getProvider(), - config.getService().getCredentials())); - - withdrawContentClientService.process(request); + withdrawContentClientService.process(validationSecretsApplicationResult.getToken()); visualizationState.getLabel().pushNext(); } diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/apply/ApplyCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/apply/ApplyCommandVisualizationLabel.java index e8be508..349661b 100644 --- a/cli/src/main/java/com/objectstorage/service/visualization/label/apply/ApplyCommandVisualizationLabel.java +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/apply/ApplyCommandVisualizationLabel.java @@ -28,11 +28,15 @@ public ApplyCommandVisualizationLabel(@Autowired PropertiesEntity properties) { VisualizationLabelDto.of( properties.getProgressVisualizationHealthCheckRequestLabel(), 10), VisualizationLabelDto.of( - properties.getProgressVisualizationHealthCheckResponseLabel(), 30), + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionRequestLabel(), 40), + properties.getProgressVisualizationVersionRequestLabel(), 30), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionResponseLabel(), 60), + properties.getProgressVisualizationVersionResponseLabel(), 40), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), VisualizationLabelDto.of(properties.getProgressVisualizationApplyRequestLabel(), 70), VisualizationLabelDto.of( properties.getProgressVisualizationApplyResponseLabel(), 100))); diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/topology/TopologyCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/clean/object/CleanObjectCommandVisualizationLabel.java similarity index 74% rename from cli/src/main/java/com/objectstorage/service/visualization/label/topology/TopologyCommandVisualizationLabel.java rename to cli/src/main/java/com/objectstorage/service/visualization/label/clean/object/CleanObjectCommandVisualizationLabel.java index d22b2bc..4bb9ac0 100644 --- a/cli/src/main/java/com/objectstorage/service/visualization/label/topology/TopologyCommandVisualizationLabel.java +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/clean/object/CleanObjectCommandVisualizationLabel.java @@ -1,4 +1,4 @@ -package com.objectstorage.service.visualization.label.topology; +package com.objectstorage.service.visualization.label.clean.object; import com.objectstorage.dto.VisualizationLabelDto; import com.objectstorage.entity.PropertiesEntity; @@ -11,31 +11,34 @@ import java.util.concurrent.locks.ReentrantLock; /** - * Represents label set used for topology command service. + * Represents label set used for clean object command service. */ @Service -public class TopologyCommandVisualizationLabel implements IVisualizationLabel { +public class CleanObjectCommandVisualizationLabel implements IVisualizationLabel { private final ArrayDeque stepsQueue = new ArrayDeque<>(); private final ArrayDeque batchQueue = new ArrayDeque<>(); private final ReentrantLock mutex = new ReentrantLock(); - public TopologyCommandVisualizationLabel(@Autowired PropertiesEntity properties) { + public CleanObjectCommandVisualizationLabel(@Autowired PropertiesEntity properties) { stepsQueue.addAll( List.of( VisualizationLabelDto.of( properties.getProgressVisualizationHealthCheckRequestLabel(), 10), VisualizationLabelDto.of( - properties.getProgressVisualizationHealthCheckResponseLabel(), 30), + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionRequestLabel(), 40), + properties.getProgressVisualizationVersionRequestLabel(), 30), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionResponseLabel(), 60), + properties.getProgressVisualizationVersionResponseLabel(), 40), VisualizationLabelDto.of( - properties.getProgressVisualizationTopologyRequestLabel(), 70), + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), VisualizationLabelDto.of( - properties.getProgressVisualizationTopologyResponseLabel(), 100))); + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), + VisualizationLabelDto.of(properties.getProgressVisualizationCleanObjectRequestLabel(), 70), + VisualizationLabelDto.of( + properties.getProgressVisualizationCleanObjectResponseLabel(), 100))); } /** diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/cleanall/CleanAllCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/cleanall/CleanAllCommandVisualizationLabel.java index 84bf2b5..b7e3951 100644 --- a/cli/src/main/java/com/objectstorage/service/visualization/label/cleanall/CleanAllCommandVisualizationLabel.java +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/cleanall/CleanAllCommandVisualizationLabel.java @@ -27,11 +27,15 @@ public CleanAllCommandVisualizationLabel(@Autowired PropertiesEntity properties) VisualizationLabelDto.of( properties.getProgressVisualizationHealthCheckRequestLabel(), 10), VisualizationLabelDto.of( - properties.getProgressVisualizationHealthCheckResponseLabel(), 30), + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionRequestLabel(), 40), + properties.getProgressVisualizationVersionRequestLabel(), 30), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionResponseLabel(), 60), + properties.getProgressVisualizationVersionResponseLabel(), 40), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), VisualizationLabelDto.of(properties.getProgressVisualizationCleanAllRequestLabel(), 70), VisualizationLabelDto.of( properties.getProgressVisualizationCleanAllResponseLabel(), 100))); diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/content/ContentCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/content/ContentCommandVisualizationLabel.java index 0e428d4..9b2cbf2 100644 --- a/cli/src/main/java/com/objectstorage/service/visualization/label/content/ContentCommandVisualizationLabel.java +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/content/ContentCommandVisualizationLabel.java @@ -28,11 +28,15 @@ public ContentCommandVisualizationLabel(@Autowired PropertiesEntity properties) VisualizationLabelDto.of( properties.getProgressVisualizationHealthCheckRequestLabel(), 10), VisualizationLabelDto.of( - properties.getProgressVisualizationHealthCheckResponseLabel(), 30), + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionRequestLabel(), 40), + properties.getProgressVisualizationVersionRequestLabel(), 30), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionResponseLabel(), 60), + properties.getProgressVisualizationVersionResponseLabel(), 40), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), VisualizationLabelDto.of( properties.getProgressVisualizationContentRequestLabel(), 70), VisualizationLabelDto.of( diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/clean/CleanCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/download/backup/DownloadBackupCommandVisualizationLabel.java similarity index 72% rename from cli/src/main/java/com/objectstorage/service/visualization/label/clean/CleanCommandVisualizationLabel.java rename to cli/src/main/java/com/objectstorage/service/visualization/label/download/backup/DownloadBackupCommandVisualizationLabel.java index d795f68..d118504 100644 --- a/cli/src/main/java/com/objectstorage/service/visualization/label/clean/CleanCommandVisualizationLabel.java +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/download/backup/DownloadBackupCommandVisualizationLabel.java @@ -1,4 +1,4 @@ -package com.objectstorage.service.visualization.label.clean; +package com.objectstorage.service.visualization.label.download.backup; import com.objectstorage.dto.VisualizationLabelDto; import com.objectstorage.entity.PropertiesEntity; @@ -11,30 +11,34 @@ import java.util.concurrent.locks.ReentrantLock; /** - * Represents label set used for clean command service. + * Represents label set used for download backup command service. */ @Service -public class CleanCommandVisualizationLabel implements IVisualizationLabel { +public class DownloadBackupCommandVisualizationLabel implements IVisualizationLabel { private final ArrayDeque stepsQueue = new ArrayDeque<>(); private final ArrayDeque batchQueue = new ArrayDeque<>(); private final ReentrantLock mutex = new ReentrantLock(); - public CleanCommandVisualizationLabel(@Autowired PropertiesEntity properties) { + public DownloadBackupCommandVisualizationLabel(@Autowired PropertiesEntity properties) { stepsQueue.addAll( List.of( VisualizationLabelDto.of( properties.getProgressVisualizationHealthCheckRequestLabel(), 10), VisualizationLabelDto.of( - properties.getProgressVisualizationHealthCheckResponseLabel(), 30), + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionRequestLabel(), 40), + properties.getProgressVisualizationVersionRequestLabel(), 30), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionResponseLabel(), 60), - VisualizationLabelDto.of(properties.getProgressVisualizationCleanRequestLabel(), 70), + properties.getProgressVisualizationVersionResponseLabel(), 40), VisualizationLabelDto.of( - properties.getProgressVisualizationCleanResponseLabel(), 100))); + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), + VisualizationLabelDto.of(properties.getProgressVisualizationDownloadBackupRequestLabel(), 70), + VisualizationLabelDto.of( + properties.getProgressVisualizationDownloadBackupResponseLabel(), 100))); } /** diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/download/object/DownloadObjectCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/download/object/DownloadObjectCommandVisualizationLabel.java new file mode 100644 index 0000000..00ff26b --- /dev/null +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/download/object/DownloadObjectCommandVisualizationLabel.java @@ -0,0 +1,91 @@ +package com.objectstorage.service.visualization.label.download.object; + +import com.objectstorage.dto.VisualizationLabelDto; +import com.objectstorage.entity.PropertiesEntity; +import com.objectstorage.service.visualization.common.IVisualizationLabel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayDeque; +import java.util.List; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Represents label set used for download object command service. + */ +@Service +public class DownloadObjectCommandVisualizationLabel implements IVisualizationLabel { + private final ArrayDeque stepsQueue = new ArrayDeque<>(); + + private final ArrayDeque batchQueue = new ArrayDeque<>(); + + private final ReentrantLock mutex = new ReentrantLock(); + + public DownloadObjectCommandVisualizationLabel(@Autowired PropertiesEntity properties) { + stepsQueue.addAll( + List.of( + VisualizationLabelDto.of( + properties.getProgressVisualizationHealthCheckRequestLabel(), 10), + VisualizationLabelDto.of( + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), + VisualizationLabelDto.of( + properties.getProgressVisualizationVersionRequestLabel(), 30), + VisualizationLabelDto.of( + properties.getProgressVisualizationVersionResponseLabel(), 40), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), + VisualizationLabelDto.of(properties.getProgressVisualizationDownloadObjectRequestLabel(), 70), + VisualizationLabelDto.of( + properties.getProgressVisualizationDownloadObjectResponseLabel(), 100))); + } + + /** + * @see IVisualizationLabel + */ + @Override + public Boolean isEmpty() { + return stepsQueue.isEmpty(); + } + + /** + * @see IVisualizationLabel + */ + @Override + public Boolean isNext() { + mutex.lock(); + + try { + return !batchQueue.isEmpty(); + } finally { + mutex.unlock(); + } + } + + /** + * @see IVisualizationLabel + */ + @Override + public void pushNext() { + mutex.lock(); + + batchQueue.push(stepsQueue.pop().toString()); + + mutex.unlock(); + } + + /** + * @see IVisualizationLabel + */ + @Override + public String getCurrent() { + mutex.lock(); + + try { + return batchQueue.pollLast(); + } finally { + mutex.unlock(); + } + } +} diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/download/DownloadCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/upload/object/UploadObjectCommandVisualizationLabel.java similarity index 72% rename from cli/src/main/java/com/objectstorage/service/visualization/label/download/DownloadCommandVisualizationLabel.java rename to cli/src/main/java/com/objectstorage/service/visualization/label/upload/object/UploadObjectCommandVisualizationLabel.java index 2eef097..efe53b7 100644 --- a/cli/src/main/java/com/objectstorage/service/visualization/label/download/DownloadCommandVisualizationLabel.java +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/upload/object/UploadObjectCommandVisualizationLabel.java @@ -1,4 +1,4 @@ -package com.objectstorage.service.visualization.label.download; +package com.objectstorage.service.visualization.label.upload.object; import com.objectstorage.dto.VisualizationLabelDto; import com.objectstorage.entity.PropertiesEntity; @@ -11,30 +11,34 @@ import java.util.concurrent.locks.ReentrantLock; /** - * Represents label set used for download command service. + * Represents label set used for upload object command service. */ @Service -public class DownloadCommandVisualizationLabel implements IVisualizationLabel { +public class UploadObjectCommandVisualizationLabel implements IVisualizationLabel { private final ArrayDeque stepsQueue = new ArrayDeque<>(); private final ArrayDeque batchQueue = new ArrayDeque<>(); private final ReentrantLock mutex = new ReentrantLock(); - public DownloadCommandVisualizationLabel(@Autowired PropertiesEntity properties) { + public UploadObjectCommandVisualizationLabel(@Autowired PropertiesEntity properties) { stepsQueue.addAll( List.of( VisualizationLabelDto.of( properties.getProgressVisualizationHealthCheckRequestLabel(), 10), VisualizationLabelDto.of( - properties.getProgressVisualizationHealthCheckResponseLabel(), 30), + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionRequestLabel(), 40), + properties.getProgressVisualizationVersionRequestLabel(), 30), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionResponseLabel(), 60), - VisualizationLabelDto.of(properties.getProgressVisualizationDownloadRequestLabel(), 70), + properties.getProgressVisualizationVersionResponseLabel(), 40), VisualizationLabelDto.of( - properties.getProgressVisualizationDownloadResponseLabel(), 100))); + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), + VisualizationLabelDto.of(properties.getProgressVisualizationUploadObjectRequestLabel(), 70), + VisualizationLabelDto.of( + properties.getProgressVisualizationUploadObjectResponseLabel(), 100))); } /** diff --git a/cli/src/main/java/com/objectstorage/service/visualization/label/withdraw/WithdrawCommandVisualizationLabel.java b/cli/src/main/java/com/objectstorage/service/visualization/label/withdraw/WithdrawCommandVisualizationLabel.java index 91b4231..8c7e07b 100644 --- a/cli/src/main/java/com/objectstorage/service/visualization/label/withdraw/WithdrawCommandVisualizationLabel.java +++ b/cli/src/main/java/com/objectstorage/service/visualization/label/withdraw/WithdrawCommandVisualizationLabel.java @@ -28,11 +28,15 @@ public WithdrawCommandVisualizationLabel(@Autowired PropertiesEntity properties) VisualizationLabelDto.of( properties.getProgressVisualizationHealthCheckRequestLabel(), 10), VisualizationLabelDto.of( - properties.getProgressVisualizationHealthCheckResponseLabel(), 30), + properties.getProgressVisualizationHealthCheckResponseLabel(), 20), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionRequestLabel(), 40), + properties.getProgressVisualizationVersionRequestLabel(), 30), VisualizationLabelDto.of( - properties.getProgressVisualizationVersionResponseLabel(), 60), + properties.getProgressVisualizationVersionResponseLabel(), 40), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireRequestLabel(), 50), + VisualizationLabelDto.of( + properties.getProgressVisualizationSecretsAcquireResponseLabel(), 60), VisualizationLabelDto.of(properties.getProgressVisualizationWithdrawRequestLabel(), 70), VisualizationLabelDto.of( properties.getProgressVisualizationWithdrawResponseLabel(), 100))); diff --git a/cli/src/main/resources/application.properties b/cli/src/main/resources/application.properties index 4af9564..9791eb4 100644 --- a/cli/src/main/resources/application.properties +++ b/cli/src/main/resources/application.properties @@ -22,11 +22,11 @@ progress.visualization.withdraw-request=Sending configuration withdraw request # Describes visualization label used for configuration withdraw response. progress.visualization.withdraw-response=Withdrawal of configuration has been completed -# Describes visualization label used for content clean request. -progress.visualization.clean-request=Sending content clean request +# Describes visualization label used for content clean object request. +progress.visualization.clean-object-request=Sending content clean object request -# Describes visualization label used for content clean response. -progress.visualization.clean-response=Cleaning of content has been completed +# Describes visualization label used for content clean object response. +progress.visualization.clean-object-response=Cleaning of content object has been completed # Describes visualization label used for content clean all request. progress.visualization.clean-all-request=Sending content clean all request @@ -40,17 +40,23 @@ progress.visualization.content-request=Sending content retrieval request # Describes visualization label used for content retrieval response. progress.visualization.content-response=Content retrieval has been completed -# Describes visualization label used for content upload request. -progress.visualization.upload-request=Sending content upload request +# Describes visualization label used for content object download request. +progress.visualization.download-object-request=Sending content object download request -# Describes visualization label used for content upload response. -progress.visualization.upload-response=Content upload has been completed +# Describes visualization label used for content object download response. +progress.visualization.download-object-response=Content object download has been completed -# Describes visualization label used for content download request. -progress.visualization.download-request=Sending content download request +# Describes visualization label used for content backup download request. +progress.visualization.download-backup-request=Sending content backup download request -# Describes visualization label used for content download response. -progress.visualization.download-response=Content download has been completed +# Describes visualization label used for content backup download response. +progress.visualization.download-backup-response=Content backup download has been completed + +# Describes visualization label used for content object upload request. +progress.visualization.upload-object-request=Sending content object upload request + +# Describes visualization label used for content object upload response. +progress.visualization.upload-object-response=Content object upload has been completed # Describes visualization label used for version request. progress.visualization.version-request=Sending request to retrieve ObjectStorage API Server version information @@ -64,5 +70,11 @@ progress.visualization.health-check-request=Sending health check request # Describes visualization label used for health check response. progress.visualization.health-check-response=Health check retrieval has been completed +# Describes visualization label used for secrets acquire request. +progress.visualization.secrets-acquire-request=Sending secrets acquire request + +# Describes visualization label used for secrets acquire response. +progress.visualization.secrets-acquire-response=Secrets acquire has been completed + # Describes frequency used to perform logging state check. logging.state.frequency=10 \ No newline at end of file diff --git a/cli/src/main/resources/log4j2.xml b/cli/src/main/resources/log4j2.xml index 6aba8f3..e3b7a60 100644 --- a/cli/src/main/resources/log4j2.xml +++ b/cli/src/main/resources/log4j2.xml @@ -1,7 +1,7 @@ - + - + @@ -54,7 +54,7 @@ - + diff --git a/samples/config/client/user.yaml b/samples/config/client/user.yaml index 4f200e0..da64089 100644 --- a/samples/config/client/user.yaml +++ b/samples/config/client/user.yaml @@ -14,15 +14,16 @@ service: id: "1" # Represents a path to the credentials CSV file, which contains both access - # and secret keys. - file: "~/.aws/credentials" + # and secret keys. Make sure you don't use "~" symbol. + file: "/Users/yaroslavsvitlytskyi/.aws/credentials/rootkey.csv" # Represents a select region where the deployment of infrastructure will be performed. # Remember that it may influence the availability of the ObjectStorage deployed infrastructure. + # # This option can be applied to "s3" provider only. region: "us-west-2" # Represents section used for ObjectStorage API Server configuration. api-server: # Represents address for the host of ObjectStorage API Server. - host: "http://localhost:8085" + host: "http://localhost:8086"