refine the logic seraching ssvm when generate firewall configuration

This commit is contained in:
frank 2011-11-09 14:36:14 -08:00
parent 56e5255cdc
commit 3cc37ed3fb
3 changed files with 21 additions and 23 deletions

View File

@ -178,5 +178,7 @@ public interface HostDao extends GenericDao<HostVO, Long> {
List<HostVO> listByInAllStatus(Type type, Long clusterId, Long podId, long dcId);
List<HostVO> listByClusterStatus(long clusterId, Status status);
List<HostVO> listByClusterStatus(long clusterId, Status status);
List<HostVO> listSecondaryStorageVMInUpAndConnecting(long dcId);
}

View File

@ -146,7 +146,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
SecondaryStorageVMSearch = createSearchBuilder();
SecondaryStorageVMSearch.and("type", SecondaryStorageVMSearch.entity().getType(), SearchCriteria.Op.EQ);
SecondaryStorageVMSearch.and("dc", SecondaryStorageVMSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
SecondaryStorageVMSearch.and("status", SecondaryStorageVMSearch.entity().getStatus(), SearchCriteria.Op.EQ);
SecondaryStorageVMSearch.and("status", SecondaryStorageVMSearch.entity().getStatus(), SearchCriteria.Op.IN);
SecondaryStorageVMSearch.done();
TypeDcStatusSearch = createSearchBuilder();
@ -801,6 +801,17 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return listBy(sc);
}
@Override
public List<HostVO> listSecondaryStorageVMInUpAndConnecting(long dcId) {
SearchCriteria<HostVO> sc = SecondaryStorageVMSearch.create();
sc.setParameters("type", Type.SecondaryStorageVM);
sc.setParameters("status", Status.Up, Status.Connecting);
sc.setParameters("dc", dcId);
return listBy(sc);
}
@Override
public List<HostVO> listByType(Type type) {
SearchCriteria<HostVO> sc = TypeSearch.create();

View File

@ -376,37 +376,22 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
return false;
}
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, State.Running, State.Migrating, State.Starting);
String copyPort = _useSSlCopy? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
SecStorageFirewallCfgCommand cpc = new SecStorageFirewallCfgCommand();
SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand();
thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
for (SecondaryStorageVmVO ssVm : alreadyRunning) {
if ( ssVm.getDataCenterIdToDeployIn() == zoneId ) {
continue;
}
if (ssVm.getPublicIpAddress() != null) {
cpc.addPortConfig(ssVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
}
if ( ssVm.getState() != State.Running ) {
continue;
}
String instanceName = ssVm.getInstanceName();
HostVO host = _hostDao.findByName(instanceName);
if ( host == null ) {
continue;
}
Answer answer = _agentMgr.easySend(host.getId(), thiscpc);
List<HostVO> ssvms = _hostDao.listSecondaryStorageVMInUpAndConnecting(zoneId);
for (HostVO ssvm : ssvms) {
Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Successfully programmed firewall rules into " + ssVm.getHostName());
s_logger.debug("Successfully programmed firewall rules into " + ssvm.getName());
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("failed to program firewall rules into secondary storage vm : " + ssVm.getHostName());
s_logger.debug("failed to program firewall rules into secondary storage vm : " + ssvm.getName());
}
return false;
}
}