summaryrefslogtreecommitdiffstats
path: root/asdctool/src
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool/src')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java4
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java9
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java1
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksAccessor.java17
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java74
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java2
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java33
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java2
8 files changed, 114 insertions, 28 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java
index 0457c2136d..4d52347788 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java
@@ -6,7 +6,7 @@ import org.openecomp.sdc.asdctool.migration.resolver.MigrationResolver;
import org.openecomp.sdc.asdctool.migration.resolver.SpringBeansMigrationResolver;
import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
import org.openecomp.sdc.be.dao.cassandra.CassandraClient;
-import org.openecomp.sdc.be.dao.cassandra.MigrationTasksDao;
+import org.openecomp.sdc.asdctool.migration.dao.MigrationTasksDao;
import org.openecomp.sdc.be.dao.config.DAOSpringConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -56,4 +56,6 @@ public class MigrationSpringConfig {
return new CassandraClient();
}
+
+
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java
index 4ebec6e440..accd9eca53 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java
@@ -13,6 +13,7 @@ public class MigrationExecutionResult {
private double executionTime;
private DBVersion version;
private String taskName;
+ private String description;
public MigrationTaskEntry toMigrationTaskEntry() {
MigrationTaskEntry migrationTaskEntry = new MigrationTaskEntry();
@@ -23,6 +24,7 @@ public class MigrationExecutionResult {
migrationTaskEntry.setTaskStatus(this.getMigrationStatus().name());
migrationTaskEntry.setMessage(this.getMsg());
migrationTaskEntry.setExecutionTime(this.getExecutionTime());
+ migrationTaskEntry.setDescription(this.getDescription());
return migrationTaskEntry;
}
@@ -67,4 +69,11 @@ public class MigrationExecutionResult {
this.taskName = taskName;
}
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java
index 2e4d3ba8b0..39219aee23 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java
@@ -41,6 +41,7 @@ public class MigrationExecutorImpl implements MigrationExecutor {
migrationExecutionResult.setMsg(migrationResult.getMsg());
migrationExecutionResult.setTaskName(migration.getClass().getName());
migrationExecutionResult.setVersion(migration.getVersion());
+ migrationExecutionResult.setDescription(migration.description());
return migrationExecutionResult;
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksAccessor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksAccessor.java
new file mode 100644
index 0000000000..1e336e45d1
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksAccessor.java
@@ -0,0 +1,17 @@
+package org.openecomp.sdc.asdctool.migration.dao;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Param;
+import com.datastax.driver.mapping.annotations.Query;
+
+@Accessor
+public interface MigrationTasksAccessor {
+
+ @Query("SELECT minor_version FROM sdcrepository.migrationTasks WHERE major_version = :majorVersion order by minor_version desc limit 1")
+ ResultSet getLatestMinorVersion(@Param("majorVersion") Long majorVersion);
+
+ @Query("DELETE FROM sdcrepository.migrationTasks WHERE major_version = :majorVersion")
+ void deleteTasksForMajorVersion(@Param("majorVersion") Long majorVersion);
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java
new file mode 100644
index 0000000000..03fd8d1e7d
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java
@@ -0,0 +1,74 @@
+package org.openecomp.sdc.asdctool.migration.dao;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.Mapper;
+import com.datastax.driver.mapping.MappingManager;
+import fj.data.Either;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.dao.cassandra.CassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.math.BigInteger;
+
+public class MigrationTasksDao extends CassandraDao {
+
+ private static Logger logger = LoggerFactory.getLogger(MigrationTasksDao.class.getName());
+ private MigrationTasksAccessor migrationTasksAccessor;
+ private Mapper<MigrationTaskEntry> migrationTaskMapper;
+
+ @PostConstruct
+ public void init() {
+ String keyspace = AuditingTypesConstants.REPO_KEYSPACE;
+ if (client.isConnected()) {
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> result = client.connect(keyspace);
+ if (result.isLeft()) {
+ session = result.left().value().left;
+ manager = result.left().value().right;
+ migrationTasksAccessor = manager.createAccessor(MigrationTasksAccessor.class);
+ migrationTaskMapper = manager.mapper(MigrationTaskEntry.class);
+ logger.info("** migrationTasksAccessor created");
+ } else {
+ logger.info("** migrationTasksAccessor failed");
+ throw new RuntimeException("Artifact keyspace [" + keyspace + "] failed to connect with error : "
+ + result.right().value());
+ }
+ } else {
+ logger.info("** Cassandra client isn't connected");
+ logger.info("** migrationTasksAccessor created, but not connected");
+ }
+ }
+
+ public BigInteger getLatestMinorVersion(BigInteger majorVersion) {
+ try {
+ ResultSet latestMinorVersion = migrationTasksAccessor.getLatestMinorVersion(majorVersion.longValue());
+ Row minorVersionRow = latestMinorVersion.one();
+ return minorVersionRow == null ? BigInteger.valueOf(Long.MIN_VALUE) : BigInteger.valueOf(minorVersionRow.getLong(0));
+ } catch (RuntimeException e) {
+ logger.error("failed to get latest minor version for major version {}", majorVersion, e);
+ throw e;
+ }
+ }
+
+ public void deleteAllTasksForVersion(BigInteger majorVersion) {
+ try {
+ migrationTasksAccessor.deleteTasksForMajorVersion(majorVersion.longValue());
+ } catch (RuntimeException e) {
+ logger.error("failed to delete tasks for major version {}", majorVersion, e);
+ throw e;
+ }
+ }
+
+ public void createMigrationTask(MigrationTaskEntry migrationTask) {
+ migrationTaskMapper.save(migrationTask);
+ }
+
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java
index 2888ecb474..20451f2c63 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java
@@ -1,7 +1,7 @@
package org.openecomp.sdc.asdctool.migration.service;
import org.openecomp.sdc.asdctool.migration.core.DBVersion;
-import org.openecomp.sdc.be.dao.cassandra.MigrationTasksDao;
+import org.openecomp.sdc.asdctool.migration.dao.MigrationTasksDao;
import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
import java.math.BigInteger;
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java
index 763d6c83d2..7d8cc5aa78 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java
@@ -1,5 +1,6 @@
package org.openecomp.sdc.asdctool.migration.core.execution;
+import org.openecomp.sdc.asdctool.migration.DummyMigrationFactory;
import org.openecomp.sdc.asdctool.migration.core.DBVersion;
import org.openecomp.sdc.asdctool.migration.core.task.Migration;
import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
@@ -12,36 +13,18 @@ public class MigrationExecutorImplTest {
@Test
public void testExecuteMigration() throws Exception {
- MigrationExecutionResult execute = new MigrationExecutorImpl().execute(new DummyMigration());
-
+ MigrationExecutionResult execute = new MigrationExecutorImpl().execute(DummyMigrationFactory.SUCCESSFUL_MIGRATION);
+ assertMigrationTaskEntryByMigrationExecutionResult(execute, DummyMigrationFactory.SUCCESSFUL_MIGRATION);
}
- private void assertMigrationTaskEntryByMigrationExecutionResult(MigrationExecutionResult executionResult, Migration migration, MigrationResult result) {
- assertEquals(executionResult.getMsg(), result.getMsg());
- assertEquals(executionResult.getMigrationStatus().name(), result.getMigrationStatus());
+ private void assertMigrationTaskEntryByMigrationExecutionResult(MigrationExecutionResult executionResult, Migration migration) {
+ MigrationResult migrationResult = migration.migrate();
+ assertEquals(executionResult.getMsg(), migrationResult.getMsg());
+ assertEquals(executionResult.getMigrationStatus(), migrationResult.getMigrationStatus());
assertEquals(executionResult.getTaskName(), migration.getClass().getName());
assertEquals(executionResult.getVersion(), migration.getVersion());
+ assertEquals(executionResult.getDescription(), migration.description());
assertNotNull(executionResult.getExecutionTime());
}
- private class DummyMigration implements Migration {
-
- @Override
- public String description() {
- return null;
- }
-
- @Override
- public DBVersion getVersion() {
- return DBVersion.fromString("1710.22");
- }
-
- @Override
- public MigrationResult migrate() {
- MigrationResult migrationResult = new MigrationResult();
- migrationResult.setMigrationStatus(MigrationResult.MigrationStatus.COMPLETED);
- migrationResult.setMsg("myMsg");
- return migrationResult;
- }
- }
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java
index f8e9abe2c9..705f8d13e6 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java
@@ -5,7 +5,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.internal.verification.Times;
import org.openecomp.sdc.asdctool.migration.core.DBVersion;
-import org.openecomp.sdc.be.dao.cassandra.MigrationTasksDao;
+import org.openecomp.sdc.asdctool.migration.dao.MigrationTasksDao;
import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;