Skip to content

Commit 0f84c9b

Browse files
committed
schema: Add upgrade path 4.3.0 to 4.3.1 picked from 51f145b
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 6c501db commit 0f84c9b

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.upgrade.dao;
19+
20+
import com.cloud.network.Networks.BroadcastDomainType;
21+
import com.cloud.utils.exception.CloudRuntimeException;
22+
import org.apache.log4j.Logger;
23+
24+
import java.io.File;
25+
import java.sql.Connection;
26+
import java.sql.PreparedStatement;
27+
import java.sql.ResultSet;
28+
import java.sql.SQLException;
29+
30+
31+
public class Upgrade430to431 implements DbUpgrade {
32+
final static Logger s_logger = Logger.getLogger(Upgrade430to431.class);
33+
34+
@Override
35+
public String[] getUpgradableVersionRange() {
36+
return new String[] {"4.3.0", "4.3.1"};
37+
}
38+
39+
@Override
40+
public String getUpgradedVersion() {
41+
return "4.3.1";
42+
}
43+
44+
@Override
45+
public boolean supportsRollingUpgrade() {
46+
return false;
47+
}
48+
49+
@Override
50+
public File[] getPrepareScripts() {
51+
return null;
52+
}
53+
54+
@Override
55+
public void performDataMigration(Connection conn) {
56+
updateVlanUris(conn);
57+
}
58+
59+
private void updateVlanUris(Connection conn) {
60+
s_logger.debug("updating vlan URIs");
61+
Exception thrown = null;
62+
PreparedStatement selectstatement = null;
63+
ResultSet results = null;
64+
try{
65+
selectstatement = conn.prepareStatement("SELECT id, vlan_id FROM `cloud`.`vlan` where vlan_id not like '%:%'");
66+
results = selectstatement.executeQuery();
67+
68+
while (results.next()) {
69+
long id = results.getLong(1);
70+
String vlan = results.getString(2);
71+
if (vlan == null || "".equals(vlan)) {
72+
continue;
73+
}
74+
String vlanUri = BroadcastDomainType.Vlan.toUri(vlan).toString();
75+
PreparedStatement updatestatement = conn.prepareStatement("update `cloud`.`vlan` set vlan_id=? where id=?");
76+
try {
77+
updatestatement.setString(1, vlanUri);
78+
updatestatement.setLong(2, id);
79+
updatestatement.executeUpdate();
80+
} catch (SQLException e) {
81+
thrown = new CloudRuntimeException("Unable to update vlan URI " + vlanUri + " for vlan record " + id, e);
82+
} finally {
83+
try {
84+
updatestatement.close();
85+
} catch (Exception e) {
86+
if(thrown == null) {
87+
thrown = new CloudRuntimeException("Unable to close update statement vlan URI " + vlanUri + " for vlan record " + id, e);
88+
} //else don't obfuscate the original exception
89+
}
90+
}
91+
}
92+
} catch (SQLException e) {
93+
if(thrown == null) {
94+
thrown = new CloudRuntimeException("Unable to update vlan URIs ", e);
95+
} //else don't obfuscate the original exception
96+
}
97+
finally
98+
{
99+
try {
100+
if(results != null)
101+
results.close();
102+
} catch (SQLException e) {
103+
if(thrown == null) {
104+
thrown = new CloudRuntimeException("Unable to update vlan URIs ", e);
105+
} //else don't obfuscate the original exception
106+
}
107+
try {
108+
if (selectstatement != null)
109+
selectstatement.close();
110+
} catch (SQLException e) {
111+
if(thrown == null) {
112+
thrown = new CloudRuntimeException("Unable to update vlan URIs ", e);
113+
} //else don't obfuscate the original exception
114+
}
115+
}
116+
s_logger.debug("Done updateing vlan URIs");
117+
}
118+
119+
@Override
120+
public File[] getCleanupScripts() {
121+
return null;
122+
}
123+
124+
}

0 commit comments

Comments
 (0)