mirror of https://github.com/apache/cloudstack.git
Bug 11522 - New agent manager
add update count into host table in order to make agent status update atomic
This commit is contained in:
parent
30f95e638a
commit
1883afeaa3
|
|
@ -134,6 +134,9 @@ public class HostVO implements Host {
|
|||
|
||||
@Column(name="hypervisor_version")
|
||||
private String hypervisorVersion;
|
||||
|
||||
@Column(name="update_count", updatable = true, nullable=false)
|
||||
protected long updated; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code.
|
||||
|
||||
// This is a delayed load value. If the value is null,
|
||||
// then this field has not been loaded yet.
|
||||
|
|
@ -705,5 +708,14 @@ public class HostVO implements Host {
|
|||
public boolean isInMaintenanceStates() {
|
||||
return (getResourceState() == ResourceState.Maintenance || getResourceState() == ResourceState.ErrorInMaintenance
|
||||
|| getResourceState() == ResourceState.PrepareForMaintenance);
|
||||
}
|
||||
}
|
||||
|
||||
public long getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public long incrUpdated() {
|
||||
updated++;
|
||||
return updated;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -591,6 +591,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
SearchBuilder<HostVO> sb = createSearchBuilder();
|
||||
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
|
||||
sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
|
|
@ -603,11 +604,14 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
|
||||
sc.setParameters("status", oldStatus);
|
||||
sc.setParameters("id", host.getId());
|
||||
sc.setParameters("update", host.getUpdated());
|
||||
long oldUpdateCount = host.getUpdated();
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sc.setParameters("ping", oldPingTime);
|
||||
sc.setParameters("msid", host.getManagementServerId());
|
||||
}
|
||||
|
||||
long newUpdateCount = host.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(host);
|
||||
ub.set(host, _statusAttr, newStatus);
|
||||
if (newStatus.updateManagementServer()) {
|
||||
|
|
@ -636,17 +640,19 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=")
|
||||
.append(oldPingTime).append("]");
|
||||
str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=")
|
||||
.append(vo.getLastPinged()).append("]");
|
||||
.append(vo.getLastPinged()).append(":old update count=").append(oldUpdateCount).append("]");
|
||||
status_logger.debug(str.toString());
|
||||
} else {
|
||||
StringBuilder msg = new StringBuilder("Agent status update: [");
|
||||
msg.append("hostId = " + host.getId());
|
||||
msg.append("; old status = " + oldStatus);
|
||||
msg.append("; event = " + event);
|
||||
msg.append("; new status = " + newStatus);
|
||||
msg.append("; old update count = " + oldUpdateCount);
|
||||
msg.append("; new update count = " + newUpdateCount + "]");
|
||||
status_logger.debug(msg.toString());
|
||||
}
|
||||
|
||||
StringBuilder msg = new StringBuilder("Agent status update: [");
|
||||
msg.append("hostId = " + host.getId());
|
||||
msg.append("; old status = " + oldStatus);
|
||||
msg.append("; event = " + event);
|
||||
msg.append("; new status = " + newStatus + "]");
|
||||
status_logger.debug(msg.toString());
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -698,7 +698,7 @@ CREATE TABLE `cloud`.`host` (
|
|||
`disconnected` datetime COMMENT 'Time this was disconnected',
|
||||
`created` datetime COMMENT 'date the host first signed on',
|
||||
`removed` datetime COMMENT 'date removed if not null',
|
||||
`allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled' COMMENT 'Is this host enabled for allocation for new resources',
|
||||
`update_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'atomic increase count making status update operation atomical',
|
||||
`resource_state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'Is this host enabled for allocation for new resources',
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `i_host__removed`(`removed`),
|
||||
|
|
|
|||
Loading…
Reference in New Issue