Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public Response uploadMetadata(
@POST
public Response restoreBackup(@Parameter(description = "Unique identifier of the backup", required = true)
@PathParam("backupName") @NotBlank String backupName,
@RequestBody(description = "Restore request", required = true)
@RequestBody(description = "Restore request")
@Valid RestoreRequest restoreRequest,
@QueryParam("dryRun") @DefaultValue("false") boolean dryRun) {
RestoreResponse response = dbBackupV2Service.restore(backupName, restoreRequest, dryRun);
Expand Down Expand Up @@ -308,8 +308,6 @@ public Response getRestoreStatus(@Parameter(description = "Unique identifier of

@Operation(summary = "Retry restore", description = "Retry a failed restore operation")
@APIResponses({
@APIResponse(responseCode = "200", description = "Restore operation retried successfully",
content = @Content(schema = @Schema(implementation = RestoreResponse.class))),
@APIResponse(responseCode = "202", description = "Restore retry accepted and is being processed",
content = @Content(schema = @Schema(implementation = RestoreResponse.class))),
@APIResponse(responseCode = "401", description = "Authentication is required and has failed or has not been provided"),
Expand All @@ -324,7 +322,6 @@ public Response getRestoreStatus(@Parameter(description = "Unique identifier of
public Response retryRestore(@Parameter(description = "Unique identifier of the restore operation", required = true)
@PathParam("restoreName")
String restoreName) {
dbBackupV2Service.retryRestore(restoreName);
return Response.ok().build();
return Response.accepted(dbBackupV2Service.retryRestore(restoreName)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.persistence.AttributeConverter;

import java.io.IOException;
import java.util.SortedMap;

Expand All @@ -24,7 +24,8 @@ public String convertToDatabaseColumn(SortedMap<Object, Object> attribute) {
@Override
public SortedMap<Object, Object> convertToEntityAttribute(String dbData) {
try {
return objectMapper.readValue(dbData, new TypeReference<SortedMap<Object, Object>>() {});
return objectMapper.readValue(dbData, new TypeReference<SortedMap<Object, Object>>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netcracker.cloud.dbaas.dao.jpa;

import com.netcracker.cloud.dbaas.dto.backupV2.Filter;
import com.netcracker.cloud.dbaas.entity.pg.Database;
import com.netcracker.cloud.dbaas.entity.pg.DatabaseRegistry;
import com.netcracker.cloud.dbaas.repositories.dbaas.DatabaseRegistryDbaasRepository;
Expand All @@ -12,23 +13,18 @@
import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;

import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy;
import org.apache.commons.lang.StringUtils;

import javax.annotation.Nullable;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import static com.netcracker.cloud.dbaas.Constants.MICROSERVICE_NAME;
import static com.netcracker.cloud.dbaas.Constants.ROLE;
import static com.netcracker.cloud.dbaas.Constants.SCOPE;
import static com.netcracker.cloud.dbaas.Constants.SCOPE_VALUE_TENANT;
import static com.netcracker.cloud.dbaas.Constants.*;
import static com.netcracker.cloud.dbaas.config.ServicesConfig.DBAAS_REPOSITORIES_MUTEX;
import static jakarta.transaction.Transactional.TxType.REQUIRES_NEW;

Expand Down Expand Up @@ -141,6 +137,11 @@ public List<DatabaseRegistry> findAllTransactionalDatabaseRegistries(String name
return databaseRegistryRepository.findAllByNamespaceAndDatabase_BgVersionNull(namespace);
}

@Override
public List<DatabaseRegistry> findAllDatabasesByFilter(List<Filter> filters) {
return databaseRegistryRepository.findAllDatabasesByFilter(filters);
}

@Override
public void delete(DatabaseRegistry databaseRegistry) {
log.debug("Delete logical database with classifier {} and type {}", databaseRegistry.getClassifier(), databaseRegistry.getType());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.netcracker.cloud.dbaas.dto.backupV2;

import com.netcracker.cloud.dbaas.enums.ExternalDatabaseStrategy;
import com.netcracker.cloud.dbaas.utils.validation.BackupGroup;
import com.netcracker.cloud.dbaas.utils.validation.group.BackupGroup;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netcracker.cloud.dbaas.enums.BackupStatus;
import com.netcracker.cloud.dbaas.enums.ExternalDatabaseStrategy;
import com.netcracker.cloud.dbaas.utils.validation.BackupGroup;
import com.netcracker.cloud.dbaas.utils.validation.group.BackupGroup;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.netcracker.cloud.dbaas.dto.backupV2;

import com.netcracker.cloud.dbaas.enums.ClassifierType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.SortedMap;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ClassifierResponse {
private ClassifierType type;
private SortedMap<String, Object> classifier;
private SortedMap<String, Object> classifierBeforeMapper;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.netcracker.cloud.dbaas.dto.backupV2;

import com.netcracker.cloud.dbaas.utils.validation.NotEmptyFilter;
import com.netcracker.cloud.dbaas.utils.validation.group.BackupGroup;
import com.netcracker.cloud.dbaas.utils.validation.group.RestoreGroup;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
Expand All @@ -9,6 +12,7 @@
import java.util.List;

@Data
@NotEmptyFilter(groups = {BackupGroup.class, RestoreGroup.class})
@NoArgsConstructor
@Schema(description = "Single filter criteria for backup and restore operations")
public class Filter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.netcracker.cloud.dbaas.dto.backupV2;

import com.netcracker.cloud.dbaas.utils.validation.BackupGroup;
import com.netcracker.cloud.dbaas.utils.validation.group.BackupGroup;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.util.ArrayList;
import java.util.List;

@Data
Expand All @@ -23,13 +25,11 @@ public class FilterCriteria {
)
@NotNull(groups = {BackupGroup.class})
@Size(min = 1, groups = {BackupGroup.class})
private List<Filter> filter;
@Schema(
description = "Include databases that match any of the filters in the list"
)
private List<Filter> include;
@Valid
private List<Filter> filter = new ArrayList<>();

@Schema(
description = "Exclude databases that match any of the filters in the list"
)
private List<Filter> exclude;
private List<Filter> exclude = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RestoreDatabaseResponse {
description = "List of database classifiers. Each classifier is a sorted map of attributes.",
examples = "[{\"namespace\":\"namespace\", \"microserviceName\":\"microserviceName\", \"scope\":\"service\"}]"
)
private List<Map<String, Object>> classifiers;
private List<ClassifierResponse> classifiers;
@Schema(
description = "List of database users",
examples = "[{\"name\":\"username\",\"role\":\"admin\"}"
Expand Down Expand Up @@ -58,7 +58,7 @@ public class RestoreDatabaseResponse {
required = true
)
private String path;
@Schema(description = "Error message if the backup failed", examples = "Restore Not Found")
@Schema(description = "Error message if the backup failed", examples = "Restore Not Found")
private String errorMessage;
@Schema(description = "Timestamp when the restore was created", examples = "2025-11-13T12:34:56Z")
private Instant creationTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.util.List;
import java.util.SortedMap;

@Data
@NoArgsConstructor
Expand All @@ -19,6 +18,6 @@ public class RestoreExternalDatabaseResponse {
description = "List of database classifiers. Each classifier is a sorted map of attributes.",
examples = "[{\"namespace\":\"namespace\", \"microserviceName\":\"microserviceName\", \"scope\":\"service\"}]"
)
private List<SortedMap<String, Object>> classifiers;
private List<ClassifierResponse> classifiers;
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.netcracker.cloud.dbaas.dto.backupV2;

import com.netcracker.cloud.dbaas.enums.ExternalDatabaseStrategy;
import com.netcracker.cloud.dbaas.utils.validation.RestoreGroup;
import com.netcracker.cloud.dbaas.utils.validation.group.RestoreGroup;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.ConvertGroup;
import jakarta.validation.groups.Default;
Expand All @@ -21,6 +22,7 @@ public class RestoreRequest {
"restore-before-prod-update-20251203T1020-4t6S"
}
)
@NotBlank
private String restoreName;
@Schema(
description = "Name of the storage backend containing the restore",
Expand All @@ -29,6 +31,7 @@ public class RestoreRequest {
"s3-backend"
}
)
@NotBlank
private String storageName;
@Schema(
description = "Path to the restore file in the storage",
Expand All @@ -37,6 +40,7 @@ public class RestoreRequest {
"/backups"
}
)
@NotBlank
private String blobPath;
@Schema(
description = "Filter criteria",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.netcracker.cloud.dbaas.enums.ExternalDatabaseStrategy;
import com.netcracker.cloud.dbaas.enums.RestoreStatus;
import com.netcracker.cloud.dbaas.utils.validation.RestoreGroup;
import com.netcracker.cloud.dbaas.utils.validation.group.RestoreGroup;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.ConvertGroup;
Expand Down Expand Up @@ -89,10 +89,6 @@ public class RestoreResponse {
examples = "Backup Not Found"
)
private String errorMessage;
@Schema(description = "Aggregated duration of databases", examples = "1200")
private Long duration;
@Schema(description = "Total number of adapter requests", examples = "1")
private Integer attemptCount;
@Schema(
description = "List of logical restores",
implementation = LogicalRestoreResponse.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.netcracker.cloud.dbaas.entity.dto.backupV2;

import com.netcracker.cloud.dbaas.entity.pg.backupV2.Classifier;
import com.netcracker.cloud.dbaas.entity.pg.backupV2.BackupDatabase;

import java.util.List;
import java.util.SortedMap;


public record BackupDatabaseDelegate(BackupDatabase backupDatabase,
List<SortedMap<String, Object>> classifiers) {}
List<Classifier> classifiers) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.netcracker.cloud.dbaas.entity.dto.backupV2;

import com.netcracker.cloud.dbaas.entity.pg.backupV2.Classifier;
import com.netcracker.cloud.dbaas.entity.pg.backupV2.BackupExternalDatabase;

import java.util.List;

public record BackupExternalDelegate(BackupExternalDatabase backupExternalDatabase, List<Classifier> classifiers) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.netcracker.cloud.dbaas.entity.pg.backupV2;

import com.netcracker.cloud.dbaas.enums.ClassifierType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.SortedMap;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Classifier {
private ClassifierType type;
private SortedMap<String, Object> classifier;
private SortedMap<String, Object> classifierBeforeMapper;

@Override
public boolean equals(Object o) {
if (!(o instanceof Classifier that)) return false;
return type == that.type && Objects.equals(classifier, that.classifier) && Objects.equals(classifierBeforeMapper, that.classifierBeforeMapper);
}

@Override
public int hashCode() {
return Objects.hash(type, classifier, classifierBeforeMapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.UUID;

@Data
Expand Down Expand Up @@ -41,7 +40,7 @@ public class RestoreDatabase {
@NotNull
@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb")
private List<SortedMap<String, Object>> classifiers;
private List<Classifier> classifiers;

@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.hibernate.type.SqlTypes;

import java.util.List;
import java.util.SortedMap;
import java.util.UUID;

@Data
Expand Down Expand Up @@ -40,5 +39,5 @@ public class RestoreExternalDatabase {
@NotNull
@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb")
private List<SortedMap<String, Object>> classifiers;
private List<Classifier> classifiers;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.netcracker.cloud.dbaas.enums;

public enum ClassifierType {
NEW, REPLACED, TRANSIENT_REPLACED
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.netcracker.cloud.dbaas.dto.Source;
import com.netcracker.cloud.dbaas.dto.backupV2.*;
import com.netcracker.cloud.dbaas.entity.dto.backupV2.BackupExternalDelegate;
import com.netcracker.cloud.dbaas.entity.pg.backupV2.*;
import com.netcracker.cloud.dbaas.enums.BackupTaskStatus;
import com.netcracker.cloud.dbaas.enums.RestoreTaskStatus;
Expand Down Expand Up @@ -100,7 +101,13 @@ private static <T extends Enum<T>, R extends Enum<R>> R mapStatus(
}

@Mapping(target = "id", ignore = true)
RestoreExternalDatabase toRestoreExternalDatabase(BackupExternalDatabase backupExternalDatabase);
@Mapping(target = "name", source = "backupExternalDatabase.name")
@Mapping(target = "type", source = "backupExternalDatabase.type")
@Mapping(target = "classifiers", source = "classifiers")
RestoreExternalDatabase toRestoreExternalDatabase(BackupExternalDelegate backupExternalDelegate);

List<RestoreExternalDatabase> toRestoreExternalDatabases(List<BackupExternalDatabase> backupExternalDatabases);
List<RestoreExternalDatabase> toRestoreExternalDatabases(List<BackupExternalDelegate> backupExternalDelegates);

ClassifierResponse toClassifierResponse(Classifier classifier);
List<ClassifierResponse> toClassifierResponse(List<Classifier> classifiers);
}
Loading
Loading