Skip to content

Commit 35fd17c

Browse files
committed
Merge branch '4.19'
2 parents afdf4d7 + a53365d commit 35fd17c

File tree

23 files changed

+126
-80
lines changed

23 files changed

+126
-80
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
116116
Pair<List<Backup>, Integer> result = backupManager.listBackups(this);
117117
setupResponseBackupList(result.first(), result.second());
118118
} catch (Exception e) {
119+
logger.debug("Exception while listing backups", e);
119120
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
120121
}
121122
}

api/src/main/java/org/apache/cloudstack/backup/Backup.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public String toString() {
134134
}
135135

136136
long getVmId();
137+
long getBackupOfferingId();
137138
String getExternalId();
138139
String getType();
139140
Date getDate();

engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.cloud.utils.db.SearchCriteria;
3030
import com.cloud.utils.db.Transaction;
3131
import com.cloud.utils.db.TransactionCallback;
32+
import com.cloud.utils.db.TransactionCallbackNoReturn;
3233
import com.cloud.utils.db.TransactionLegacy;
3334
import com.cloud.utils.db.TransactionStatus;
3435
import com.cloud.utils.exception.CloudRuntimeException;
@@ -538,21 +539,25 @@ public void saveUsageRecords(List<UsageVO> usageRecords) {
538539

539540
@Override
540541
public void removeOldUsageRecords(int days) {
541-
String sql = DELETE_ALL_BY_INTERVAL;
542-
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
543-
PreparedStatement pstmt = null;
544-
try {
545-
txn.start();
546-
pstmt = txn.prepareAutoCloseStatement(sql);
547-
pstmt.setLong(1, days);
548-
pstmt.executeUpdate();
549-
txn.commit();
550-
} catch (Exception ex) {
551-
txn.rollback();
552-
logger.error("error removing old cloud_usage records for interval: " + days);
553-
} finally {
554-
txn.close();
555-
}
542+
Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallbackNoReturn() {
543+
@Override
544+
public void doInTransactionWithoutResult(TransactionStatus status) {
545+
TransactionLegacy txn = TransactionLegacy.currentTxn();
546+
PreparedStatement pstmt = null;
547+
try {
548+
txn.start();
549+
pstmt = txn.prepareAutoCloseStatement(DELETE_ALL_BY_INTERVAL);
550+
pstmt.setLong(1, days);
551+
pstmt.executeUpdate();
552+
txn.commit();
553+
} catch (Exception ex) {
554+
txn.rollback();
555+
logger.error("error removing old cloud_usage records for interval: " + days);
556+
} finally {
557+
txn.close();
558+
}
559+
}
560+
});
556561
}
557562

558563
public UsageVO persistUsage(final UsageVO usage) {

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ public List<VMInstanceVO> listNonRemovedVmsByTypeAndNetwork(long networkId, Virt
856856

857857
SearchBuilder<NicVO> nicSearch = nicDao.createSearchBuilder();
858858
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
859+
nicSearch.and("removed", nicSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
859860

860861
NetworkTypeSearch = createSearchBuilder();
861862
NetworkTypeSearch.and("types", NetworkTypeSearch.entity().getType(), SearchCriteria.Op.IN);

engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public void setStatus(Status status) {
158158
this.status = status;
159159
}
160160

161+
@Override
161162
public long getBackupOfferingId() {
162163
return backupOfferingId;
163164
}

engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDaoImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ public BackupResponse newBackupResponse(Backup backup) {
145145
AccountVO account = accountDao.findByIdIncludingRemoved(vm.getAccountId());
146146
DomainVO domain = domainDao.findByIdIncludingRemoved(vm.getDomainId());
147147
DataCenterVO zone = dataCenterDao.findByIdIncludingRemoved(vm.getDataCenterId());
148-
BackupOffering offering = backupOfferingDao.findByIdIncludingRemoved(vm.getBackupOfferingId());
148+
Long offeringId = vm.getBackupOfferingId();
149+
if (offeringId == null) {
150+
offeringId = backup.getBackupOfferingId();
151+
}
152+
BackupOffering offering = backupOfferingDao.findByIdIncludingRemoved(offeringId);
149153

150154
BackupResponse response = new BackupResponse();
151155
response.setId(backup.getUuid());

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapperTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.UUID;
2727

2828
import org.junit.Assert;
29+
import org.junit.Assume;
2930
import org.junit.Test;
3031
import org.junit.runner.RunWith;
3132
import org.mockito.Spy;
@@ -49,8 +50,7 @@ public void testGetInterfaceDetailsValidValid() {
4950
while(interfaces.hasMoreElements()) {
5051
NetworkInterface networkInterface = interfaces.nextElement();
5152
if (networkInterface.getInetAddresses().hasMoreElements() &&
52-
(networkInterface.getName().startsWith("eth") ||
53-
networkInterface.getName().startsWith("wl"))) {
53+
networkInterface.getName().matches("^(eth|wl|en).*")) {
5454
interfaceName = networkInterface.getName();
5555
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
5656
while(addresses.hasMoreElements()) {
@@ -60,9 +60,13 @@ public void testGetInterfaceDetailsValidValid() {
6060
break;
6161
};
6262
}
63+
if (StringUtils.isNotBlank(interfaceName) && StringUtils.isNotBlank(ipAddress)) {
64+
break;
65+
}
6366
}
6467
}
6568
} catch (SocketException ignored) {}
69+
Assume.assumeTrue(StringUtils.isNotBlank(interfaceName));
6670
Ternary<String, String, String> result = null;
6771
try {
6872
result = wrapper.getInterfaceDetails(interfaceName);

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public String authenticate(final String command, final Map<String, Object[]> par
226226
"Received SAML response for a SSO request that we may not have made or has expired, please try logging in again",
227227
params, responseType));
228228
}
229+
samlAuthManager.purgeToken(token);
229230

230231
// Set IdpId for this session
231232
session.setAttribute(SAMLPluginConstants.SAML_IDPID, issuer.getValue());

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManager.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ public interface SAML2AuthManager extends PluggableAPIAuthenticator, PluggableSe
7171
"SAML2 IDP Metadata refresh interval in seconds, minimum value is set to 300", true);
7272

7373
ConfigKey<Boolean> SAMLCheckSignature = new ConfigKey<Boolean>("Advanced", Boolean.class, "saml2.check.signature", "true",
74-
"Whether SAML2 signature must be checked, when enforced and when the SAML response does not have a signature would lead to login exception", true);
74+
"When enabled (default and recommended), SAML2 signature checks are enforced and lack of signature in the SAML SSO response will cause login exception. Disabling this is not advisable but provided for backward compatibility for users who are able to accept the risks.", false);
7575

76-
public SAMLProviderMetadata getSPMetadata();
77-
public SAMLProviderMetadata getIdPMetadata(String entityId);
78-
public Collection<SAMLProviderMetadata> getAllIdPMetadata();
76+
SAMLProviderMetadata getSPMetadata();
77+
SAMLProviderMetadata getIdPMetadata(String entityId);
78+
Collection<SAMLProviderMetadata> getAllIdPMetadata();
7979

80-
public boolean isUserAuthorized(Long userId, String entityId);
81-
public boolean authorizeUser(Long userId, String entityId, boolean enable);
80+
boolean isUserAuthorized(Long userId, String entityId);
81+
boolean authorizeUser(Long userId, String entityId, boolean enable);
8282

83-
public void saveToken(String authnId, String domain, String entity);
84-
public SAMLTokenVO getToken(String authnId);
85-
public void expireTokens();
83+
void saveToken(String authnId, String domain, String entity);
84+
SAMLTokenVO getToken(String authnId);
85+
void purgeToken(SAMLTokenVO token);
86+
void expireTokens();
8687
}

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ public SAMLTokenVO getToken(String authnId) {
485485
return _samlTokenDao.findByUuid(authnId);
486486
}
487487

488+
@Override
489+
public void purgeToken(SAMLTokenVO token) {
490+
if (token != null) {
491+
_samlTokenDao.remove(token.getId());
492+
}
493+
}
494+
488495
@Override
489496
public void expireTokens() {
490497
_samlTokenDao.expireTokens();

0 commit comments

Comments
 (0)