Browse Source
* Added upgrade * Added upgrade call for attributes from ThingsboardInstallService * refactored cassandra upgrade servicespull/2444/head
committed by
GitHub
7 changed files with 140 additions and 28 deletions
@ -0,0 +1,48 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2020 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.thingsboard.server.dao.cassandra.CassandraCluster; |
||||
|
import org.thingsboard.server.dao.cassandra.CassandraInstallCluster; |
||||
|
import org.thingsboard.server.service.install.cql.CQLStatementsParser; |
||||
|
|
||||
|
import java.nio.file.Path; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Slf4j |
||||
|
public abstract class AbstractCassandraDatabaseUpgradeService { |
||||
|
@Autowired |
||||
|
protected CassandraCluster cluster; |
||||
|
|
||||
|
@Autowired |
||||
|
@Qualifier("CassandraInstallCluster") |
||||
|
private CassandraInstallCluster installCluster; |
||||
|
|
||||
|
protected void loadCql(Path cql) throws Exception { |
||||
|
List<String> statements = new CQLStatementsParser(cql).getStatements(); |
||||
|
statements.forEach(statement -> { |
||||
|
installCluster.getSession().execute(statement); |
||||
|
try { |
||||
|
Thread.sleep(2500); |
||||
|
} catch (InterruptedException e) { |
||||
|
} |
||||
|
}); |
||||
|
Thread.sleep(5000); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2020 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
import com.datastax.driver.core.exceptions.InvalidQueryException; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.context.annotation.Profile; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.dao.util.NoSqlTsDao; |
||||
|
|
||||
|
@Service |
||||
|
@NoSqlTsDao |
||||
|
@Profile("install") |
||||
|
@Slf4j |
||||
|
public class CassandraTsDatabaseUpgradeService extends AbstractCassandraDatabaseUpgradeService implements DatabaseTsUpgradeService { |
||||
|
|
||||
|
@Override |
||||
|
public void upgradeDatabase(String fromVersion) throws Exception { |
||||
|
switch (fromVersion) { |
||||
|
case "2.4.3": |
||||
|
log.info("Updating schema ..."); |
||||
|
String updateTsKvTableStmt = "alter table ts_kv_cf add json_v text"; |
||||
|
String updateTsKvLatestTableStmt = "alter table ts_kv_latest_cf add json_v text"; |
||||
|
|
||||
|
try { |
||||
|
log.info("Updating ts ..."); |
||||
|
cluster.getSession().execute(updateTsKvTableStmt); |
||||
|
Thread.sleep(2500); |
||||
|
log.info("Ts updated."); |
||||
|
log.info("Updating ts latest ..."); |
||||
|
cluster.getSession().execute(updateTsKvLatestTableStmt); |
||||
|
Thread.sleep(2500); |
||||
|
log.info("Ts latest updated."); |
||||
|
} catch (InvalidQueryException e) { |
||||
|
} |
||||
|
log.info("Schema updated."); |
||||
|
break; |
||||
|
default: |
||||
|
throw new RuntimeException("Unable to upgrade Cassandra database, unsupported fromVersion: " + fromVersion); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue