Commit bb46c3dd authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

GONRG-693 POC

Fix listAvailable backups , added OSDU common exception handling
parent 51c461b5
......@@ -17,6 +17,11 @@
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
......
......@@ -34,8 +34,10 @@ import org.opengroup.osdu.backup.model.BackupsResponse;
import org.opengroup.osdu.backup.model.SubmitTaskRequest;
import org.opengroup.osdu.backup.provider.gcp.model.GCPSubmitTask;
import org.opengroup.osdu.backup.provider.interfaces.BackupRepository;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Repository;
@Log
......@@ -44,6 +46,7 @@ import org.springframework.stereotype.Repository;
public class BackupRepositoryImpl implements BackupRepository {
private static final String OUTPUT_URL_PREFIX = "outputUrlPrefix";
private static final String OVERALL_EXPORT_METADATA = ".overall_export_metadata";
private JsonFactory JSON_FACTORY = new JacksonFactory();
......@@ -92,7 +95,7 @@ public class BackupRepositoryImpl implements BackupRepository {
repository.save(oneByKindAndNamespace);
} catch (IOException e) {
// TODO OSDU
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e.getMessage());
}
}
......@@ -103,8 +106,8 @@ public class BackupRepositoryImpl implements BackupRepository {
GoogleDatastoreAdminV1ImportEntitiesRequest importRequest = new GoogleDatastoreAdminV1ImportEntitiesRequest();
importRequest.setInputUrl(backup.getBackupPath());
getDatastore().projects().datastoreImport(projectID, importRequest).execute();
} catch (IOException ioException) {
ioException.printStackTrace();
} catch (IOException e) {
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e.getMessage());
}
}
......@@ -121,9 +124,10 @@ public class BackupRepositoryImpl implements BackupRepository {
BackupsResponse backupsResponse = new BackupsResponse();
Page<Blob> list = storage.list(backupBucket);
HashMap<String, HashMap<String, List<String>>> assetsMap = new HashMap<>();
for (Blob blob : list.getValues()) {
String[] pathSplit = blob.getName().split("/");
if (pathSplit.length > 1) {
if (blob.getName().contains(OVERALL_EXPORT_METADATA)) {
String[] pathSplit = blob.getName().split("/");
HashMap<String, List<String>> backupCollectionsMap = assetsMap.get(pathSplit[0]);
if (backupCollectionsMap != null) {
List<String> backupsList = backupCollectionsMap.get(pathSplit[1]);
......@@ -164,7 +168,7 @@ public class BackupRepositoryImpl implements BackupRepository {
new HttpCredentialsAdapter(credential));
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e.getMessage());
}
}
return datastore;
......@@ -178,7 +182,7 @@ public class BackupRepositoryImpl implements BackupRepository {
private String getInputUrlPrefixRequest(String[] path) {
return "gs://" + backupBucket + "/" + path[0] + "/" + path[1] + "/" + path[2] + "/" + path[2]
+ ".overall_export_metadata";
+ OVERALL_EXPORT_METADATA;
}
private GoogleDatastoreAdminV1ExportEntitiesRequest buildExportEntitiesRequest(
......
......@@ -2,6 +2,7 @@ package org.opengroup.osdu.backup.provider.gcp.repository;
import java.util.List;
import java.util.Objects;
import javax.annotation.PostConstruct;
import org.opengroup.osdu.backup.model.BackupImportRequest;
import org.opengroup.osdu.backup.model.BackupsResponse;
......@@ -25,12 +26,19 @@ public class BackupServiceImpl implements BackupService {
@Autowired
private SchedulerService schedulerService;
@PostConstruct
public void startUpSchedulers() {
List<SubmitTaskRequest> submitTaskRequestList = backupRepository.listBackupSchedules();
submitTaskRequestList.stream().filter(SubmitTaskRequest::isActive)
.forEach(t -> schedulerService.addTaskToScheduler(t));
}
@Override
public void submitScheduledTask(SubmitTaskRequest submitTaskRequest) {
GCPSubmitTask taskExist = taskRepository
.findOneByKindAndNamespace(submitTaskRequest.getKind(), submitTaskRequest.getNamespace());
if (taskExist != null) {
if (Objects.nonNull(taskExist)) {
if (submitTaskRequest.isActive() != taskExist.isActive()) {
schedulerService.taskStatusChanged(submitTaskRequest);
taskExist.setActive(submitTaskRequest.isActive());
......@@ -58,9 +66,5 @@ public class BackupServiceImpl implements BackupService {
return backupRepository.listAvailableBackups();
}
@PostConstruct
public void startUpSchedulers() {
List<SubmitTaskRequest> submitTaskRequestList = backupRepository.listBackupSchedules();
submitTaskRequestList.stream().filter(SubmitTaskRequest::isActive).forEach(t -> schedulerService.addTaskToScheduler(t));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment