Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Deployment and Operations
Backup Service
Commits
cfad8e06
Commit
cfad8e06
authored
Feb 09, 2021
by
Rustam Lotsmanenko (EPAM)
Browse files
delete redundant classes after mr conflict resolving
parent
1ff2ae48
Pipeline
#25561
passed with stages
in 7 minutes and 34 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backup-core/src/main/java/org/opengroup/osdu/backup/service/impl/BackupServiceImpl.java
deleted
100644 → 0
View file @
1ff2ae48
/*
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
http://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.service.impl
;
import
java.util.EnumMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
lombok.RequiredArgsConstructor
;
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.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
;
import
org.springframework.stereotype.Service
;
@Service
@RequiredArgsConstructor
public
class
BackupServiceImpl
implements
BackupService
{
private
final
SchedulerService
schedulerService
;
private
final
BackupStampRepository
backupStampRepository
;
private
final
ScheduleRepository
scheduleRepository
;
private
final
AssetManagerFactory
factory
;
//TODO currently schedules startup changed to BackupCollectionServiceImpl.startUpSchedulers()
// @PostConstruct
public
void
startUpSchedulers
()
{
List
<
BackupSchedule
>
backupScheduleList
=
scheduleRepository
.
listBackupSchedules
();
backupScheduleList
.
stream
()
/*.filter(BackupSchedule::isActive)*/
.
forEach
(
schedulerService:
:
addTaskToScheduler
);
}
@Override
public
BackupSchedule
submitBackupSchedule
(
BackupSchedule
backupSchedule
)
{
Map
<
String
,
String
>
assetContext
=
backupSchedule
.
getAssetContext
();
BackupSchedule
byAssetContext
=
scheduleRepository
.
findByAssetContext
(
backupSchedule
.
getAssetType
(),
assetContext
);
if
(
Objects
.
nonNull
(
byAssetContext
))
{
throw
new
AppException
(
HttpStatus
.
CONFLICT
.
value
(),
"Conflict"
,
String
.
format
(
"Schedule with context %s already exist"
,
assetContext
));
}
else
{
BackupSchedule
savedSchedule
=
scheduleRepository
.
save
(
backupSchedule
);
schedulerService
.
addTaskToScheduler
(
backupSchedule
);
return
savedSchedule
;
}
}
@Override
public
BackupSchedule
updateBackupSchedule
(
BackupSchedule
backupSchedule
)
{
if
(
Objects
.
isNull
(
backupSchedule
.
getScheduleId
()))
{
throw
new
AppException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"Bad request"
,
"Schedule id required"
);
}
BackupSchedule
updatedSchedule
=
scheduleRepository
.
updateSchedule
(
backupSchedule
);
schedulerService
.
updateTask
(
updatedSchedule
);
return
updatedSchedule
;
}
@Override
public
BackupSchedule
getBackupSchedule
(
String
scheduleId
)
{
return
scheduleRepository
.
findById
(
scheduleId
);
}
@Override
public
BackupStamp
submitBackupImportRequest
(
BackupImportRequest
importRequest
)
{
return
factory
.
getAssetManager
(
importRequest
.
getAsset
()).
importBackup
(
importRequest
.
getBackupStampId
());
}
@Override
public
List
<
BackupSchedule
>
listSchedules
()
{
return
scheduleRepository
.
listBackupSchedules
();
}
@Override
public
EnumMap
<
Asset
,
List
<
BackupStamp
>>
listBackups
()
{
return
backupStampRepository
.
listAvailableBackupStamps
();
}
}
backup-core/src/main/java/org/opengroup/osdu/backup/shedulers/BackupScheduledTask.java
deleted
100644 → 0
View file @
1ff2ae48
/*
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
http://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.shedulers
;
import
lombok.RequiredArgsConstructor
;
import
org.opengroup.osdu.backup.manager.AssetBackupManager
;
import
org.opengroup.osdu.backup.model.BackupSchedule
;
@RequiredArgsConstructor
public
class
BackupScheduledTask
implements
Runnable
{
private
final
AssetBackupManager
assetBackupManager
;
private
final
BackupSchedule
backupSchedule
;
@Override
public
void
run
()
{
assetBackupManager
.
exportBackup
(
backupSchedule
);
}
}
backup-core/src/test/java/org/opengroup/osdu/backup/service/impl/BackupServiceImplTest.java
deleted
100644 → 0
View file @
1ff2ae48
package
org.opengroup.osdu.backup.service.impl
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.util.Collections
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.opengroup.osdu.backup.locator.Asset
;
import
org.opengroup.osdu.backup.model.BackupSchedule
;
import
org.opengroup.osdu.backup.repository.ScheduleRepository
;
import
org.opengroup.osdu.backup.shedulers.SchedulerService
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
BackupServiceImplTest
{
@Mock
private
SchedulerService
schedulerService
;
@Mock
private
ScheduleRepository
scheduleRepository
;
@InjectMocks
private
BackupServiceImpl
backupService
;
private
BackupSchedule
schedule
;
@Before
public
void
setUp
()
{
schedule
=
BackupSchedule
.
builder
()
/*.active(true)*/
.
assetType
(
Asset
.
DATASTORE
)
/*.backupPeriod(1).lifetime(1)*/
.
build
();
}
@Test
public
void
startUpSchedulers
()
{
when
(
scheduleRepository
.
listBackupSchedules
()).
thenReturn
(
Collections
.
singletonList
(
schedule
));
backupService
.
startUpSchedulers
();
verify
(
schedulerService
).
addTaskToScheduler
(
schedule
);
}
@Test
public
void
testSubmitSchedule
()
{
when
(
scheduleRepository
.
findByAssetContext
(
any
(),
any
())).
thenReturn
(
null
);
when
(
scheduleRepository
.
save
(
any
())).
thenReturn
(
schedule
);
backupService
.
submitBackupSchedule
(
schedule
);
verify
(
schedulerService
).
addTaskToScheduler
(
schedule
);
}
@Test
(
expected
=
AppException
.
class
)
public
void
testSubmitExistingSchedule
()
{
when
(
scheduleRepository
.
findByAssetContext
(
any
(),
any
())).
thenReturn
(
schedule
);
backupService
.
submitBackupSchedule
(
schedule
);
}
@Test
(
expected
=
AppException
.
class
)
public
void
updateBadRequestBackupSchedule
()
{
backupService
.
updateBackupSchedule
(
schedule
);
}
}
\ No newline at end of file
provider/backup-gcp/src/main/java/org/opengroup/osdu/backup/provider/gcp/repository/DatastoreScheduleRepository.java
deleted
100644 → 0
View file @
1ff2ae48
/*
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
http://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.provider.gcp.repository
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.StreamSupport
;
import
lombok.RequiredArgsConstructor
;
import
org.opengroup.osdu.backup.locator.Asset
;
import
org.opengroup.osdu.backup.model.BackupSchedule
;
import
org.opengroup.osdu.backup.provider.gcp.mapper.BackupScheduleMapper
;
import
org.opengroup.osdu.backup.provider.gcp.model.entity.BackupScheduleEntity
;
import
org.opengroup.osdu.backup.repository.ScheduleRepository
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
@Service
@RequiredArgsConstructor
public
class
DatastoreScheduleRepository
implements
ScheduleRepository
{
private
final
SchedulesEntityRepository
schedulesEntityRepository
;
private
final
BackupScheduleMapper
backupScheduleMapper
;
@Override
public
List
<
BackupSchedule
>
listBackupSchedules
()
{
Iterable
<
BackupScheduleEntity
>
gcpSubmitTasks
=
schedulesEntityRepository
.
findAll
();
List
<
BackupScheduleEntity
>
collect
=
StreamSupport
.
stream
(
gcpSubmitTasks
.
spliterator
(),
false
)
.
collect
(
Collectors
.
toList
());
return
collect
.
stream
().
map
(
backupScheduleMapper:
:
toBackupSchedule
).
collect
(
Collectors
.
toList
());
}
@Override
public
BackupSchedule
submitSchedule
(
BackupSchedule
backupSchedule
)
{
BackupScheduleEntity
saved
=
schedulesEntityRepository
.
save
(
backupScheduleMapper
.
toEntity
(
backupSchedule
));
return
backupScheduleMapper
.
toBackupSchedule
(
saved
);
}
@Override
public
BackupSchedule
updateSchedule
(
BackupSchedule
backupSchedule
)
{
BackupScheduleEntity
scheduleEntity
=
schedulesEntityRepository
.
findByScheduleId
(
backupSchedule
.
getScheduleId
())
.
orElseThrow
((()
->
new
AppException
(
HttpStatus
.
NOT_FOUND
.
value
(),
"Not found"
,
String
.
format
(
"Schedule with scheduleId=%s not found"
,
backupSchedule
.
getScheduleId
()))));
BackupScheduleEntity
backupScheduleEntity
=
backupScheduleMapper
.
toEntity
(
backupSchedule
);
BeanUtils
.
copyProperties
(
backupScheduleEntity
,
scheduleEntity
);
return
backupScheduleMapper
.
toBackupSchedule
(
schedulesEntityRepository
.
save
(
scheduleEntity
));
}
// TODO define correct way to find schedules by context
@Override
public
BackupSchedule
findByAssetContext
(
Asset
asset
,
Map
<
String
,
String
>
assetContext
)
{
// Optional<BackupScheduleEntity> taskExist;
// if (asset.equals(Asset.SQL)) {
// String instance = assetContext.get(Constants.CONTEXT_INSTANCE);
// taskExist = sqlTypeScheduleEntityRepository.findByInstance(instance);
// } else {
// String kind = assetContext.get(Constants.CONTEXT_KIND);
// String namespace = assetContext.get(Constants.CONTEXT_NAMESPACE);
// taskExist = datastoreTypeScheduleEntityRepository.findByNamespaceAndKind(namespace, kind);
// }
// return Objects.isNull(taskExist) ? null : backupScheduleMapper.toBackupSchedule(taskExist);
return
null
;
}
@Override
public
BackupSchedule
save
(
BackupSchedule
backupSchedule
)
{
BackupScheduleEntity
backupScheduleEntity
=
backupScheduleMapper
.
toEntity
(
backupSchedule
);
return
backupScheduleMapper
.
toBackupSchedule
(
schedulesEntityRepository
.
save
(
backupScheduleEntity
));
}
@Override
public
BackupSchedule
findById
(
String
scheduleId
)
{
BackupScheduleEntity
scheduleById
=
schedulesEntityRepository
.
findByScheduleId
(
scheduleId
)
.
orElseThrow
(()
->
new
AppException
(
HttpStatus
.
NOT_FOUND
.
value
(),
"Not found"
,
String
.
format
(
"Schedule with scheduleId=%s not found"
,
scheduleId
)));
return
backupScheduleMapper
.
toBackupSchedule
(
scheduleById
);
}
}
testing/backup-test-core/src/main/java/org/opengroup/osdu/backup/apitest/Backup.java
deleted
100644 → 0
View file @
1ff2ae48
package
org.opengroup.osdu.backup.apitest
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
org.opengroup.osdu.backup.TestBase
;
import
org.opengroup.osdu.backup.model.BackupSchedule
;
public
abstract
class
Backup
extends
TestBase
{
static
final
String
SCHEDULE
=
"/schedule"
;
static
final
String
SCHEDULE_LIST
=
"/list_schedules"
;
static
final
String
BACKUP_IMPORT
=
"/backup_import"
;
static
final
String
BACKUP_LIST
=
"/list_backups"
;
static
final
String
GET_ID
=
"?id="
;
protected
static
ObjectMapper
mapper
=
new
ObjectMapper
();
protected
static
List
<
String
>
scheduleIds
=
new
ArrayList
<>();
@Test
public
void
shouldCreateBackupSchedule
()
throws
Exception
{
}
@Test
public
void
shouldUpdateSchedule
()
throws
Exception
{
}
@Test
public
void
shouldReturnCreatedScheduleById
()
throws
Exception
{
}
@Test
public
void
getSchedulesShouldReturnSchedulesWithCreatedSchedule
()
throws
Exception
{
}
@Test
public
void
shouldReturnConflictWhenCreateScheduleWithExistingAssetContext
()
throws
Exception
{
}
@Test
public
void
shouldReturnNotFoundForNotExistingSchedule
()
throws
Exception
{
}
@Test
public
void
shouldReturnNotFoundWhenImportNotExistingBackup
()
throws
Exception
{
}
@Test
public
void
shouldReturnOkWhenListAvailableBackups
()
throws
Exception
{
}
@Test
public
void
shouldReturnNotAuthorizedWhenGivenAnonymous
()
throws
Exception
{
}
@Test
public
void
shouldReturnNotAuthorizedWhenGivenNoAccess
()
throws
Exception
{
}
private
BackupSchedule
submitBackupSchedule
()
throws
Exception
{
return
null
;
}
private
void
cancelSchedule
(
BackupSchedule
schedule
)
throws
Exception
{
}
}
testing/backup-test-gcp/src/test/java/org/opengroup/osdu/backup/TestBackup.java
deleted
100644 → 0
View file @
1ff2ae48
package
org.opengroup.osdu.backup
;
import
org.junit.jupiter.api.AfterAll
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.opengroup.osdu.backup.apitest.Backup
;
import
org.opengroup.osdu.backup.util.DatastoreUtil
;
public
class
TestBackup
extends
Backup
{
private
static
DatastoreUtil
datastoreUtil
;
@BeforeAll
static
void
setUp
()
{
}
@AfterAll
static
void
tearDown
()
throws
Exception
{
}
}
testing/backup-test-gcp/src/test/java/org/opengroup/osdu/backup/util/DatastoreUtil.java
deleted
100644 → 0
View file @
1ff2ae48
package
org.opengroup.osdu.backup.util
;
import
com.google.api.client.json.JsonFactory
;
import
com.google.api.client.json.jackson2.JacksonFactory
;
import
com.google.auth.oauth2.GoogleCredentials
;
import
com.google.cloud.datastore.Datastore
;
import
com.google.cloud.datastore.DatastoreOptions
;
import
com.google.cloud.datastore.Key
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
org.opengroup.osdu.backup.ConfigGCP
;
public
class
DatastoreUtil
{
private
final
JsonFactory
JSON_FACTORY
=
new
JacksonFactory
();
private
Datastore
datastore
;
public
void
deleteSchedule
(
String
name
)
throws
Exception
{
Key
backupSchedule
=
getDatastore
().
newKeyFactory
().
setKind
(
"BackupSchedule"
).
newKey
(
name
);
getDatastore
().
delete
(
backupSchedule
);
}
private
Datastore
getDatastore
()
throws
Exception
{
if
(
Objects
.
isNull
(
datastore
))
{
try
{
GoogleCredentials
credential
=
GoogleCredentials
.
fromStream
(
new
FileInputStream
(
ConfigGCP
.
getDatastoreCredentialsCredentials
()));
if
(
credential
.
createScopedRequired
())
{
List
<
String
>
scopes
=
new
ArrayList
<>();
scopes
.
add
(
"https://www.googleapis.com/auth/cloud-platform"
);
scopes
.
add
(
"https://www.googleapis.com/auth/datastore"
);
credential
=
credential
.
createScoped
(
scopes
);
}
credential
.
refreshAccessToken
();
return
datastore
=
DatastoreOptions
.
newBuilder
().
setNamespace
(
ConfigGCP
.
getDatastoreNamespace
())
.
setCredentials
(
credential
).
build
().
getService
();
}
catch
(
IOException
e
)
{
throw
new
Exception
(
e
);
}
}
return
datastore
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment