aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/main
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-07-20 01:29:49 +0300
committerMichael Lando <ml636r@att.com>2017-07-20 01:30:06 +0300
commit3c3c833897dbfc0e85feaf36086a505f990ecb76 (patch)
tree8c308fbe7298aa65066ba0fc8a71e51d20d8e0de /asdctool/src/main
parent30db4407bab8cfea48e278d29e55b11c6c0a528c (diff)
[SDC] 1710 rebase + pom modifications
Change-Id: I1f9c0a5201576c7a6b124f6a786db12c1a8cd7c0 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'asdctool/src/main')
-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
6 files changed, 105 insertions, 2 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;