Bug 11522 - New agent manager

add update count into host table in order to make agent status update atomic
This commit is contained in:
frank 2011-10-26 16:14:57 -07:00
parent 30f95e638a
commit 1883afeaa3
3 changed files with 28 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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`),