Skip to content

Commit ee6419b

Browse files
author
Epshteyn
committed
Removed unsupported attribute migration to graph database.
1 parent 25634e7 commit ee6419b

File tree

9 files changed

+87
-439
lines changed

9 files changed

+87
-439
lines changed

service/src/main/java/org/eclipse/keti/acs/monitoring/AcsDbHealthIndicator.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.eclipse.keti.acs.monitoring;
2020

21+
import org.eclipse.keti.acs.privilege.management.dao.GraphStartupManager;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
2324
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,8 +30,6 @@
2930
import org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException;
3031
import org.springframework.stereotype.Component;
3132

32-
import org.eclipse.keti.acs.privilege.management.dao.GraphMigrationManager;
33-
3433
@Component
3534
public class AcsDbHealthIndicator implements HealthIndicator {
3635

@@ -40,16 +39,16 @@ public class AcsDbHealthIndicator implements HealthIndicator {
4039
+ "sets stored in the database";
4140

4241
private final AcsMonitoringRepository acsMonitoringRepository;
43-
private GraphMigrationManager migrationManager;
42+
private GraphStartupManager startupManager;
4443

4544
@Autowired
4645
public AcsDbHealthIndicator(final AcsMonitoringRepository acsMonitoringRepository) {
4746
this.acsMonitoringRepository = acsMonitoringRepository;
4847
}
4948

5049
@Autowired(required = false)
51-
void setMigrationManager(final GraphMigrationManager migrationManager) {
52-
this.migrationManager = migrationManager;
50+
void setStartupManager(final GraphStartupManager startupManager) {
51+
this.startupManager = startupManager;
5352
}
5453

5554
@Override
@@ -64,7 +63,7 @@ private AcsMonitoringUtilities.HealthCode check() {
6463
LOGGER.debug("Checking ACS database status");
6564
this.acsMonitoringRepository.queryPolicySetTable();
6665

67-
if (this.migrationManager != null && !this.migrationManager.isMigrationComplete()) {
66+
if (this.startupManager != null && !this.startupManager.isStartupComplete()) {
6867
healthCode = AcsMonitoringUtilities.HealthCode.MIGRATION_INCOMPLETE;
6968
} else {
7069
healthCode = AcsMonitoringUtilities.HealthCode.AVAILABLE;

service/src/main/java/org/eclipse/keti/acs/monitoring/GraphDbHealthIndicator.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
package org.eclipse.keti.acs.monitoring;
2020

21+
import org.eclipse.keti.acs.privilege.management.dao.GraphResourceRepository;
22+
import org.eclipse.keti.acs.privilege.management.dao.GraphStartupManager;
23+
import org.janusgraph.core.JanusGraphConfigurationException;
24+
import org.janusgraph.core.QueryException;
25+
import org.janusgraph.diskstorage.ResourceUnavailableException;
2126
import org.slf4j.Logger;
2227
import org.slf4j.LoggerFactory;
2328
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,12 +33,6 @@
2833
import org.springframework.context.annotation.Profile;
2934
import org.springframework.stereotype.Component;
3035

31-
import org.eclipse.keti.acs.privilege.management.dao.GraphResourceRepository;
32-
import org.eclipse.keti.acs.privilege.management.dao.GraphMigrationManager;
33-
import org.janusgraph.core.QueryException;
34-
import org.janusgraph.core.JanusGraphConfigurationException;
35-
import org.janusgraph.diskstorage.ResourceUnavailableException;
36-
3736
@Component
3837
@Profile({ "graph" })
3938
public class GraphDbHealthIndicator implements HealthIndicator {
@@ -69,7 +68,7 @@ private AcsMonitoringUtilities.HealthCode check() {
6968
try {
7069
LOGGER.debug("Checking graph database status");
7170
if (this.resourceHierarchicalRepository
72-
.checkVersionVertexExists(GraphMigrationManager.INITIAL_ATTRIBUTE_GRAPH_VERSION)) {
71+
.checkVersionVertexExists(GraphStartupManager.INITIAL_ATTRIBUTE_GRAPH_VERSION)) {
7372
healthCode = AcsMonitoringUtilities.HealthCode.AVAILABLE;
7473
}
7574
} catch (QueryException e) {

service/src/main/java/org/eclipse/keti/acs/privilege/management/dao/GraphMigrationManager.java service/src/main/java/org/eclipse/keti/acs/privilege/management/dao/GraphStartupManager.java

+15-43
Original file line numberDiff line numberDiff line change
@@ -30,77 +30,49 @@
3030

3131
@Component
3232
@Profile("graph")
33-
public final class GraphMigrationManager {
33+
public final class GraphStartupManager {
3434
public static final int INITIAL_ATTRIBUTE_GRAPH_VERSION = 1;
3535

36-
private static final Logger LOGGER = LoggerFactory.getLogger(GraphMigrationManager.class);
37-
38-
@Autowired
39-
@Qualifier("resourceRepository")
40-
private ResourceRepository resourceRepository;
36+
private static final Logger LOGGER = LoggerFactory.getLogger(GraphStartupManager.class);
4137

4238
@Autowired
4339
@Qualifier("resourceHierarchicalRepository")
4440
private GraphResourceRepository resourceHierarchicalRepository;
41+
42+
private Boolean isStartupComplete = false;
4543

46-
@Autowired
47-
@Qualifier("subjectRepository")
48-
private SubjectRepository subjectRepository;
49-
50-
@Autowired
51-
@Qualifier("subjectHierarchicalRepository")
52-
private GraphSubjectRepository subjectHierarchicalRepository;
53-
54-
private Boolean isMigrationComplete = false;
55-
56-
static final int PAGE_SIZE = 1024;
57-
58-
private final ResourceMigrationManager resourceMigrationManager = new ResourceMigrationManager();
59-
private final SubjectMigrationManager subjectMigrationManager = new SubjectMigrationManager();
6044

6145
@PostConstruct
62-
public void doMigration() {
46+
public void doStartup() {
6347
// This version vertex is common to both subject and resource repositories. So this check is sufficient to
64-
// trigger migrations in both repos.
48+
// trigger startups in both repos.
6549
if (!this.resourceHierarchicalRepository.checkVersionVertexExists(INITIAL_ATTRIBUTE_GRAPH_VERSION)) {
6650

67-
// Migration needs to be performed in a separate thread to prevent cloud-foundry health check timeout,
51+
// Startup needs to be performed in a separate thread to prevent cloud-foundry health check timeout,
6852
// which restarts the service. (Max timeout is 180 seconds which is not enough)
6953
Executors.newSingleThreadExecutor().execute(new Runnable() {
7054
@Override
7155
public void run() {
7256
try {
73-
LOGGER.info("Starting attribute migration process to graph.");
74-
75-
//Rollback in the beginning to start with a clean state
76-
resourceMigrationManager.rollbackMigratedData(resourceHierarchicalRepository);
77-
subjectMigrationManager.rollbackMigratedData(subjectHierarchicalRepository);
78-
79-
//Run migration
80-
resourceMigrationManager.doResourceMigration(resourceRepository,
81-
resourceHierarchicalRepository, PAGE_SIZE);
82-
subjectMigrationManager.doSubjectMigration(subjectRepository,
83-
subjectHierarchicalRepository, PAGE_SIZE);
84-
57+
LOGGER.info("Starting attribute startup process to graph.");
8558
//Create version vertex, to record completion.
8659
resourceHierarchicalRepository.createVersionVertex(INITIAL_ATTRIBUTE_GRAPH_VERSION);
87-
isMigrationComplete = true;
88-
89-
LOGGER.info("Graph attribute migration complete. Created version: "
60+
isStartupComplete = true;
61+
LOGGER.info("Graph attribute startup complete. Created version: "
9062
+ INITIAL_ATTRIBUTE_GRAPH_VERSION);
9163
} catch (Exception e) {
92-
LOGGER.error("Exception during attribute migration: ", e);
64+
LOGGER.error("Exception during attribute startup: ", e);
9365
}
9466
}
9567
});
9668
} else {
97-
isMigrationComplete = true;
98-
LOGGER.info("Attribute Graph migration not required.");
69+
isStartupComplete = true;
70+
LOGGER.info("Attribute Graph startup not required.");
9971
}
10072
}
10173

102-
public boolean isMigrationComplete() {
103-
return this.isMigrationComplete;
74+
public boolean isStartupComplete() {
75+
return this.isStartupComplete;
10476
}
10577

10678
}

service/src/main/java/org/eclipse/keti/acs/privilege/management/dao/ResourceMigrationManager.java

-68
This file was deleted.

service/src/main/java/org/eclipse/keti/acs/privilege/management/dao/SubjectMigrationManager.java

-69
This file was deleted.

service/src/test/java/org/eclipse/keti/acs/monitoring/AcsDbHealthIndicatorTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.eclipse.keti.acs.monitoring;
2020

21-
import org.eclipse.keti.acs.privilege.management.dao.GraphMigrationManager;
21+
import org.eclipse.keti.acs.privilege.management.dao.GraphStartupManager;
2222
import org.mockito.Mockito;
2323
import org.mockito.internal.util.reflection.Whitebox;
2424
import org.springframework.boot.actuate.health.Status;
@@ -33,14 +33,14 @@
3333

3434
public class AcsDbHealthIndicatorTest {
3535

36-
private static final String IS_MIGRATION_COMPLETE_FIELD_NAME = "isMigrationComplete";
36+
private static final String IS_STARTUP_COMPLETE_FIELD_NAME = "isStartupComplete";
3737

3838
@Test(dataProvider = "statuses")
3939
public void testHealth(final AcsMonitoringRepository acsMonitoringRepository, final Status status,
40-
final AcsMonitoringUtilities.HealthCode healthCode, final GraphMigrationManager graphMigrationManager)
40+
final AcsMonitoringUtilities.HealthCode healthCode, final GraphStartupManager graphStartupManager)
4141
throws Exception {
4242
AcsDbHealthIndicator acsDbHealthIndicator = new AcsDbHealthIndicator(acsMonitoringRepository);
43-
acsDbHealthIndicator.setMigrationManager(graphMigrationManager);
43+
acsDbHealthIndicator.setStartupManager(graphStartupManager);
4444
Assert.assertEquals(status, acsDbHealthIndicator.health().getStatus());
4545
Assert.assertEquals(AcsDbHealthIndicator.DESCRIPTION,
4646
acsDbHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.DESCRIPTION_KEY));
@@ -54,31 +54,31 @@ public void testHealth(final AcsMonitoringRepository acsMonitoringRepository, fi
5454

5555
@DataProvider
5656
public Object[][] statuses() {
57-
GraphMigrationManager happyMigrationManager = new GraphMigrationManager();
58-
GraphMigrationManager sadMigrationManager = new GraphMigrationManager();
59-
Whitebox.setInternalState(happyMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, true);
60-
Whitebox.setInternalState(sadMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, false);
57+
GraphStartupManager happyStartupManager = new GraphStartupManager();
58+
GraphStartupManager sadStartupManager = new GraphStartupManager();
59+
Whitebox.setInternalState(happyStartupManager, IS_STARTUP_COMPLETE_FIELD_NAME, true);
60+
Whitebox.setInternalState(sadStartupManager, IS_STARTUP_COMPLETE_FIELD_NAME, false);
6161

6262
return new Object[][] { new Object[] { mockDbWithUp(), Status.UP, AcsMonitoringUtilities.HealthCode.AVAILABLE,
63-
happyMigrationManager },
63+
happyStartupManager },
6464

6565
{ mockDbWithException(new TransientDataAccessResourceException("")), Status.DOWN,
66-
AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager },
66+
AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyStartupManager },
6767

6868
{ mockDbWithException(new QueryTimeoutException("")), Status.DOWN,
69-
AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager },
69+
AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyStartupManager },
7070

7171
{ mockDbWithException(new DataSourceLookupFailureException("")), Status.DOWN,
72-
AcsMonitoringUtilities.HealthCode.UNREACHABLE, happyMigrationManager },
72+
AcsMonitoringUtilities.HealthCode.UNREACHABLE, happyStartupManager },
7373

7474
{ mockDbWithException(new PermissionDeniedDataAccessException("", null)), Status.DOWN,
75-
AcsMonitoringUtilities.HealthCode.MISCONFIGURATION, happyMigrationManager },
75+
AcsMonitoringUtilities.HealthCode.MISCONFIGURATION, happyStartupManager },
7676

7777
{ mockDbWithException(new ConcurrencyFailureException("")), Status.DOWN,
78-
AcsMonitoringUtilities.HealthCode.ERROR, happyMigrationManager },
78+
AcsMonitoringUtilities.HealthCode.ERROR, happyStartupManager },
7979

8080
{ mockDbWithUp(), Status.DOWN, AcsMonitoringUtilities.HealthCode.MIGRATION_INCOMPLETE,
81-
sadMigrationManager }, };
81+
sadStartupManager }, };
8282
}
8383

8484
private AcsMonitoringRepository mockDbWithUp() {

0 commit comments

Comments
 (0)