Skip to content

Commit f6b2a58

Browse files
committed
Merge branch '4.18'
2 parents 54a7a5d + f049f54 commit f6b2a58

15 files changed

Lines changed: 169 additions & 58 deletions

File tree

core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ public Long getRemoteFileSize(String url, String format) {
183183
SSLContext context = getSSLContext();
184184
urlConnection.setSSLSocketFactory(context.getSocketFactory());
185185
urlConnection.connect();
186-
return QCOW2Utils.getVirtualSize(urlConnection.getInputStream());
186+
boolean isCompressed = !url.endsWith("qcow2");
187+
return QCOW2Utils.getVirtualSize(urlObj.openStream(), isCompressed);
187188
} catch (IOException e) {
188189
throw new CloudRuntimeException(String.format("Cannot obtain qcow2 virtual size due to: %s", e.getMessage()), e);
189190
}

engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.sql.Connection;
2020
import java.sql.PreparedStatement;
21+
import java.sql.ResultSet;
2122
import java.sql.SQLException;
2223

2324
import org.apache.log4j.Logger;
@@ -84,6 +85,33 @@ public boolean columnExists(Connection conn, String tableName, String columnName
8485
return columnExists;
8586
}
8687

88+
public String generateIndexName(String tableName, String columnName) {
89+
return String.format("i_%s__%s", tableName, columnName);
90+
}
91+
92+
public boolean indexExists(Connection conn, String tableName, String indexName) {
93+
try (PreparedStatement pstmt = conn.prepareStatement(String.format("SHOW INDEXES FROM %s where Key_name = \"%s\"", tableName, indexName))) {
94+
ResultSet result = pstmt.executeQuery();
95+
if (result.next()) {
96+
return true;
97+
}
98+
} catch (SQLException e) {
99+
s_logger.debug(String.format("Index %s doesn't exist, ignoring exception:", indexName, e.getMessage()));
100+
}
101+
return false;
102+
}
103+
104+
public void createIndex(Connection conn, String tableName, String columnName, String indexName) {
105+
String stmt = String.format("CREATE INDEX %s on %s (%s)", indexName, tableName, columnName);
106+
s_logger.debug("Statement: " + stmt);
107+
try (PreparedStatement pstmt = conn.prepareStatement(stmt)) {
108+
pstmt.execute();
109+
s_logger.debug(String.format("Created index %s", indexName));
110+
} catch (SQLException e) {
111+
s_logger.warn(String.format("Unable to create index %s", indexName), e);
112+
}
113+
}
114+
87115
protected static void closePreparedStatement(PreparedStatement pstmt, String errorMessage) {
88116
try {
89117
if (pstmt != null) {
@@ -93,5 +121,4 @@ protected static void closePreparedStatement(PreparedStatement pstmt, String err
93121
s_logger.warn(errorMessage, e);
94122
}
95123
}
96-
97124
}

engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public class DbUpgradeUtils {
2323

2424
private static DatabaseAccessObject dao = new DatabaseAccessObject();
2525

26+
public static void addIndexIfNeeded(Connection conn, String tableName, String columnName) {
27+
String indexName = dao.generateIndexName(tableName, columnName);
28+
29+
if (!dao.indexExists(conn, tableName, indexName)) {
30+
dao.createIndex(conn, tableName, columnName, indexName);
31+
}
32+
}
33+
2634
public static void addForeignKey(Connection conn, String tableName, String tableColumn, String foreignTableName, String foreignColumnName) {
2735
dao.addForeignKey(conn, tableName, tableColumn, foreignTableName, foreignColumnName);
2836
}

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void performDataMigration(Connection conn) {
6969
copyGuestOsMappingsToVMware80u1();
7070
addForeignKeyToAutoscaleVmprofiles(conn);
7171
mergeDuplicateGuestOSes();
72+
addIndexes(conn);
7273
}
7374

7475
private void mergeDuplicateGuestOSes() {
@@ -242,4 +243,8 @@ private void fixForeignKeyNames(Connection conn) {
242243
private void addForeignKeyToAutoscaleVmprofiles(Connection conn) {
243244
DbUpgradeUtils.addForeignKey(conn, "autoscale_vmprofiles", "user_data_id", "user_data", "id");
244245
}
246+
247+
private void addIndexes(Connection conn) {
248+
DbUpgradeUtils.addIndexIfNeeded(conn, "cluster_details", "name");
249+
}
245250
}

engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.upgrade.dao;
1818

19+
import static org.mockito.Matchers.startsWith;
1920
import static org.mockito.Matchers.any;
2021
import static org.mockito.Matchers.anyString;
2122
import static org.mockito.Matchers.contains;
@@ -27,9 +28,11 @@
2728

2829
import java.sql.Connection;
2930
import java.sql.PreparedStatement;
31+
import java.sql.ResultSet;
3032
import java.sql.SQLException;
3133

3234
import org.apache.log4j.Logger;
35+
import org.junit.Assert;
3336
import org.junit.Before;
3437
import org.junit.Test;
3538
import org.junit.runner.RunWith;
@@ -49,6 +52,9 @@ public class DatabaseAccessObjectTest {
4952
@Mock
5053
private Logger loggerMock;
5154

55+
@Mock
56+
private ResultSet resultSetMock;
57+
5258
private final DatabaseAccessObject dao = new DatabaseAccessObject();
5359

5460
@Before
@@ -83,6 +89,61 @@ public void testDropKeyWhenConnectionIsNull() throws Exception {
8389
dao.dropKey(conn, tableName, key, isForeignKey);
8490
}
8591

92+
@Test
93+
public void generateIndexNameTest() {
94+
String indexName = dao.generateIndexName("mytable","mycolumn");
95+
Assert.assertEquals( "i_mytable__mycolumn", indexName);
96+
}
97+
98+
@Test
99+
public void indexExistsFalseTest() throws Exception {
100+
when(resultSetMock.next()).thenReturn(false);
101+
when(connectionMock.prepareStatement(startsWith("SHOW INDEXES FROM"))).thenReturn(preparedStatementMock);
102+
when(preparedStatementMock.executeQuery()).thenReturn(resultSetMock);
103+
104+
Connection conn = connectionMock;
105+
String tableName = "mytable";
106+
String indexName = "myindex";
107+
108+
Assert.assertFalse(dao.indexExists(conn, tableName, indexName));
109+
verify(connectionMock, times(1)).prepareStatement(anyString());
110+
verify(preparedStatementMock, times(1)).executeQuery();
111+
verify(preparedStatementMock, times(1)).close();
112+
}
113+
114+
@Test
115+
public void indexExistsTrueTest() throws Exception {
116+
when(resultSetMock.next()).thenReturn(true);
117+
when(connectionMock.prepareStatement(startsWith("SHOW INDEXES FROM"))).thenReturn(preparedStatementMock);
118+
when(preparedStatementMock.executeQuery()).thenReturn(resultSetMock);
119+
120+
Connection conn = connectionMock;
121+
String tableName = "mytable";
122+
String indexName = "myindex";
123+
124+
Assert.assertTrue(dao.indexExists(conn, tableName, indexName));
125+
verify(connectionMock, times(1)).prepareStatement(anyString());
126+
verify(preparedStatementMock, times(1)).executeQuery();
127+
verify(preparedStatementMock, times(1)).close();
128+
}
129+
130+
@Test
131+
public void createIndexTest() throws Exception {
132+
when(connectionMock.prepareStatement(startsWith("CREATE INDEX"))).thenReturn(preparedStatementMock);
133+
when(preparedStatementMock.execute()).thenReturn(true);
134+
135+
Connection conn = connectionMock;
136+
String tableName = "mytable";
137+
String columnName = "mycolumn";
138+
String indexName = "myindex";
139+
140+
dao.createIndex(conn, tableName, columnName, indexName);
141+
verify(connectionMock, times(1)).prepareStatement(anyString());
142+
verify(preparedStatementMock, times(1)).execute();
143+
verify(preparedStatementMock, times(1)).close();
144+
verify(loggerMock, times(1)).debug("Created index myindex");
145+
}
146+
86147
@Test
87148
public void testDropKeyWhenTableNameIsNull() throws Exception {
88149
SQLException sqlException = new SQLException();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.apache.log4j.Logger;
2323
import org.libvirt.Connect;
24-
import org.libvirt.Library;
2524
import org.libvirt.LibvirtException;
2625

2726
import com.cloud.hypervisor.Hypervisor;
@@ -45,7 +44,6 @@ static public Connect getConnection(String hypervisorURI) throws LibvirtExceptio
4544
if (conn == null) {
4645
s_logger.info("No existing libvirtd connection found. Opening a new one");
4746
conn = new Connect(hypervisorURI, false);
48-
Library.initEventLoop();
4947
s_logger.debug("Successfully connected to libvirt at: " + hypervisorURI);
5048
s_connections.put(hypervisorURI, conn);
5149
} else {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckUrlCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public CheckUrlAnswer execute(CheckUrlCommand cmd, LibvirtComputingResource serv
4040
boolean checkResult = DirectDownloadHelper.checkUrlExistence(url);
4141
if (checkResult) {
4242
remoteSize = DirectDownloadHelper.getFileSize(url, cmd.getFormat());
43+
if (remoteSize == null || remoteSize < 0) {
44+
s_logger.error(String.format("Couldn't properly retrieve the remote size of the template on " +
45+
"url %s, obtained size = %s", url, remoteSize));
46+
return new CheckUrlAnswer(false, remoteSize);
47+
}
4348
}
4449
return new CheckUrlAnswer(checkResult, remoteSize);
4550
}

plugins/network-elements/vxlan/src/main/java/com/cloud/network/guru/VxlanGuestNetworkGuru.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,16 @@ protected boolean canHandle(NetworkOffering offering, final NetworkType networkT
6969

7070
@Override
7171
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
72-
7372
NetworkVO network = (NetworkVO)super.design(offering, plan, userSpecified, owner);
7473
if (network == null) {
7574
return null;
7675
}
77-
7876
if (offering.getGuestType() == GuestType.L2 && network.getBroadcastUri() != null) {
7977
String vxlan = BroadcastDomainType.getValue(network.getBroadcastUri());
8078
network.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(vxlan));
8179
}
8280
network.setBroadcastDomainType(BroadcastDomainType.Vxlan);
83-
84-
return network;
81+
return updateNetworkDesignForIPv6IfNeeded(network, userSpecified);
8582
}
8683

8784
@Override

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientImpl.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -738,11 +738,20 @@ public boolean deleteVolume(final String volumeId) {
738738
try {
739739
unmapVolumeFromAllSdcs(volumeId);
740740
} catch (Exception ignored) {}
741-
Boolean removeVolumeStatus = post(
742-
"/instances/Volume::" + volumeId + "/action/removeVolume",
743-
"{\"removeMode\":\"ONLY_ME\"}", Boolean.class);
744-
if (removeVolumeStatus != null) {
745-
return removeVolumeStatus;
741+
742+
try {
743+
Boolean removeVolumeStatus = post(
744+
"/instances/Volume::" + volumeId + "/action/removeVolume",
745+
"{\"removeMode\":\"ONLY_ME\"}", Boolean.class);
746+
if (removeVolumeStatus != null) {
747+
return removeVolumeStatus;
748+
}
749+
} catch (Exception ex) {
750+
if (ex instanceof ServerApiException && ex.getMessage().contains("Could not find the volume")) {
751+
LOG.warn(String.format("API says deleting volume %s does not exist, handling gracefully", volumeId));
752+
return true;
753+
}
754+
throw ex;
746755
}
747756
return false;
748757
}

server/src/main/java/com/cloud/network/guru/ExternalGuestNetworkGuru.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.cloud.event.EventVO;
3737
import com.cloud.exception.InsufficientAddressCapacityException;
3838
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
39-
import com.cloud.exception.InvalidParameterValueException;
4039
import com.cloud.network.IpAddressManager;
4140
import com.cloud.network.Network;
4241
import com.cloud.network.Network.GuestType;
@@ -124,22 +123,7 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
124123
/* In order to revert userSpecified network setup */
125124
config.setState(State.Allocated);
126125
}
127-
if (userSpecified == null) {
128-
return config;
129-
}
130-
if ((userSpecified.getIp6Cidr() == null && userSpecified.getIp6Gateway() != null) ||
131-
(userSpecified.getIp6Cidr() != null && userSpecified.getIp6Gateway() == null)) {
132-
throw new InvalidParameterValueException("ip6gateway and ip6cidr must be specified together.");
133-
}
134-
if (userSpecified.getIp6Cidr() != null) {
135-
config.setIp6Cidr(userSpecified.getIp6Cidr());
136-
config.setIp6Gateway(userSpecified.getIp6Gateway());
137-
}
138-
if (userSpecified.getRouterIpv6() != null) {
139-
config.setRouterIpv6(userSpecified.getRouterIpv6());
140-
}
141-
142-
return config;
126+
return updateNetworkDesignForIPv6IfNeeded(config, userSpecified);
143127
}
144128

145129
@Override

0 commit comments

Comments
 (0)