Skip to content

Commit 2f8235d

Browse files
committed
fix local seconeary storage related issues(sync/download templates, etc) for mycloud
1 parent 5ad41e0 commit 2f8235d

8 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎core/src/com/cloud/storage/resource/LocalSecondaryStorageResource.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.cloud.agent.api.CheckHealthAnswer;
3030
import com.cloud.agent.api.CheckHealthCommand;
3131
import com.cloud.agent.api.Command;
32+
import com.cloud.agent.api.ComputeChecksumCommand;
3233
import com.cloud.agent.api.PingCommand;
3334
import com.cloud.agent.api.PingStorageCommand;
3435
import com.cloud.agent.api.ReadyAnswer;
@@ -97,11 +98,18 @@ public Answer executeRequest(Command cmd) {
9798
return new ReadyAnswer((ReadyCommand)cmd);
9899
} else if (cmd instanceof ListTemplateCommand){
99100
return execute((ListTemplateCommand)cmd);
101+
} else if (cmd instanceof ComputeChecksumCommand){
102+
return execute((ComputeChecksumCommand)cmd);
100103
} else {
101104
return Answer.createUnsupportedCommandAnswer(cmd);
102105
}
103106
}
104107

108+
private Answer execute(ComputeChecksumCommand cmd) {
109+
return new Answer(cmd, false, null);
110+
}
111+
112+
105113
private Answer execute(ListTemplateCommand cmd) {
106114
String root = getRootDir();
107115
Map<String, TemplateInfo> templateInfos = _dlMgr.gatherTemplateInfo(root);

‎server/src/com/cloud/host/dao/HostDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ public interface HostDao extends GenericDao<HostVO, Long> {
173173
List<HostVO> listLocalSecondaryStorageHosts();
174174

175175
List<HostVO> listLocalSecondaryStorageHosts(long dataCenterId);
176+
177+
List<HostVO> listAllSecondaryStorageHosts(long dataCenterId);
176178
}

‎server/src/com/cloud/host/dao/HostDaoImpl.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ public List<HostVO> listLocalSecondaryStorageHosts(long dataCenterId) {
317317
return search(sc, null);
318318

319319
}
320+
321+
@Override
322+
public List<HostVO> listAllSecondaryStorageHosts(long dataCenterId) {
323+
SearchCriteria<HostVO> sc = createSearchCriteria();
324+
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dataCenterId);
325+
sc.addAnd("type", SearchCriteria.Op.IN, new Object[]{Host.Type.LocalSecondaryStorage, Host.Type.SecondaryStorage});
326+
return search(sc, null);
327+
}
320328

321329
@Override
322330
public List<HostVO> findDirectlyConnectedHosts() {

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ private List<HostVO> searchForServers(Long startIndex, Long pageSize, Object nam
13071307
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
13081308
}
13091309
if (type != null) {
1310-
sc.addAnd("type", SearchCriteria.Op.EQ, type);
1310+
sc.addAnd("type", SearchCriteria.Op.LIKE, "%" + type + "%");
13111311
}
13121312
if (state != null) {
13131313
sc.addAnd("status", SearchCriteria.Op.EQ, state);

‎server/src/com/cloud/server/StatsCollector.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public void run() {
152152
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.Storage.toString());
153153
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.ConsoleProxy.toString());
154154
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.SecondaryStorage.toString());
155+
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.LocalSecondaryStorage.toString());
155156
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.TrafficMonitor.toString());
156157
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.SecondaryStorageVM.toString());
157158
ConcurrentHashMap<Long, HostStats> hostStats = new ConcurrentHashMap<Long, HostStats>();

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,10 @@ public HostVO getSecondaryStorageHost(long zoneId, long tmpltId) {
959959
public HostVO getSecondaryStorageHost(long zoneId) {
960960
List<HostVO> hosts = _hostDao.listSecondaryStorageHosts(zoneId);
961961
if( hosts == null || hosts.size() == 0) {
962-
return null;
962+
hosts = _hostDao.listLocalSecondaryStorageHosts(zoneId);
963+
if (hosts.isEmpty()) {
964+
return null;
965+
}
963966
}
964967

965968
int size = hosts.size();

‎server/src/com/cloud/storage/download/DownloadMonitorImpl.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public boolean downloadTemplateToStorage(Long templateId, Long zoneId) {
360360
dcs.add(_dcDao.findById(zoneId));
361361
}
362362
for ( DataCenterVO dc : dcs ) {
363-
List<HostVO> ssHosts = _hostDao.listBy(Host.Type.SecondaryStorage, dc.getId());
363+
List<HostVO> ssHosts = _hostDao.listAllSecondaryStorageHosts(dc.getId());
364364
for ( HostVO ssHost : ssHosts ) {
365365
if (isTemplateUpdateable(ssHost.getId(), templateId)) {
366366

@@ -533,7 +533,7 @@ public void handleTemplateSync(HostVO ssHost) {
533533
s_logger.warn("Huh? Agent id " + sserverId + " does not correspond to a row in hosts table?");
534534
return;
535535
}
536-
if ( ssHost.getType() != Host.Type.SecondaryStorage ) {
536+
if ( !(ssHost.getType() == Host.Type.SecondaryStorage || ssHost.getType() == Host.Type.LocalSecondaryStorage) ) {
537537
s_logger.warn("Huh? Agent id " + sserverId + " is not secondary storage host");
538538
return;
539539
}
@@ -676,7 +676,8 @@ public void handleTemplateSync(HostVO ssHost) {
676676
}
677677

678678
//This code is mostly for migration purposes so that we have checksum for all the templates
679-
checksumSync(sserverId);
679+
if (ssHost.getType() == Host.Type.SecondaryStorage)
680+
checksumSync(sserverId);
680681

681682

682683
}

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ public String getChecksum(Long hostId, String templatePath){
15981598
String secUrl = ssHost.getStorageUrl();
15991599
Answer answer;
16001600
answer = _agentMgr.sendToSecStorage(ssHost, new ComputeChecksumCommand(secUrl, templatePath));
1601-
if(answer.getResult()) {
1601+
if(answer != null && answer.getResult()) {
16021602
return answer.getDetails();
16031603
}
16041604
return null;

0 commit comments

Comments
 (0)