fix local seconeary storage related issues(sync/download templates, etc) for mycloud

This commit is contained in:
Edison Su 2011-05-21 12:04:54 -04:00
parent 5ad41e09ae
commit 2f8235dbd2
8 changed files with 29 additions and 6 deletions

View File

@ -29,6 +29,7 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckHealthAnswer;
import com.cloud.agent.api.CheckHealthCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.ComputeChecksumCommand;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.PingStorageCommand;
import com.cloud.agent.api.ReadyAnswer;
@ -97,11 +98,18 @@ public class LocalSecondaryStorageResource extends ServerResourceBase implements
return new ReadyAnswer((ReadyCommand)cmd);
} else if (cmd instanceof ListTemplateCommand){
return execute((ListTemplateCommand)cmd);
} else if (cmd instanceof ComputeChecksumCommand){
return execute((ComputeChecksumCommand)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
}
private Answer execute(ComputeChecksumCommand cmd) {
return new Answer(cmd, false, null);
}
private Answer execute(ListTemplateCommand cmd) {
String root = getRootDir();
Map<String, TemplateInfo> templateInfos = _dlMgr.gatherTemplateInfo(root);

View File

@ -173,4 +173,6 @@ public interface HostDao extends GenericDao<HostVO, Long> {
List<HostVO> listLocalSecondaryStorageHosts();
List<HostVO> listLocalSecondaryStorageHosts(long dataCenterId);
List<HostVO> listAllSecondaryStorageHosts(long dataCenterId);
}

View File

@ -317,6 +317,14 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return search(sc, null);
}
@Override
public List<HostVO> listAllSecondaryStorageHosts(long dataCenterId) {
SearchCriteria<HostVO> sc = createSearchCriteria();
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dataCenterId);
sc.addAnd("type", SearchCriteria.Op.IN, new Object[]{Host.Type.LocalSecondaryStorage, Host.Type.SecondaryStorage});
return search(sc, null);
}
@Override
public List<HostVO> findDirectlyConnectedHosts() {

View File

@ -1307,7 +1307,7 @@ public class ManagementServerImpl implements ManagementServer {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
}
if (type != null) {
sc.addAnd("type", SearchCriteria.Op.EQ, type);
sc.addAnd("type", SearchCriteria.Op.LIKE, "%" + type + "%");
}
if (state != null) {
sc.addAnd("status", SearchCriteria.Op.EQ, state);

View File

@ -152,6 +152,7 @@ public class StatsCollector {
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.Storage.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.ConsoleProxy.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.SecondaryStorage.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.LocalSecondaryStorage.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.TrafficMonitor.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.SecondaryStorageVM.toString());
ConcurrentHashMap<Long, HostStats> hostStats = new ConcurrentHashMap<Long, HostStats>();

View File

@ -959,7 +959,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
public HostVO getSecondaryStorageHost(long zoneId) {
List<HostVO> hosts = _hostDao.listSecondaryStorageHosts(zoneId);
if( hosts == null || hosts.size() == 0) {
return null;
hosts = _hostDao.listLocalSecondaryStorageHosts(zoneId);
if (hosts.isEmpty()) {
return null;
}
}
int size = hosts.size();

View File

@ -360,7 +360,7 @@ public class DownloadMonitorImpl implements DownloadMonitor {
dcs.add(_dcDao.findById(zoneId));
}
for ( DataCenterVO dc : dcs ) {
List<HostVO> ssHosts = _hostDao.listBy(Host.Type.SecondaryStorage, dc.getId());
List<HostVO> ssHosts = _hostDao.listAllSecondaryStorageHosts(dc.getId());
for ( HostVO ssHost : ssHosts ) {
if (isTemplateUpdateable(ssHost.getId(), templateId)) {
@ -533,7 +533,7 @@ public class DownloadMonitorImpl implements DownloadMonitor {
s_logger.warn("Huh? Agent id " + sserverId + " does not correspond to a row in hosts table?");
return;
}
if ( ssHost.getType() != Host.Type.SecondaryStorage ) {
if ( !(ssHost.getType() == Host.Type.SecondaryStorage || ssHost.getType() == Host.Type.LocalSecondaryStorage) ) {
s_logger.warn("Huh? Agent id " + sserverId + " is not secondary storage host");
return;
}
@ -676,7 +676,8 @@ public class DownloadMonitorImpl implements DownloadMonitor {
}
//This code is mostly for migration purposes so that we have checksum for all the templates
checksumSync(sserverId);
if (ssHost.getType() == Host.Type.SecondaryStorage)
checksumSync(sserverId);
}

View File

@ -1598,7 +1598,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
String secUrl = ssHost.getStorageUrl();
Answer answer;
answer = _agentMgr.sendToSecStorage(ssHost, new ComputeChecksumCommand(secUrl, templatePath));
if(answer.getResult()) {
if(answer != null && answer.getResult()) {
return answer.getDetails();
}
return null;