Skip to content

Commit

Permalink
Fixes with maven
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Aug 5, 2016
1 parent cef2b97 commit 07797a4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 124 deletions.
2 changes: 1 addition & 1 deletion server/node/pom.xml
Expand Up @@ -161,7 +161,7 @@
<groupId>org.kaaproject.kaa.server.common</groupId>
<artifactId>admin-rest-client</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
Expand Down
Expand Up @@ -118,8 +118,7 @@ private <S extends SpecificRecordBase> S buildDefaultProperties(Class<S> propert
try {
Schema schema = (Schema)propertiesClass.getField(SCHEMA).get(null);
RawSchema rawSchema = new RawSchema(schema.toString());
DefaultRecordGenerationAlgorithm<RawData> algotithm =
new DefaultRecordGenerationAlgorithmImpl<>(rawSchema, new RawDataFactory());
DefaultRecordGenerationAlgorithm<RawData> algotithm = new DefaultRecordGenerationAlgorithmImpl<>(rawSchema, new RawDataFactory());
RawData rawData = algotithm.getRootData();
AvroJsonConverter<S> converter = new AvroJsonConverter<>(schema, propertiesClass);
result = converter.decodeJson(rawData.getRawData());
Expand Down
1 change: 1 addition & 0 deletions server/pom.xml
Expand Up @@ -40,6 +40,7 @@
<module>appenders</module>
<module>transports</module>
<module>verifiers</module>
<module>upgrade/data-migration-0.9.0-0.10.0</module>
</modules>

<profiles>
Expand Down
49 changes: 21 additions & 28 deletions server/upgrade/data-migration-0.9.0-0.10.0/pom.xml
Expand Up @@ -2,46 +2,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<modelVersion>4.0.0</modelVersion>
<groupId>org.kaaproject</groupId>
<artifactId>data-migration</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<packaging>jar</packaging>

<properties>
<pgsql-driver.version>9.3-1101-jdbc41</pgsql-driver.version>
<mariadb-driver.version>1.4.3</mariadb-driver.version>
</properties>
<parent>
<groupId>org.kaaproject.kaa</groupId>
<version>0.10.0-SNAPSHOT</version>
<artifactId>server</artifactId>
</parent>

<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb-driver.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${pgsql-driver.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
Expand All @@ -56,20 +40,29 @@
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.kaaproject.kaa.common</groupId>
<artifactId>core</artifactId>
<version>0.10.0-SNAPSHOT</version>
<groupId>org.kaaproject.kaa.server.common</groupId>
<artifactId>admin-rest-client</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>



Expand Down
Expand Up @@ -8,6 +8,10 @@
import org.kaaproject.data_migration.model.ConfigurationSchema;
import org.kaaproject.data_migration.model.Ctl;
import org.kaaproject.data_migration.model.CtlMetaInfo;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto;
import org.kaaproject.kaa.server.common.admin.AdminClient;


import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
Expand All @@ -20,6 +24,7 @@ public class CTLConfigurationMigration {

private Connection connection;
private final int NUM_OF_BASE_SCHEMA_FIELDS = 8;
private AdminClient client = new AdminClient("localhost", 8080);

public CTLConfigurationMigration(Connection connection) {
this.connection = connection;
Expand All @@ -38,22 +43,13 @@ public void transform() throws SQLException {
runner.update(connection, "update configuration_schems set id = id + " + shift + " order by id desc");
schemas.forEach(s -> s.setId(s.getId() + shift));
Map<Ctl, List<ConfigurationSchema>> confSchemasToCTL = new HashMap<>();
Long currentCTLMetaId = runner.query(connection, "select max(id) as max_id from ctl_metainfo", rs -> rs.next() ? rs.getLong("max_id") : null);
Long currentCtlId = runner.query(connection, "select max(id) as max_id from ctl", rs -> rs.next() ? rs.getLong("max_id") : null);

// CTL creation
for (ConfigurationSchema schema : schemas) {
currentCTLMetaId++;
currentCtlId++;
Schema schemaBody = new Schema.Parser().parse(schema.getSchems());
String fqn = schemaBody.getFullName();
String defaultRecord = ""; //TODO
Long tenantId = runner.query(connection, "select tenant_id from application where id = " + schema.getAppId(), rs -> rs.next() ? rs.getLong("tenant_id") : null);
runner.insert(connection, "insert into ctl_metainfo values(?, ?, ?, ?)", rs -> null, currentCTLMetaId, fqn, schema.getAppId(), tenantId);
runner.insert(connection, "insert into ctl values(?, ?, ?, ?, ?, ?, ?)", rs -> null, currentCtlId, schema.getSchems(), schema.getCreatedTime(),
schema.getCreatedUsername(), defaultRecord, schema.getVersion(), currentCTLMetaId);

CTLSchemaDto ctlSchemaDto = client.saveCTLSchemaWithAppToken(schema.getSchems(), tenantId.toString(), schema.getAppId().toString());
// aggregate configuration schemas with same fqn
Ctl ctl = new Ctl(currentCtlId, new CtlMetaInfo(fqn, schema.getAppId(), tenantId));
Ctl ctl = new Ctl(Long.parseLong(ctlSchemaDto.getId()), new CtlMetaInfo(ctlSchemaDto.getMetaInfo().getFqn(), schema.getAppId(), tenantId));
if (confSchemasToCTL.containsKey(ctl)) {
List<ConfigurationSchema> list = confSchemasToCTL.get(ctl);
list.add(schema);
Expand Down
@@ -1,81 +1,81 @@
package org.kaaproject.data_migration;



import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import org.kaaproject.data_migration.model.gen.tables.pojos.Configuration;
import org.kaaproject.data_migration.model.gen.tables.records.ConfigurationRecord;
import org.kaaproject.data_migration.utils.DataSources;

import java.util.Base64;
import java.util.List;

import static org.kaaproject.data_migration.model.gen.Tables.CONFIGURATION;



public final class ConfigurationUpgrade {
private static final String UUID_FIELD = "__uuid";
private static final String UUID_VALUE = "org.kaaproject.configuration.uuidT";

private ConfigurationUpgrade() {}

public static void run() throws Exception {
updateUuids();
//todo: transformation into CTL
}

private static void updateUuids() throws Exception {
DSLContext create = DSL.using(DataSources.MARIADB.getDs(), SQLDialect.MARIADB);
List<Configuration> configs = create.select().from(CONFIGURATION).fetchInto(Configuration.class);

for (Configuration config : configs) {
JsonNode json = new ObjectMapper().readTree(config.getConfigurationBody());
JsonNode jsonEncoded = encodeUuids(json);
byte[] encodedConfigurationBody = jsonEncoded.toString().getBytes();
config.setConfigurationBody(encodedConfigurationBody);

ConfigurationRecord record = create.newRecord(CONFIGURATION, config);
create.executeUpdate(record);
}
}

private static JsonNode encodeUuids(JsonNode json) throws Exception {
if (json.has(UUID_FIELD)) {
JsonNode j = json.get(UUID_FIELD);
if (j.has(UUID_VALUE)) {
String value = j.get(UUID_VALUE).asText();
String encodedValue = Base64.getEncoder().encodeToString(value.getBytes("ISO-8859-1"));
((ObjectNode)j).put(UUID_VALUE, encodedValue);
}
}

for (JsonNode node : json) {
if (node.isContainerNode()) encodeUuids(node);
}

return json;
}

private static JsonNode decodeUuids(JsonNode json) throws Exception {
if (json.has(UUID_FIELD)) {
JsonNode j = json.get(UUID_FIELD);
if (j.has(UUID_VALUE)) {
String value = j.get(UUID_VALUE).asText();
String encodedValue = new String (Base64.getDecoder().decode(value.getBytes("ISO-8859-1")), "ISO-8859-1");
((ObjectNode)j).put(UUID_VALUE, encodedValue);
}
}

for (JsonNode node : json) {
if (node.isContainerNode()) decodeUuids(node);
}

return json;
}
}
//package org.kaaproject.data_migration;
//
//
//
//import org.codehaus.jackson.JsonNode;
//import org.codehaus.jackson.map.ObjectMapper;
//import org.codehaus.jackson.node.ObjectNode;
//import org.jooq.DSLContext;
//import org.jooq.SQLDialect;
//import org.jooq.impl.DSL;
//import org.kaaproject.data_migration.model.gen.tables.pojos.Configuration;
//import org.kaaproject.data_migration.model.gen.tables.records.ConfigurationRecord;
//import org.kaaproject.data_migration.utils.DataSources;
//
//import java.util.Base64;
//import java.util.List;
//
//import static org.kaaproject.data_migration.model.gen.Tables.CONFIGURATION;
//
//
//
//public final class ConfigurationUpgrade {
// private static final String UUID_FIELD = "__uuid";
// private static final String UUID_VALUE = "org.kaaproject.configuration.uuidT";
//
// private ConfigurationUpgrade() {}
//
// public static void run() throws Exception {
// updateUuids();
// //todo: transformation into CTL
// }
//
// private static void updateUuids() throws Exception {
// DSLContext create = DSL.using(DataSources.MARIADB.getDs(), SQLDialect.MARIADB);
// List<Configuration> configs = create.select().from(CONFIGURATION).fetchInto(Configuration.class);
//
// for (Configuration config : configs) {
// JsonNode json = new ObjectMapper().readTree(config.getConfigurationBody());
// JsonNode jsonEncoded = encodeUuids(json);
// byte[] encodedConfigurationBody = jsonEncoded.toString().getBytes();
// config.setConfigurationBody(encodedConfigurationBody);
//
// ConfigurationRecord record = create.newRecord(CONFIGURATION, config);
// create.executeUpdate(record);
// }
// }
//
// private static JsonNode encodeUuids(JsonNode json) throws Exception {
// if (json.has(UUID_FIELD)) {
// JsonNode j = json.get(UUID_FIELD);
// if (j.has(UUID_VALUE)) {
// String value = j.get(UUID_VALUE).asText();
// String encodedValue = Base64.getEncoder().encodeToString(value.getBytes("ISO-8859-1"));
// ((ObjectNode)j).put(UUID_VALUE, encodedValue);
// }
// }
//
// for (JsonNode node : json) {
// if (node.isContainerNode()) encodeUuids(node);
// }
//
// return json;
// }
//
// private static JsonNode decodeUuids(JsonNode json) throws Exception {
// if (json.has(UUID_FIELD)) {
// JsonNode j = json.get(UUID_FIELD);
// if (j.has(UUID_VALUE)) {
// String value = j.get(UUID_VALUE).asText();
// String encodedValue = new String (Base64.getDecoder().decode(value.getBytes("ISO-8859-1")), "ISO-8859-1");
// ((ObjectNode)j).put(UUID_VALUE, encodedValue);
// }
// }
//
// for (JsonNode node : json) {
// if (node.isContainerNode()) decodeUuids(node);
// }
//
// return json;
// }
//}

0 comments on commit 07797a4

Please sign in to comment.