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

GONRG-863

Changes:
Added exception handling
Refactoring
Move BackupServiceImpl.java to core
parent 6873e116
......@@ -7,14 +7,14 @@
<parent>
<artifactId>backup-service</artifactId>
<groupId>org.opengroup.osdu</groupId>
<version>1.0.0</version>
<version>0.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>backup-core</artifactId>
<description>Backup service Core on GCP</description>
<version>1.0.0</version>
<version>0.0.1</version>
<dependencies>
<dependency>
......
......@@ -9,7 +9,7 @@ import org.opengroup.osdu.backup.model.BackupImportRequest;
import org.opengroup.osdu.backup.model.BackupRole;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.model.BackupStamp;
import org.opengroup.osdu.backup.provider.interfaces.BackupService;
import org.opengroup.osdu.backup.service.BackupService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
......
package org.opengroup.osdu.backup.config;
import org.opengroup.osdu.backup.locator.AssetManagerFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.ServiceLocatorFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AssetConfig {
public class AssetLocatorConfig {
@Bean
public FactoryBean serviceLocatorFactoryBean() {
......
/*
* Copyright 2020 Google LLC
* Copyright 2020 EPAM Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.backup.exception;
import java.util.logging.Level;
import lombok.extern.java.Log;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
@Log
public class AppExceptionHandler {
@ExceptionHandler(AppException.class)
public ResponseEntity<Object> handleAppExceptions(AppException e) {
return this.getErrorResponse(e);
}
private ResponseEntity<Object> getErrorResponse(AppException e) {
String exceptionMsg = e.getOriginalException() != null
? e.getOriginalException().getMessage()
: e.getError().getMessage();
if (e.getError().getCode() > 499) {
log.log(Level.SEVERE, exceptionMsg, e.getOriginalException());
} else {
log.log(Level.WARNING, exceptionMsg, e.getOriginalException());
}
return new ResponseEntity<Object>(e.getError(), HttpStatus.resolve(e.getError().getCode()));
}
}
package org.opengroup.osdu.backup.config;
package org.opengroup.osdu.backup.locator;
import org.opengroup.osdu.backup.locator.Asset;
import org.opengroup.osdu.backup.provider.interfaces.AssetBackupManager;
import org.opengroup.osdu.backup.manager.AssetBackupManager;
public interface AssetManagerFactory {
......
package org.opengroup.osdu.backup.provider.interfaces;
package org.opengroup.osdu.backup.manager;
import java.util.List;
import org.opengroup.osdu.backup.model.BackupSchedule;
......
......@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.opengroup.osdu.backup.locator.Asset;
@Data
@NoArgsConstructor
......@@ -13,4 +14,6 @@ public class BackupImportRequest {
private String backupStampId;
private Asset asset;
}
package org.opengroup.osdu.backup.provider.interfaces;
package org.opengroup.osdu.backup.repository;
import java.time.LocalDateTime;
import java.util.EnumMap;
......
package org.opengroup.osdu.backup.provider.interfaces;
package org.opengroup.osdu.backup.repository;
import java.util.List;
import java.util.Map;
......
package org.opengroup.osdu.backup.provider.interfaces;
package org.opengroup.osdu.backup.service;
import java.util.EnumMap;
import java.util.List;
......
package org.opengroup.osdu.backup.provider.gcp.service;
package org.opengroup.osdu.backup.service.impl;
import java.util.EnumMap;
......@@ -7,14 +7,14 @@ import java.util.Map;
import java.util.Objects;
import javax.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.backup.config.AssetManagerFactory;
import org.opengroup.osdu.backup.locator.Asset;
import org.opengroup.osdu.backup.locator.AssetManagerFactory;
import org.opengroup.osdu.backup.model.BackupImportRequest;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.model.BackupStamp;
import org.opengroup.osdu.backup.provider.interfaces.BackupService;
import org.opengroup.osdu.backup.provider.interfaces.BackupStampRepository;
import org.opengroup.osdu.backup.provider.interfaces.ScheduleRepository;
import org.opengroup.osdu.backup.repository.BackupStampRepository;
import org.opengroup.osdu.backup.repository.ScheduleRepository;
import org.opengroup.osdu.backup.service.BackupService;
import org.opengroup.osdu.backup.shedulers.SchedulerService;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.http.HttpStatus;
......@@ -71,8 +71,7 @@ public class BackupServiceImpl implements BackupService {
@Override
public BackupStamp submitBackupImportRequest(BackupImportRequest importRequest) {
return factory.getAssetManager(Asset.DATASTORE)
.importBackup(importRequest.getBackupStampId());
return factory.getAssetManager(importRequest.getAsset()).importBackup(importRequest.getBackupStampId());
}
@Override
......
package org.opengroup.osdu.backup.shedulers;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.backup.manager.AssetBackupManager;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.provider.interfaces.AssetBackupManager;
@RequiredArgsConstructor
public class BackupScheduledTask implements Runnable {
......
......@@ -4,10 +4,10 @@ import java.time.LocalDateTime;
import java.util.EnumMap;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.backup.config.AssetManagerFactory;
import org.opengroup.osdu.backup.locator.Asset;
import org.opengroup.osdu.backup.locator.AssetManagerFactory;
import org.opengroup.osdu.backup.model.BackupStamp;
import org.opengroup.osdu.backup.provider.interfaces.BackupStampRepository;
import org.opengroup.osdu.backup.repository.BackupStampRepository;
@RequiredArgsConstructor
public class TearDownBackupScheduledTask implements Runnable {
......
......@@ -8,8 +8,8 @@ import java.util.logging.Level;
import javax.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import org.opengroup.osdu.backup.config.AssetManagerFactory;
import org.opengroup.osdu.backup.config.property.SchedulersProperties;
import org.opengroup.osdu.backup.locator.AssetManagerFactory;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.shedulers.BackupScheduledTask;
import org.opengroup.osdu.backup.shedulers.SchedulerService;
......
......@@ -2,9 +2,9 @@ package org.opengroup.osdu.backup.shedulers.impl;
import javax.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.backup.config.AssetManagerFactory;
import org.opengroup.osdu.backup.config.property.SchedulersProperties;
import org.opengroup.osdu.backup.provider.interfaces.BackupStampRepository;
import org.opengroup.osdu.backup.locator.AssetManagerFactory;
import org.opengroup.osdu.backup.repository.BackupStampRepository;
import org.opengroup.osdu.backup.shedulers.TearDownBackupScheduledTask;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.PeriodicTrigger;
......
......@@ -2,7 +2,6 @@ package org.opengroup.osdu.backup.shedulers.impl;
import static java.lang.Thread.sleep;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
......@@ -16,12 +15,11 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.opengroup.osdu.backup.config.AssetManagerFactory;
import org.opengroup.osdu.backup.config.property.SchedulersProperties;
import org.opengroup.osdu.backup.locator.Asset;
import org.opengroup.osdu.backup.locator.AssetManagerFactory;
import org.opengroup.osdu.backup.manager.AssetBackupManager;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.provider.interfaces.AssetBackupManager;
import org.springframework.test.util.ReflectionTestUtils;
@RunWith(MockitoJUnitRunner.class)
public class SchedulerServiceImplTest {
......@@ -32,7 +30,7 @@ public class SchedulerServiceImplTest {
@Mock
private AssetBackupManager assetBackupManager;
@Mock
@Mock
private SchedulersProperties schedulersProperties;
@InjectMocks
......
......@@ -24,20 +24,20 @@
<parent>
<artifactId>backup-service</artifactId>
<groupId>org.opengroup.osdu</groupId>
<version>1.0.0</version>
<version>0.0.1</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>backup-gcp</artifactId>
<description>Backup service on GCP</description>
<version>1.0.0</version>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>backup-core</artifactId>
<version>1.0.0</version>
<version>0.0.1</version>
</dependency>
<dependency>
......
......@@ -32,13 +32,13 @@ import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import org.opengroup.osdu.backup.manager.AssetBackupManager;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.model.BackupStamp;
import org.opengroup.osdu.backup.provider.gcp.config.property.PropertiesConfiguration;
import org.opengroup.osdu.backup.provider.gcp.model.constant.Constants;
import org.opengroup.osdu.backup.provider.gcp.model.entity.BackupStampEntity;
import org.opengroup.osdu.backup.provider.interfaces.AssetBackupManager;
import org.opengroup.osdu.backup.provider.interfaces.BackupStampRepository;
import org.opengroup.osdu.backup.repository.BackupStampRepository;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
......
......@@ -3,9 +3,9 @@ package org.opengroup.osdu.backup.provider.gcp.manager;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import org.opengroup.osdu.backup.manager.AssetBackupManager;
import org.opengroup.osdu.backup.model.BackupSchedule;
import org.opengroup.osdu.backup.model.BackupStamp;
import org.opengroup.osdu.backup.provider.interfaces.AssetBackupManager;
import org.springframework.stereotype.Component;
@Log
......
......@@ -10,7 +10,7 @@ import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.backup.locator.Asset;
import org.opengroup.osdu.backup.model.BackupStamp;
import org.opengroup.osdu.backup.provider.gcp.model.entity.BackupStampEntity;
import org.opengroup.osdu.backup.provider.interfaces.BackupStampRepository;
import org.opengroup.osdu.backup.repository.BackupStampRepository;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
......
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