From 07797a4d6f967d9ffb9e395789312ce43922ccf0 Mon Sep 17 00:00:00 2001 From: Kirill Liubun Date: Fri, 5 Aug 2016 17:20:46 +0300 Subject: [PATCH] Fixes with maven --- server/node/pom.xml | 2 +- .../admin/services/dao/PropertiesFacade.java | 3 +- server/pom.xml | 1 + .../data-migration-0.9.0-0.10.0/pom.xml | 49 +++--- .../CTLConfigurationMigration.java | 20 +-- .../data_migration/ConfigurationUpgrade.java | 162 +++++++++--------- 6 files changed, 113 insertions(+), 124 deletions(-) diff --git a/server/node/pom.xml b/server/node/pom.xml index 34008d51bc..978553d0ee 100644 --- a/server/node/pom.xml +++ b/server/node/pom.xml @@ -161,7 +161,7 @@ org.kaaproject.kaa.server.common admin-rest-client test - + org.springframework spring-context diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java index a5ca3bf07e..abe44f9b48 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java @@ -118,8 +118,7 @@ private S buildDefaultProperties(Class propert try { Schema schema = (Schema)propertiesClass.getField(SCHEMA).get(null); RawSchema rawSchema = new RawSchema(schema.toString()); - DefaultRecordGenerationAlgorithm algotithm = - new DefaultRecordGenerationAlgorithmImpl<>(rawSchema, new RawDataFactory()); + DefaultRecordGenerationAlgorithm algotithm = new DefaultRecordGenerationAlgorithmImpl<>(rawSchema, new RawDataFactory()); RawData rawData = algotithm.getRootData(); AvroJsonConverter converter = new AvroJsonConverter<>(schema, propertiesClass); result = converter.decodeJson(rawData.getRawData()); diff --git a/server/pom.xml b/server/pom.xml index 9b608e5e7c..7ffd03f45f 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -40,6 +40,7 @@ appenders transports verifiers + upgrade/data-migration-0.9.0-0.10.0 diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/pom.xml b/server/upgrade/data-migration-0.9.0-0.10.0/pom.xml index 49953d0f8c..3f42a3b210 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/pom.xml +++ b/server/upgrade/data-migration-0.9.0-0.10.0/pom.xml @@ -2,46 +2,30 @@ - 4.0.0 + 4.0.0 org.kaaproject data-migration - 1.0-SNAPSHOT - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - + jar - - 9.3-1101-jdbc41 - 1.4.3 - + + org.kaaproject.kaa + 0.10.0-SNAPSHOT + server + org.mariadb.jdbc mariadb-java-client - ${mariadb-driver.version} org.postgresql postgresql - ${pgsql-driver.version} commons-dbcp commons-dbcp - 1.4 org.jdbi @@ -56,20 +40,29 @@ org.apache.avro avro - 1.7.5 org.codehaus.jackson jackson-mapper-asl - 1.9.13 - org.kaaproject.kaa.common - core - 0.10.0-SNAPSHOT + org.kaaproject.kaa.server.common + admin-rest-client + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java index 0ab11f2b26..da63bd97e9 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java @@ -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.*; @@ -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; @@ -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> 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 list = confSchemasToCTL.get(ctl); list.add(schema); diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/ConfigurationUpgrade.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/ConfigurationUpgrade.java index 7db111a608..9c00fc0ee5 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/ConfigurationUpgrade.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/ConfigurationUpgrade.java @@ -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 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 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; +// } +//}