Add implemention to pick EndPoint for secondary storage

This commit is contained in:
Min Chen 2013-04-22 13:19:04 -07:00
parent 0a6e386997
commit ffdf567b58
4 changed files with 51 additions and 20 deletions

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.cloudstack.engine.subsystem.api.storage; package org.apache.cloudstack.engine.subsystem.api.storage;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.framework.async.AsyncCallFuture;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncCompletionCallback;

View File

@ -22,6 +22,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@ -37,6 +38,7 @@ import org.apache.cloudstack.storage.LocalHostEndpoint;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.cloud.host.Host;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
import com.cloud.host.Status; import com.cloud.host.Status;
import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDao;
@ -175,6 +177,36 @@ public class DefaultEndPointSelector implements EndPointSelector {
return findEndPointInScope(store.getScope(), findOneHostOnPrimaryStorage); return findEndPointInScope(store.getScope(), findOneHostOnPrimaryStorage);
} }
protected EndPoint findEndpointForImageStorage(DataStore store) {
Long dcId = null;
Scope storeScope = store.getScope();
if (storeScope.getScopeType() == ScopeType.ZONE) {
dcId = storeScope.getScopeId();
}
// find ssvm that can be used to download data to store. For zone-wide
// image store, use SSVM for that zone. For region-wide store,
// we can arbitrarily pick one ssvm to do that task
List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
if (ssAHosts == null || ssAHosts.isEmpty()) {
return new LocalHostEndpoint(); // use local host as endpoint in
// case of no ssvm existing
}
Collections.shuffle(ssAHosts);
HostVO host = ssAHosts.get(0);
return RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress());
}
private List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
if (dcId != null) {
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
}
sc.addAnd(sc.getEntity().getStatus(), Op.IN, com.cloud.host.Status.Up, com.cloud.host.Status.Connecting);
sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
return sc.list();
}
@Override @Override
public EndPoint select(DataObject object) { public EndPoint select(DataObject object) {
DataStore store = object.getDataStore(); DataStore store = object.getDataStore();
@ -182,8 +214,8 @@ public class DefaultEndPointSelector implements EndPointSelector {
return findEndpointForPrimaryStorage(store); return findEndpointForPrimaryStorage(store);
} else if (store.getRole() == DataStoreRole.Image) { } else if (store.getRole() == DataStoreRole.Image) {
//in case there is no ssvm, directly send down command hypervisor host //in case there is no ssvm, directly send down command hypervisor host
//TODO: add code to handle in case ssvm is there // otherwise, send to localhost for bootstrap system vm template download
return findEndpointForPrimaryStorage(store); return findEndpointForImageStorage(store);
}else { }else {
throw new CloudRuntimeException("not implemented yet"); throw new CloudRuntimeException("not implemented yet");
} }

View File

@ -710,7 +710,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
} }
@DB @DB
private void updateClusterNativeHAState(HostVO host, StartupCommand cmd) { private void updateClusterNativeHAState(Host host, StartupCommand cmd) {
ClusterVO cluster = _clusterDao.findById(host.getClusterId()); ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if(cluster.getClusterType() == ClusterType.ExternalManaged) { if(cluster.getClusterType() == ClusterType.ExternalManaged) {
if(cmd instanceof StartupRoutingCommand) { if(cmd instanceof StartupRoutingCommand) {