Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,31 @@ public long download(boolean resume, DownloadCompleteCallback callback) {
try {
fic.close();
} catch (IOException e) {
s_logger.info("[ignore] error while closing file input channel.");
}
}

if (foc != null) {
try {
foc.close();
} catch (IOException e) {
s_logger.info("[ignore] error while closing file output channel.");
}
}

if (fis != null) {
try {
fis.close();
} catch (IOException e) {
s_logger.info("[ignore] error while closing file input stream.");
}
}

if (fos != null) {
try {
fos.close();
} catch (IOException e) {
s_logger.info("[ignore] error while closing file output stream.");
}
}

Expand Down
24 changes: 4 additions & 20 deletions core/src/com/cloud/storage/template/TemplateLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,10 @@ public boolean purge() {
}

public boolean load() throws IOException {
FileInputStream strm = null;
try {
strm = new FileInputStream(_file);
try (FileInputStream strm = new FileInputStream(_file);) {
_props.load(strm);
} finally {
if (strm != null) {
try {
strm.close();
} catch (IOException e) {
}
}
} catch (IOException e) {
s_logger.warn("Unable to load the template properties", e);
}

for (ImageFormat format : ImageFormat.values()) {
Expand Down Expand Up @@ -142,20 +135,11 @@ public boolean save() {
_props.setProperty(info.format.getFileExtension() + ".size", Long.toString(info.size));
_props.setProperty(info.format.getFileExtension() + ".virtualsize", Long.toString(info.virtualSize));
}
FileOutputStream strm = null;
try {
strm = new FileOutputStream(_file);
try (FileOutputStream strm = new FileOutputStream(_file);) {
_props.store(strm, "");
} catch (IOException e) {
s_logger.warn("Unable to save the template properties ", e);
return false;
} finally {
if (strm != null) {
try {
strm.close();
} catch (IOException e) {
}
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ public boolean stop() {
s_logger.info("Closing: " + ch.toString());
ch.close();
} catch (IOException e) {
s_logger.info("[ignored] error on closing channel: " +ch.toString(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
// under the License.
package com.cloud.certificate.dao;

import java.io.BufferedInputStream;
import java.io.IOException;

import javax.ejb.Local;

import org.apache.log4j.Logger;
Expand All @@ -41,7 +38,6 @@ public CertificateDaoImpl() {

@Override
public Long persistCustomCertToDb(String certStr, CertificateVO cert, Long managementServerId) {
BufferedInputStream f = null;
try {
cert.setCertificate(certStr);
cert.setUpdated("Y");
Expand All @@ -50,12 +46,6 @@ public Long persistCustomCertToDb(String certStr, CertificateVO cert, Long manag
} catch (Exception e) {
s_logger.warn("Unable to read the certificate: " + e);
return new Long(0);
} finally {
if (f != null)
try {
f.close();
} catch (IOException ignored) {
}
}
}
}
42 changes: 42 additions & 0 deletions engine/schema/src/com/cloud/upgrade/dao/LegacyDbUpgrade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 com.cloud.upgrade.dao;

import org.apache.log4j.Logger;

public abstract class LegacyDbUpgrade implements DbUpgrade{

final static Logger s_logger = Logger.getLogger(LegacyDbUpgrade.class);

public LegacyDbUpgrade() {
super();
}

/**
* @param closable
*/
protected void closeAutoCloseable(AutoCloseable closable) {
if (closable != null) {
try {
closable.close();
} catch (Exception e) {
s_logger.info("[ignored]",e);
}
}
}

}
11 changes: 7 additions & 4 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade2214to30.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ private void encryptConfigValues(Connection conn) {
pstmt.close();
}
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
s_logger.debug("Done encrypting Config values");
Expand Down Expand Up @@ -861,6 +862,7 @@ protected void updateReduntantRouters(Connection conn) {
pstmt.executeUpdate();
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
TransactionLegacy.closePstmts(pstmt2Close);
}
Expand Down Expand Up @@ -1000,6 +1002,7 @@ protected void switchAccountSpecificNetworksToIsolated(Connection conn) {
pstmt.executeUpdate();
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
TransactionLegacy.closePstmts(pstmt2Close);
}
Expand Down Expand Up @@ -1053,6 +1056,7 @@ private void migrateUserConcentratedPlannerChoice(Connection conn) {
pstmt.close();
}
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
}
Expand Down Expand Up @@ -1151,11 +1155,10 @@ protected String fixNetworksWithExternalDevices(Connection conn) {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to switch networks to the new network offering", e);
} finally {
try {
pstmt = conn.prepareStatement("DROP TABLE `cloud`.`network_offerings2`");
pstmt.executeUpdate();
pstmt.close();
try (PreparedStatement dropStatement = conn.prepareStatement("DROP TABLE `cloud`.`network_offerings2`");){
dropStatement.executeUpdate();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
TransactionLegacy.closePstmts(pstmt2Close);
}
Expand Down
6 changes: 6 additions & 0 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade222to224.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,21 @@ private void updateClusterIdInOpHostCapacity(Connection conn) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}

Expand Down Expand Up @@ -406,18 +409,21 @@ private void updateTotalCPUInOpHostCapacity(Connection conn) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}

Expand Down
41 changes: 15 additions & 26 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade229to2210.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,29 @@ public File[] getCleanupScripts() {
}

private void updateSnapshots(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
long currentSnapshotId = 0;
try {
pstmt =
conn.prepareStatement("select id, prev_snap_id from snapshots where sechost_id is NULL and prev_snap_id is not NULL and status=\"BackedUp\" and removed is NULL order by id");
rs = pstmt.executeQuery();
try (
PreparedStatement pstmt = conn.prepareStatement("select id, prev_snap_id from snapshots where sechost_id is NULL and prev_snap_id is not NULL and status=\"BackedUp\" and removed is NULL order by id");
ResultSet rs = pstmt.executeQuery();
PreparedStatement pstmt2 = conn.prepareStatement("select sechost_id from snapshots where id=? and sechost_id is not NULL");
PreparedStatement updateSnapshotStatement = conn.prepareStatement("update snapshots set sechost_id=? where id=?");
){
while (rs.next()) {
long id = rs.getLong(1);
long preSnapId = rs.getLong(2);
currentSnapshotId = id;
pstmt = conn.prepareStatement("select sechost_id from snapshots where id=? and sechost_id is not NULL");
pstmt.setLong(1, preSnapId);
ResultSet sechost = pstmt.executeQuery();
if (sechost.next()) {
long secHostId = sechost.getLong(1);
pstmt = conn.prepareStatement("update snapshots set sechost_id=? where id=?");
pstmt.setLong(1, secHostId);
pstmt.setLong(2, id);
pstmt.executeUpdate();
pstmt2.setLong(1, preSnapId);
try (ResultSet sechost = pstmt2.executeQuery();) {
if (sechost.next()) {
long secHostId = sechost.getLong(1);
updateSnapshotStatement.setLong(1, secHostId);
updateSnapshotStatement.setLong(2, id);
updateSnapshotStatement.executeUpdate();
}
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to update snapshots id=" + currentSnapshotId, e);
} finally {
try {
if (rs != null) {
rs.close();
}

if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}

Expand Down Expand Up @@ -192,6 +180,7 @@ private void updateFirewallRules(Connection conn) {
pstmt.close();
}
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
}
Expand Down
Loading