private static final Log log = LogFactory.getLog(Alpha1.class);
public void migrate() throws Exception {
// changes to the data model for the statics.
TenantManager tenantManager = Util.getRealmService().getTenantManager();
SystemMeteringAgent meteringAgent = Util.getSystemMeteringAgent();
//get super tenant governance registry
UserRegistry superTenantGovernanceRegistry = Util.getSuperTenantGovernanceSystemRegistry();
if (!superTenantGovernanceRegistry.resourceExists(OLD_BANDWIDTH_USE_STORE_PATH)) {
return;
}
Tenant[] tenants = tenantManager.getAllTenants();
// uses only the current year month 2010-july
String yearMonth = CommonUtil.getCurrentMonthString();
for (Tenant tenant : tenants) {
int tenantId = tenant.getId();
long incomingBw = getOldIncomingRegistryBandwidth(yearMonth, tenantId);
long outgoingBw = getOldOutgoingRegistryBandwidth(yearMonth, tenantId);
if (incomingBw != 0) {
meteringAgent.persistUsage(tenantId, yearMonth,
UsageConstants.REGISTRY_INCOMING_BW, incomingBw + "");
}
if (outgoingBw != 0) {
meteringAgent.persistUsage(tenantId, yearMonth,
UsageConstants.REGISTRY_OUTGOING_BW, outgoingBw + "");
}
log.info("Migrating registry bandwidth data to the new data model. tenant id: " +
tenantId + ".");
}