Skip to content
Open
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
28 changes: 12 additions & 16 deletions engine/schema/src/main/java/com/cloud/alert/dao/AlertDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;


import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import com.cloud.alert.AlertVO;
Expand All @@ -28,7 +29,7 @@
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.UpdateBuilder;

@Component
public class AlertDaoImpl extends GenericDaoBase<AlertVO, Long> implements AlertDao {
Expand Down Expand Up @@ -107,25 +108,20 @@ public boolean archiveAlert(List<Long> ids, String type, Date startDate, Date en
}
sc.setParameters("archived", false);

boolean result = true;
;
List<AlertVO> alerts = listBy(sc);
if (ids != null && alerts.size() < ids.size()) {
result = false;
return result;
return false;
}
if (alerts != null && !alerts.isEmpty()) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
for (AlertVO alert : alerts) {
alert = lockRow(alert.getId(), true);
alert.setArchived(true);
update(alert.getId(), alert);
txn.commit();
}
txn.close();

if (CollectionUtils.isEmpty(alerts)) {
return true;
}
return result;

AlertVO alertForUpdate = createForUpdate();
alertForUpdate.setArchived(true);
UpdateBuilder ub = getUpdateBuilder(alertForUpdate);
update(ub, sc, null);
return true;
}

@Override
Expand Down
29 changes: 18 additions & 11 deletions engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import com.cloud.event.Event.State;
Expand All @@ -29,12 +31,13 @@
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.UpdateBuilder;

@Component
public class EventDaoImpl extends GenericDaoBase<EventVO, Long> implements EventDao {
protected final SearchBuilder<EventVO> CompletedEventSearch;
protected final SearchBuilder<EventVO> ToArchiveOrDeleteEventSearch;
protected final SearchBuilder<EventVO> ArchiveByIdsSearch;

public EventDaoImpl() {
CompletedEventSearch = createSearchBuilder();
Expand All @@ -51,6 +54,10 @@ public EventDaoImpl() {
ToArchiveOrDeleteEventSearch.and("createdDateL", ToArchiveOrDeleteEventSearch.entity().getCreateDate(), Op.LTEQ);
ToArchiveOrDeleteEventSearch.and("archived", ToArchiveOrDeleteEventSearch.entity().getArchived(), Op.EQ);
ToArchiveOrDeleteEventSearch.done();

ArchiveByIdsSearch = createSearchBuilder();
ArchiveByIdsSearch.and("id", ArchiveByIdsSearch.entity().getId(), Op.IN);
ArchiveByIdsSearch.done();
}

@Override
Expand Down Expand Up @@ -100,16 +107,16 @@ public List<EventVO> listToArchiveOrDeleteEvents(List<Long> ids, String type, Da

@Override
public void archiveEvents(List<EventVO> events) {
if (events != null && !events.isEmpty()) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
for (EventVO event : events) {
event = lockRow(event.getId(), true);
event.setArchived(true);
update(event.getId(), event);
txn.commit();
}
txn.close();
if (CollectionUtils.isEmpty(events)) {
return;
}

List<Long> ids = events.stream().map(EventVO::getId).collect(Collectors.toList());
SearchCriteria<EventVO> sc = ArchiveByIdsSearch.create();
sc.setParameters("id", ids.toArray(new Object[ids.size()]));
EventVO eventForUpdate = createForUpdate();
eventForUpdate.setArchived(true);
UpdateBuilder ub = getUpdateBuilder(eventForUpdate);
update(ub, sc, null);
}
}
22 changes: 14 additions & 8 deletions engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,22 @@ private void resetHosts(long managementServerId, long lastPingSecondsAfter) {
sc.setParameters("lastPinged", lastPingSecondsAfter);
sc.setParameters("status", Status.Disconnected, Status.Down, Status.Alert);

StringBuilder sb = new StringBuilder();
List<HostVO> hosts = lockRows(sc, null, true); // exclusive lock
for (HostVO host : hosts) {
host.setManagementServerId(null);
update(host.getId(), host);
sb.append(host.getId());
sb.append(" ");
// SELECT before bulk UPDATE to preserve per-host-ID trace logging — the bulk UPDATE
// cannot return which rows it matched since the WHERE column is being set to NULL
if (logger.isTraceEnabled()) {
List<HostVO> hosts = listBy(sc);
StringBuilder sb = new StringBuilder();
for (HostVO host : hosts) {
sb.append(host.getId());
sb.append(" ");
}
logger.trace("Following hosts will be reset: {}", sb);
}

logger.trace("Following hosts got reset: {}", sb);
HostVO host = createForUpdate();
host.setManagementServerId(null);
UpdateBuilder ub = getUpdateBuilder(host);
update(ub, sc, null);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public SecurityGroupWorkVO take(long serverId) {
//ensure that there is no job in Processing state for the same VM
processing = true;
if (logger.isTraceEnabled()) {
logger.trace("Security Group work take: found a job in Scheduled and Processing vmid=" + work.getInstanceId());
logger.trace("Security Group work take: found a job in Scheduled and Processing vmid={}", work.getInstanceId());
}
}
work.setServerId(serverId);
Expand All @@ -141,7 +141,6 @@ public SecurityGroupWorkVO take(long serverId) {
}

@Override
@DB
public void updateStep(Long vmId, Long logSequenceNumber, Step step) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
Expand Down Expand Up @@ -172,21 +171,10 @@ public SecurityGroupWorkVO findByVmIdStep(long vmId, Step step) {
}

@Override
@DB
public void updateStep(Long workId, Step step) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();

SecurityGroupWorkVO work = lockRow(workId, true);
if (work == null) {
txn.commit();
return;
}
work.setStep(step);
update(work.getId(), work);

txn.commit();

SecurityGroupWorkVO workForUpdate = createForUpdate();
workForUpdate.setStep(step);
update(workId, workForUpdate);
}

@Override
Expand Down
Loading