mirror of https://github.com/apache/cloudstack.git
Merge branch 'master' into ui-restyle
This commit is contained in:
commit
ef74127984
|
|
@ -188,6 +188,8 @@ public class EventTypes {
|
|||
public static final String EVENT_VOLUME_DETAIL_UPDATE = "VOLUME.DETAIL.UPDATE";
|
||||
public static final String EVENT_VOLUME_DETAIL_ADD = "VOLUME.DETAIL.ADD";
|
||||
public static final String EVENT_VOLUME_DETAIL_REMOVE = "VOLUME.DETAIL.REMOVE";
|
||||
public static final String EVENT_VOLUME_UPDATE = "VOLUME.UPDATE";
|
||||
|
||||
|
||||
// Domains
|
||||
public static final String EVENT_DOMAIN_CREATE = "DOMAIN.CREATE";
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ import org.apache.cloudstack.api.Identity;
|
|||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
public interface VirtualRouterProvider extends InternalIdentity, Identity {
|
||||
public enum VirtualRouterProviderType {
|
||||
public enum Type {
|
||||
VirtualRouter,
|
||||
ElasticLoadBalancerVm,
|
||||
VPCVirtualRouter,
|
||||
InternalLbVm
|
||||
}
|
||||
|
||||
public VirtualRouterProviderType getType();
|
||||
public Type getType();
|
||||
|
||||
public boolean isEnabled();
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElem
|
|||
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
|
||||
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
|
||||
public interface VirtualRouterElementService extends PluggableService{
|
||||
VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd);
|
||||
VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType);
|
||||
VirtualRouterProvider addElement(Long nspId, Type providerType);
|
||||
VirtualRouterProvider getCreatedElement(long id);
|
||||
List<? extends VirtualRouterProvider> searchForVirtualRouterElement(ListVirtualRouterElementsCmd cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public interface VolumeApiService {
|
|||
|
||||
Snapshot allocSnapshot(Long volumeId, Long policyId)
|
||||
throws ResourceAllocationException;
|
||||
Volume updateVolume(UpdateVolumeCmd updateVolumeCmd);
|
||||
Volume updateVolume(long volumeId, String path, String state, Long storageId);
|
||||
|
||||
/**
|
||||
* Extracts the volume to a particular location.
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import com.cloud.event.EventTypes;
|
|||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.element.VirtualRouterElementService;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
|
|
@ -70,15 +70,15 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
|
|||
return nspId;
|
||||
}
|
||||
|
||||
public VirtualRouterProviderType getProviderType() {
|
||||
public Type getProviderType() {
|
||||
if (providerType != null) {
|
||||
if (providerType.equalsIgnoreCase(VirtualRouterProviderType.VirtualRouter.toString())) {
|
||||
return VirtualRouterProviderType.VirtualRouter;
|
||||
} else if (providerType.equalsIgnoreCase(VirtualRouterProviderType.VPCVirtualRouter.toString())) {
|
||||
return VirtualRouterProviderType.VPCVirtualRouter;
|
||||
if (providerType.equalsIgnoreCase(Type.VirtualRouter.toString())) {
|
||||
return Type.VirtualRouter;
|
||||
} else if (providerType.equalsIgnoreCase(Type.VPCVirtualRouter.toString())) {
|
||||
return Type.VPCVirtualRouter;
|
||||
} else throw new InvalidParameterValueException("Invalid providerType specified");
|
||||
}
|
||||
return VirtualRouterProviderType.VirtualRouter;
|
||||
return Type.VirtualRouter;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -23,15 +23,14 @@ import org.apache.cloudstack.api.ApiErrorCode;
|
|||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "updateVolume", description="Updates the volume.", responseObject=VolumeResponse.class)
|
||||
public class UpdateVolumeCmd extends BaseAsyncCmd {
|
||||
|
|
@ -42,13 +41,18 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
|
|||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VolumeResponse.class,
|
||||
required=true, description="the ID of the disk volume")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VolumeResponse.class, description="the ID of the disk volume")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.PATH, type=CommandType.STRING,
|
||||
required=true, description="the path of the volume")
|
||||
@Parameter(name=ApiConstants.PATH, type=CommandType.STRING, description="The path of the volume")
|
||||
private String path;
|
||||
|
||||
@Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.UUID, entityType=StoragePoolResponse.class,
|
||||
description="Destination storage pool UUID for the volume", since="4.3")
|
||||
private Long storageId;
|
||||
|
||||
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="The state of the volume", since="4.3")
|
||||
private String state;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -61,6 +65,15 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
|
|||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Long getStorageId() {
|
||||
return storageId;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
|
|
@ -83,25 +96,37 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
|
|||
public long getEntityOwnerId() {
|
||||
Volume volume = _responseGenerator.findVolumeById(getId());
|
||||
if (volume == null) {
|
||||
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked
|
||||
throw new InvalidParameterValueException("Invalid volume id was provided");
|
||||
}
|
||||
return volume.getAccountId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_VOLUME_ATTACH;
|
||||
return EventTypes.EVENT_VOLUME_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "adding detail to the volume: " + getId();
|
||||
StringBuffer desc = new StringBuffer();
|
||||
desc.append(" with");
|
||||
if (getPath() != null) {
|
||||
desc.append(" path " + getPath());
|
||||
}
|
||||
if (getStorageId() != null) {
|
||||
desc.append(", storage id " + getStorageId());
|
||||
}
|
||||
|
||||
if (getState() != null) {
|
||||
desc.append(", state " + getState());
|
||||
}
|
||||
return "Updating volume: " + getId() + desc.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
CallContext.current().setEventDetails("Volume Id: "+getId());
|
||||
Volume result = _volumeService.updateVolume(this);
|
||||
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId());
|
||||
if (result != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
*/
|
||||
public class CallContext {
|
||||
private static final Logger s_logger = Logger.getLogger(CallContext.class);
|
||||
private static ThreadLocal<CallContext> s_currentContext = new ThreadLocal<CallContext>();
|
||||
private static final ThreadLocal<CallContext> s_currentContext = new ThreadLocal<CallContext>();
|
||||
|
||||
private String contextId;
|
||||
private Account account;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Description: CloudStack server library
|
|||
|
||||
Package: cloudstack-agent
|
||||
Architecture: all
|
||||
Depends: openjdk-6-jre | openjdk-7-jre, cloudstack-common (= ${source:Version}), lsb-base (>= 3.2), libcommons-daemon-java, libjna-java, openssh-client, libvirt0, sysvinit-utils, qemu-kvm, libvirt-bin, uuid-runtime, rsync, grep, iproute, perl-base, perl-modules, ebtables, vlan, wget, jsvc, ipset, python-libvirt
|
||||
Depends: openjdk-6-jre | openjdk-7-jre, cloudstack-common (= ${source:Version}), lsb-base (>= 3.2), libcommons-daemon-java, openssh-client, libvirt0, sysvinit-utils, qemu-kvm, libvirt-bin, uuid-runtime, rsync, grep, iproute, perl-base, perl-modules, ebtables, vlan, wget, jsvc, ipset, python-libvirt
|
||||
Conflicts: cloud-agent, cloud-agent-libs, cloud-agent-deps, cloud-agent-scripts
|
||||
Description: CloudStack agent
|
||||
The CloudStack agent is in charge of managing shared computing resources in
|
||||
|
|
|
|||
|
|
@ -97,9 +97,8 @@ import com.cloud.utils.component.ManagerBase;
|
|||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.exception.HypervisorVersionChangedException;
|
||||
|
|
@ -1448,8 +1447,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
|||
try {
|
||||
List<Long> behindAgents = findAgentsBehindOnPing();
|
||||
for (Long agentId : behindAgents) {
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getId(), Op.EQ, agentId);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getId(), Op.EQ, agentId);
|
||||
HostVO h = sc.find();
|
||||
if (h != null) {
|
||||
ResourceState resourceState = h.getResourceState();
|
||||
|
|
@ -1470,8 +1469,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
|||
}
|
||||
}
|
||||
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getResourceState(), Op.IN, ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getResourceState(), Op.IN, ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance);
|
||||
List<HostVO> hosts = sc.list();
|
||||
|
||||
for (HostVO host : hosts) {
|
||||
|
|
|
|||
|
|
@ -87,9 +87,8 @@ import com.cloud.serializer.GsonHelper;
|
|||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.Profiler;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.nio.Link;
|
||||
|
|
@ -783,9 +782,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
|||
public void startRebalanceAgents() {
|
||||
s_logger.debug("Management server " + _nodeId + " is asking other peers to rebalance their agents");
|
||||
List<ManagementServerHostVO> allMS = _mshostDao.listBy(ManagementServerHost.State.Up);
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getManagementServerId(), Op.NNULL);
|
||||
sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.Routing);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getManagementServerId(), Op.NNULL);
|
||||
sc.and(sc.entity().getType(), Op.EQ, Host.Type.Routing);
|
||||
List<HostVO> allManagedAgents = sc.list();
|
||||
|
||||
int avLoad = 0;
|
||||
|
|
@ -1369,13 +1368,13 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
|||
profilerAgentLB.start();
|
||||
//initiate agent lb task will be scheduled and executed only once, and only when number of agents loaded exceeds _connectedAgentsThreshold
|
||||
if (EnableLB.value() && !_agentLbHappened) {
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getManagementServerId(), Op.NNULL);
|
||||
sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.Routing);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getManagementServerId(), Op.NNULL);
|
||||
sc.and(sc.entity().getType(), Op.EQ, Host.Type.Routing);
|
||||
List<HostVO> allManagedRoutingAgents = sc.list();
|
||||
|
||||
sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.Routing);
|
||||
sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getType(), Op.EQ, Host.Type.Routing);
|
||||
List<HostVO> allAgents = sc.list();
|
||||
double allHostsCount = allAgents.size();
|
||||
double managedHostsCount = allManagedRoutingAgents.size();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import java.util.Map;
|
|||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -36,9 +35,8 @@ import com.cloud.host.HostVO;
|
|||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
|
||||
@Component
|
||||
@Local(value=AgentLoadBalancerPlanner.class)
|
||||
|
|
@ -49,9 +47,9 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements
|
|||
|
||||
@Override
|
||||
public List<HostVO> getHostsToRebalance(long msId, int avLoad) {
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.Routing);
|
||||
sc.addAnd(sc.getEntity().getManagementServerId(), Op.EQ, msId);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getType(), Op.EQ, Host.Type.Routing);
|
||||
sc.and(sc.entity().getManagementServerId(), Op.EQ, msId);
|
||||
List<HostVO> allHosts = sc.list();
|
||||
|
||||
if (allHosts.size() <= avLoad) {
|
||||
|
|
@ -59,15 +57,15 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements
|
|||
return null;
|
||||
}
|
||||
|
||||
sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getManagementServerId(), Op.EQ, msId);
|
||||
sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
|
||||
sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getManagementServerId(), Op.EQ, msId);
|
||||
sc.and(sc.entity().getStatus(), Op.EQ, Status.Up);
|
||||
List<HostVO> directHosts = sc.list();
|
||||
|
||||
if (directHosts.isEmpty()) {
|
||||
s_logger.debug("No direct agents in status " + Status.Up + " exist for the management server " + msId + "; so it doesn't participate in agent rebalancing process");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Map<Long, List<HostVO>> hostToClusterMap = new HashMap<Long, List<HostVO>>();
|
||||
|
|
@ -91,7 +89,7 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements
|
|||
int hostsLeft = directHosts.size();
|
||||
List<HostVO> hostsToReturn = new ArrayList<HostVO>();
|
||||
|
||||
s_logger.debug("Management server " + msId + " can give away " + hostsToGive + " as it currently owns " + allHosts.size() +
|
||||
s_logger.debug("Management server " + msId + " can give away " + hostsToGive + " as it currently owns " + allHosts.size() +
|
||||
" and the average agent load in the system is " + avLoad + "; finalyzing list of hosts to give away...");
|
||||
for (Long cluster : hostToClusterMap.keySet()) {
|
||||
List<HostVO> hostsInCluster = hostToClusterMap.get(cluster);
|
||||
|
|
@ -105,7 +103,7 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements
|
|||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("Taking all " + hostsInCluster.size() + " hosts: " + hostsInCluster + " from cluster id=" + cluster);
|
||||
hostsToReturn.addAll(hostsInCluster);
|
||||
|
|
|
|||
|
|
@ -257,7 +257,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
this._hostAllocators = _hostAllocators;
|
||||
}
|
||||
|
||||
@Inject
|
||||
protected List<StoragePoolAllocator> _storagePoolAllocators;
|
||||
|
||||
@Inject
|
||||
|
|
@ -3271,4 +3270,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
VmOpWaitInterval};
|
||||
}
|
||||
|
||||
public List<StoragePoolAllocator> getStoragePoolAllocators() {
|
||||
return _storagePoolAllocators;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators) {
|
||||
this._storagePoolAllocators = storagePoolAllocators;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ public class VMEntityManagerImpl implements VMEntityManager {
|
|||
@Inject
|
||||
protected VirtualMachineManager _itMgr;
|
||||
|
||||
@Inject
|
||||
protected List<DeploymentPlanner> _planners;
|
||||
|
||||
@Inject
|
||||
|
|
@ -257,4 +256,13 @@ public class VMEntityManagerImpl implements VMEntityManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
public List<DeploymentPlanner> getPlanners() {
|
||||
return _planners;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setPlanners(List<DeploymentPlanner> planners) {
|
||||
this._planners = planners;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ public class EngineClusterDaoImpl extends GenericDaoBase<EngineClusterVO, Long>
|
|||
@Override
|
||||
public List<Long> listDisabledClusters(long zoneId, Long podId) {
|
||||
GenericSearchBuilder<EngineClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
|
||||
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.selectFields(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.and("dataCenterId", clusterIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
if(podId != null){
|
||||
clusterIdSearch.and("podId", clusterIdSearch.entity().getPodId(), Op.EQ);
|
||||
|
|
@ -224,12 +224,12 @@ public class EngineClusterDaoImpl extends GenericDaoBase<EngineClusterVO, Long>
|
|||
public List<Long> listClustersWithDisabledPods(long zoneId) {
|
||||
|
||||
GenericSearchBuilder<EngineHostPodVO, Long> disabledPodIdSearch = _hostPodDao.createSearchBuilder(Long.class);
|
||||
disabledPodIdSearch.selectField(disabledPodIdSearch.entity().getId());
|
||||
disabledPodIdSearch.selectFields(disabledPodIdSearch.entity().getId());
|
||||
disabledPodIdSearch.and("dataCenterId", disabledPodIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
disabledPodIdSearch.and("allocationState", disabledPodIdSearch.entity().getAllocationState(), Op.EQ);
|
||||
|
||||
GenericSearchBuilder<EngineClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
|
||||
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.selectFields(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.join("disabledPodIdSearch", disabledPodIdSearch, clusterIdSearch.entity().getPodId(), disabledPodIdSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
clusterIdSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
|
|||
AvailHypevisorInZone.done();
|
||||
|
||||
HostsInStatusSearch = createSearchBuilder(Long.class);
|
||||
HostsInStatusSearch.selectField(HostsInStatusSearch.entity().getId());
|
||||
HostsInStatusSearch.selectFields(HostsInStatusSearch.entity().getId());
|
||||
HostsInStatusSearch.and("dc", HostsInStatusSearch.entity().getDataCenterId(), Op.EQ);
|
||||
HostsInStatusSearch.and("pod", HostsInStatusSearch.entity().getPodId(), Op.EQ);
|
||||
HostsInStatusSearch.and("cluster", HostsInStatusSearch.entity().getClusterId(), Op.EQ);
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ public class EngineHostPodDaoImpl extends GenericDaoBase<EngineHostPodVO, Long>
|
|||
@Override
|
||||
public List<Long> listDisabledPods(long zoneId) {
|
||||
GenericSearchBuilder<EngineHostPodVO, Long> podIdSearch = createSearchBuilder(Long.class);
|
||||
podIdSearch.selectField(podIdSearch.entity().getId());
|
||||
podIdSearch.selectFields(podIdSearch.entity().getId());
|
||||
podIdSearch.and("dataCenterId", podIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
podIdSearch.and("allocationState", podIdSearch.entity().getAllocationState(), Op.EQ);
|
||||
podIdSearch.done();
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
|||
ZoneClusterSearch.done();
|
||||
|
||||
ClusterIdSearch = createSearchBuilder(Long.class);
|
||||
ClusterIdSearch.selectField(ClusterIdSearch.entity().getId());
|
||||
ClusterIdSearch.selectFields(ClusterIdSearch.entity().getId());
|
||||
ClusterIdSearch.and("dataCenterId", ClusterIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
ClusterIdSearch.done();
|
||||
}
|
||||
|
|
@ -196,7 +196,7 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
|||
@Override
|
||||
public List<Long> listDisabledClusters(long zoneId, Long podId) {
|
||||
GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
|
||||
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.selectFields(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.and("dataCenterId", clusterIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
if (podId != null) {
|
||||
clusterIdSearch.and("podId", clusterIdSearch.entity().getPodId(), Op.EQ);
|
||||
|
|
@ -217,12 +217,12 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
|||
public List<Long> listClustersWithDisabledPods(long zoneId) {
|
||||
|
||||
GenericSearchBuilder<HostPodVO, Long> disabledPodIdSearch = _hostPodDao.createSearchBuilder(Long.class);
|
||||
disabledPodIdSearch.selectField(disabledPodIdSearch.entity().getId());
|
||||
disabledPodIdSearch.selectFields(disabledPodIdSearch.entity().getId());
|
||||
disabledPodIdSearch.and("dataCenterId", disabledPodIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
disabledPodIdSearch.and("allocationState", disabledPodIdSearch.entity().getAllocationState(), Op.EQ);
|
||||
|
||||
GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
|
||||
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.selectFields(clusterIdSearch.entity().getId());
|
||||
clusterIdSearch.join("disabledPodIdSearch", disabledPodIdSearch, clusterIdSearch.entity().getPodId(), disabledPodIdSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
clusterIdSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements H
|
|||
DataCenterIdSearch.done();
|
||||
|
||||
PodIdSearch = createSearchBuilder(Long.class);
|
||||
PodIdSearch.selectField(PodIdSearch.entity().getId());
|
||||
PodIdSearch.selectFields(PodIdSearch.entity().getId());
|
||||
PodIdSearch.and("dataCenterId", PodIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
PodIdSearch.and("allocationState", PodIdSearch.entity().getAllocationState(), Op.EQ);
|
||||
PodIdSearch.done();
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import com.cloud.utils.db.GenericDaoBase;
|
|||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.GenericQueryBuilder;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
|
@ -56,7 +56,7 @@ public class StorageNetworkIpAddressDaoImpl extends GenericDaoBase<StorageNetwor
|
|||
countInUserIp.done();
|
||||
|
||||
listInUseIp = createSearchBuilder(String.class);
|
||||
listInUseIp.selectField(listInUseIp.entity().getIpAddress());
|
||||
listInUseIp.selectFields(listInUseIp.entity().getIpAddress());
|
||||
listInUseIp.and("rangeId", listInUseIp.entity().getRangeId(), Op.EQ);
|
||||
listInUseIp.and("taken", listInUseIp.entity().getTakenAt(), Op.NNULL);
|
||||
listInUseIp.done();
|
||||
|
|
|
|||
|
|
@ -17,22 +17,17 @@
|
|||
package com.cloud.dc.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.StorageNetworkIpRangeVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
||||
|
|
@ -50,22 +45,22 @@ public class StorageNetworkIpRangeDaoImpl extends GenericDaoBase<StorageNetworkI
|
|||
|
||||
@Override
|
||||
public List<StorageNetworkIpRangeVO> listByPodId(long podId) {
|
||||
SearchCriteriaService<StorageNetworkIpRangeVO, StorageNetworkIpRangeVO> sc = SearchCriteria2.create(StorageNetworkIpRangeVO.class);
|
||||
sc.addAnd(sc.getEntity().getPodId(), Op.EQ, podId);
|
||||
QueryBuilder<StorageNetworkIpRangeVO> sc = QueryBuilder.create(StorageNetworkIpRangeVO.class);
|
||||
sc.and(sc.entity().getPodId(), Op.EQ, podId);
|
||||
return sc.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageNetworkIpRangeVO> listByRangeId(long rangeId) {
|
||||
SearchCriteriaService<StorageNetworkIpRangeVO, StorageNetworkIpRangeVO> sc = SearchCriteria2.create(StorageNetworkIpRangeVO.class);
|
||||
sc.addAnd(sc.getEntity().getId(), Op.EQ, rangeId);
|
||||
QueryBuilder<StorageNetworkIpRangeVO> sc = QueryBuilder.create(StorageNetworkIpRangeVO.class);
|
||||
sc.and(sc.entity().getId(), Op.EQ, rangeId);
|
||||
return sc.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageNetworkIpRangeVO> listByDataCenterId(long dcId) {
|
||||
SearchCriteriaService<StorageNetworkIpRangeVO, StorageNetworkIpRangeVO> sc = SearchCriteria2.create(StorageNetworkIpRangeVO.class);
|
||||
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
|
||||
QueryBuilder<StorageNetworkIpRangeVO> sc = QueryBuilder.create(StorageNetworkIpRangeVO.class);
|
||||
sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId);
|
||||
return sc.list();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class DomainDaoImpl extends GenericDaoBase<DomainVO, Long> implements Dom
|
|||
FindAllChildrenSearch.done();
|
||||
|
||||
FindIdsOfAllChildrenSearch = createSearchBuilder(Long.class);
|
||||
FindIdsOfAllChildrenSearch.selectField(FindIdsOfAllChildrenSearch.entity().getId());
|
||||
FindIdsOfAllChildrenSearch.selectFields(FindIdsOfAllChildrenSearch.entity().getId());
|
||||
FindIdsOfAllChildrenSearch.and("path", FindIdsOfAllChildrenSearch.entity().getPath(), SearchCriteria.Op.LIKE);
|
||||
FindIdsOfAllChildrenSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implem
|
|||
IpeventsSearch.and("networktype", IpeventsSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
|
||||
IpeventsSearch.and().op("assignEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
IpeventsSearch.or("releaseEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
IpeventsSearch.closeParen();
|
||||
IpeventsSearch.cp();
|
||||
IpeventsSearch.done();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ import com.cloud.utils.db.UpdateBuilder;
|
|||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
@Local(value = { HostDao.class })
|
||||
@Local(value = {HostDao.class})
|
||||
@DB(txn = false)
|
||||
@TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1)
|
||||
public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao {
|
||||
|
|
@ -123,13 +123,17 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected Attribute _msIdAttr;
|
||||
protected Attribute _pingTimeAttr;
|
||||
|
||||
@Inject protected HostDetailsDao _detailsDao;
|
||||
@Inject protected HostTagsDao _hostTagsDao;
|
||||
@Inject protected HostTransferMapDao _hostTransferDao;
|
||||
@Inject protected ClusterDao _clusterDao;
|
||||
@Inject
|
||||
protected HostDetailsDao _detailsDao;
|
||||
@Inject
|
||||
protected HostTagsDao _hostTagsDao;
|
||||
@Inject
|
||||
protected HostTransferMapDao _hostTransferDao;
|
||||
@Inject
|
||||
protected ClusterDao _clusterDao;
|
||||
|
||||
public HostDaoImpl() {
|
||||
super();
|
||||
super();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
|
@ -271,18 +275,19 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
* SearchCriteria.Op.LTEQ); UnmanagedDirectConnectSearch.cp(); UnmanagedDirectConnectSearch.cp();
|
||||
*/
|
||||
try {
|
||||
HostTransferSearch = _hostTransferDao.createSearchBuilder();
|
||||
HostTransferSearch = _hostTransferDao.createSearchBuilder();
|
||||
} catch (Throwable e) {
|
||||
s_logger.debug("error", e);
|
||||
s_logger.debug("error", e);
|
||||
}
|
||||
HostTransferSearch.and("id", HostTransferSearch.entity().getId(), SearchCriteria.Op.NULL);
|
||||
UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(), JoinType.LEFTOUTER);
|
||||
UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(),
|
||||
JoinType.LEFTOUTER);
|
||||
ClusterManagedSearch = _clusterDao.createSearchBuilder();
|
||||
ClusterManagedSearch.and("managed", ClusterManagedSearch.entity().getManagedState(), SearchCriteria.Op.EQ);
|
||||
UnmanagedDirectConnectSearch.join("ClusterManagedSearch", ClusterManagedSearch, ClusterManagedSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getClusterId(), JoinType.INNER);
|
||||
UnmanagedDirectConnectSearch.join("ClusterManagedSearch", ClusterManagedSearch, ClusterManagedSearch.entity().getId(),
|
||||
UnmanagedDirectConnectSearch.entity().getClusterId(), JoinType.INNER);
|
||||
UnmanagedDirectConnectSearch.done();
|
||||
|
||||
|
||||
DirectConnectSearch = createSearchBuilder();
|
||||
DirectConnectSearch.and("resource", DirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
|
||||
DirectConnectSearch.and("id", DirectConnectSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -306,7 +311,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
AvailHypevisorInZone.done();
|
||||
|
||||
HostsInStatusSearch = createSearchBuilder(Long.class);
|
||||
HostsInStatusSearch.selectField(HostsInStatusSearch.entity().getId());
|
||||
HostsInStatusSearch.selectFields(HostsInStatusSearch.entity().getId());
|
||||
HostsInStatusSearch.and("dc", HostsInStatusSearch.entity().getDataCenterId(), Op.EQ);
|
||||
HostsInStatusSearch.and("pod", HostsInStatusSearch.entity().getPodId(), Op.EQ);
|
||||
HostsInStatusSearch.and("cluster", HostsInStatusSearch.entity().getClusterId(), Op.EQ);
|
||||
|
|
@ -370,7 +375,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
HostsInClusterSearch.done();
|
||||
|
||||
HostIdSearch = createSearchBuilder(Long.class);
|
||||
HostIdSearch.selectField(HostIdSearch.entity().getId());
|
||||
HostIdSearch.selectFields(HostIdSearch.entity().getId());
|
||||
HostIdSearch.and("dataCenterId", HostIdSearch.entity().getDataCenterId(), Op.EQ);
|
||||
HostIdSearch.done();
|
||||
|
||||
|
|
@ -386,7 +391,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
public long countBy(long clusterId, ResourceState... states) {
|
||||
SearchCriteria<HostVO> sc = MaintenanceCountSearch.create();
|
||||
|
||||
sc.setParameters("resourceState", (Object[]) states);
|
||||
sc.setParameters("resourceState", (Object[])states);
|
||||
sc.setParameters("cluster", clusterId);
|
||||
|
||||
List<HostVO> hosts = listBy(sc);
|
||||
|
|
@ -482,7 +487,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
return ownCluster;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public List<HostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
|
|
@ -580,24 +586,26 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
return assignedHosts;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
txn.start();
|
||||
SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
|
||||
sc.setParameters("lastPinged", lastPingSecondsAfter);
|
||||
sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.BaremetalDhcp, Type.BaremetalPxe, Type.TrafficMonitor, Type.L2Networking);
|
||||
List<HostVO> hosts = lockRows(sc, null, true);
|
||||
txn.start();
|
||||
SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
|
||||
sc.setParameters("lastPinged", lastPingSecondsAfter);
|
||||
sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.BaremetalDhcp, Type.BaremetalPxe, Type.TrafficMonitor,
|
||||
Type.L2Networking);
|
||||
List<HostVO> hosts = lockRows(sc, null, true);
|
||||
|
||||
for (HostVO host : hosts) {
|
||||
host.setManagementServerId(managementServerId);
|
||||
update(host.getId(), host);
|
||||
}
|
||||
for (HostVO host : hosts) {
|
||||
host.setManagementServerId(managementServerId);
|
||||
update(host.getId(), host);
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
txn.commit();
|
||||
|
||||
return hosts;
|
||||
return hosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -657,7 +665,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag) {
|
||||
SearchBuilder<HostTagVO> hostTagSearch = null;
|
||||
|
|
@ -726,7 +733,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
List<HostVO> result = new ArrayList<HostVO>();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "select h.id from host h left join cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;" ;
|
||||
String sql = "select h.id from host h left join cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;";
|
||||
pstmt = txn.prepareStatement(sql);
|
||||
pstmt.setLong(1, timeout);
|
||||
rs = pstmt.executeQuery();
|
||||
|
|
@ -818,9 +825,9 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
@DB
|
||||
public List<RunningHostCountInfo> getRunningHostCounts(Date cutTime) {
|
||||
String sql = "select * from (" + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid "
|
||||
+ "where h.status='Up' and h.type='SecondaryStorage' and m.last_update > ? " + "group by h.data_center_id, h.type " + "UNION ALL "
|
||||
+ "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid "
|
||||
+ "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type";
|
||||
+ "where h.status='Up' and h.type='SecondaryStorage' and m.last_update > ? " + "group by h.data_center_id, h.type " + "UNION ALL "
|
||||
+ "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid "
|
||||
+ "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type";
|
||||
|
||||
ArrayList<RunningHostCountInfo> l = new ArrayList<RunningHostCountInfo>();
|
||||
|
||||
|
|
@ -870,90 +877,100 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
return customSearch(sc, null).get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
|
||||
HostVO host = findById(vo.getId());
|
||||
if (host == null) {
|
||||
if (event == Event.Remove && newStatus == Status.Removed) {
|
||||
host = findByIdIncludingRemoved(vo.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
|
||||
HostVO host = findById(vo.getId());
|
||||
if(host == null){
|
||||
if(event == Event.Remove && newStatus == Status.Removed){
|
||||
host = findByIdIncludingRemoved(vo.getId());
|
||||
}
|
||||
}
|
||||
|
||||
if(host == null){
|
||||
if (host == null) {
|
||||
return false;
|
||||
}
|
||||
long oldPingTime = host.getLastPinged();
|
||||
}
|
||||
long oldPingTime = host.getLastPinged();
|
||||
|
||||
SearchBuilder<HostVO> sb = createSearchBuilder();
|
||||
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
|
||||
sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
|
||||
sb.closeParen();
|
||||
}
|
||||
sb.done();
|
||||
SearchBuilder<HostVO> sb = createSearchBuilder();
|
||||
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
|
||||
sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
|
||||
sb.cp();
|
||||
}
|
||||
sb.done();
|
||||
|
||||
SearchCriteria<HostVO> sc = sb.create();
|
||||
SearchCriteria<HostVO> sc = sb.create();
|
||||
|
||||
sc.setParameters("status", oldStatus);
|
||||
sc.setParameters("id", host.getId());
|
||||
sc.setParameters("update", host.getUpdated());
|
||||
long oldUpdateCount = host.getUpdated();
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sc.setParameters("ping", oldPingTime);
|
||||
sc.setParameters("msid", host.getManagementServerId());
|
||||
}
|
||||
sc.setParameters("status", oldStatus);
|
||||
sc.setParameters("id", host.getId());
|
||||
sc.setParameters("update", host.getUpdated());
|
||||
long oldUpdateCount = host.getUpdated();
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sc.setParameters("ping", oldPingTime);
|
||||
sc.setParameters("msid", host.getManagementServerId());
|
||||
}
|
||||
|
||||
long newUpdateCount = host.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(host);
|
||||
ub.set(host, _statusAttr, newStatus);
|
||||
if (newStatus.updateManagementServer()) {
|
||||
if (newStatus.lostConnection()) {
|
||||
ub.set(host, _msIdAttr, null);
|
||||
} else {
|
||||
ub.set(host, _msIdAttr, host.getManagementServerId());
|
||||
}
|
||||
if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
|
||||
ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
|
||||
}
|
||||
}
|
||||
if (event.equals(Event.ManagementServerDown)) {
|
||||
ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
|
||||
}
|
||||
int result = update(ub, sc, null);
|
||||
assert result <= 1 : "How can this update " + result + " rows? ";
|
||||
long newUpdateCount = host.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(host);
|
||||
ub.set(host, _statusAttr, newStatus);
|
||||
if (newStatus.updateManagementServer()) {
|
||||
if (newStatus.lostConnection()) {
|
||||
ub.set(host, _msIdAttr, null);
|
||||
} else {
|
||||
ub.set(host, _msIdAttr, host.getManagementServerId());
|
||||
}
|
||||
if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
|
||||
ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
|
||||
}
|
||||
}
|
||||
if (event.equals(Event.ManagementServerDown)) {
|
||||
ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
|
||||
}
|
||||
int result = update(ub, sc, null);
|
||||
assert result <= 1 : "How can this update " + result + " rows? ";
|
||||
|
||||
if (status_logger.isDebugEnabled() && result == 0) {
|
||||
HostVO ho = findById(host.getId());
|
||||
assert ho != null : "How how how? : " + host.getId();
|
||||
if (status_logger.isDebugEnabled() && result == 0) {
|
||||
HostVO ho = findById(host.getId());
|
||||
assert ho != null : "How how how? : " + host.getId();
|
||||
|
||||
StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
|
||||
str.append(". Name=").append(host.getName());
|
||||
str.append("; New=[status=").append(newStatus.toString()).append(":msid=")
|
||||
.append(newStatus.lostConnection() ? "null" : host.getManagementServerId()).append(":lastpinged=").append(host.getLastPinged()).append("]");
|
||||
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=")
|
||||
.append(oldPingTime).append("]");
|
||||
str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=")
|
||||
.append(vo.getLastPinged()).append(":old update count=").append(oldUpdateCount).append("]");
|
||||
status_logger.debug(str.toString());
|
||||
} else {
|
||||
StringBuilder msg = new StringBuilder("Agent status update: [");
|
||||
msg.append("id = " + host.getId());
|
||||
msg.append("; name = " + host.getName());
|
||||
msg.append("; old status = " + oldStatus);
|
||||
msg.append("; event = " + event);
|
||||
msg.append("; new status = " + newStatus);
|
||||
msg.append("; old update count = " + oldUpdateCount);
|
||||
msg.append("; new update count = " + newUpdateCount + "]");
|
||||
status_logger.debug(msg.toString());
|
||||
}
|
||||
StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
|
||||
str.append(". Name=").append(host.getName());
|
||||
str.append("; New=[status=")
|
||||
.append(newStatus.toString())
|
||||
.append(":msid=")
|
||||
.append(newStatus.lostConnection() ? "null" : host.getManagementServerId())
|
||||
.append(":lastpinged=")
|
||||
.append(host.getLastPinged())
|
||||
.append("]");
|
||||
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=").append(oldPingTime).append("]");
|
||||
str.append("; DB=[status=")
|
||||
.append(vo.getStatus().toString())
|
||||
.append(":msid=")
|
||||
.append(vo.getManagementServerId())
|
||||
.append(":lastpinged=")
|
||||
.append(vo.getLastPinged())
|
||||
.append(":old update count=")
|
||||
.append(oldUpdateCount)
|
||||
.append("]");
|
||||
status_logger.debug(str.toString());
|
||||
} else {
|
||||
StringBuilder msg = new StringBuilder("Agent status update: [");
|
||||
msg.append("id = " + host.getId());
|
||||
msg.append("; name = " + host.getName());
|
||||
msg.append("; old status = " + oldStatus);
|
||||
msg.append("; event = " + event);
|
||||
msg.append("; new status = " + newStatus);
|
||||
msg.append("; old update count = " + oldUpdateCount);
|
||||
msg.append("; new update count = " + newUpdateCount + "]");
|
||||
status_logger.debug(msg.toString());
|
||||
}
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo) {
|
||||
|
|
@ -978,20 +995,20 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
assert ho != null : "How how how? : " + host.getId();
|
||||
|
||||
StringBuilder str = new StringBuilder("Unable to update resource state: [");
|
||||
str.append("m = " + host.getId());
|
||||
str.append("; name = " + host.getName());
|
||||
str.append("; old state = " + oldState);
|
||||
str.append("; event = " + event);
|
||||
str.append("; new state = " + newState + "]");
|
||||
state_logger.debug(str.toString());
|
||||
str.append("m = " + host.getId());
|
||||
str.append("; name = " + host.getName());
|
||||
str.append("; old state = " + oldState);
|
||||
str.append("; event = " + event);
|
||||
str.append("; new state = " + newState + "]");
|
||||
state_logger.debug(str.toString());
|
||||
} else {
|
||||
StringBuilder msg = new StringBuilder("Resource state update: [");
|
||||
msg.append("id = " + host.getId());
|
||||
msg.append("; name = " + host.getName());
|
||||
msg.append("; old state = " + oldState);
|
||||
msg.append("; event = " + event);
|
||||
msg.append("; new state = " + newState + "]");
|
||||
state_logger.debug(msg.toString());
|
||||
StringBuilder msg = new StringBuilder("Resource state update: [");
|
||||
msg.append("id = " + host.getId());
|
||||
msg.append("; name = " + host.getName());
|
||||
msg.append("; old state = " + oldState);
|
||||
msg.append("; event = " + event);
|
||||
msg.append("; new state = " + newState + "]");
|
||||
state_logger.debug(msg.toString());
|
||||
}
|
||||
|
||||
return result > 0;
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
|||
OfferingAccountNetworkSearch.done();
|
||||
|
||||
GarbageCollectedSearch = createSearchBuilder(Long.class);
|
||||
GarbageCollectedSearch.selectField(GarbageCollectedSearch.entity().getId());
|
||||
GarbageCollectedSearch.selectFields(GarbageCollectedSearch.entity().getId());
|
||||
SearchBuilder<NetworkOpVO> join7 = _ntwkOpDao.createSearchBuilder();
|
||||
join7.and("activenics", join7.entity().getActiveNicsCount(), Op.EQ);
|
||||
join7.and("gc", join7.entity().isGarbageCollected(), Op.EQ);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class NetworkOpDaoImpl extends GenericDaoBase<NetworkOpVO, Long> implemen
|
|||
super();
|
||||
|
||||
ActiveNicsSearch = createSearchBuilder(Integer.class);
|
||||
ActiveNicsSearch.selectField(ActiveNicsSearch.entity().getActiveNicsCount());
|
||||
ActiveNicsSearch.selectFields(ActiveNicsSearch.entity().getActiveNicsCount());
|
||||
ActiveNicsSearch.and("network", ActiveNicsSearch.entity().getId(), Op.EQ);
|
||||
ActiveNicsSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO
|
|||
DistinctProvidersSearch.and("networkId", DistinctProvidersSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.and("service", DistinctProvidersSearch.entity().getService(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
|
||||
DistinctProvidersSearch.selectFields(DistinctProvidersSearch.entity().getProvider());
|
||||
DistinctProvidersSearch.done();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class PhysicalNetworkIsolationMethodDaoImpl extends GenericDaoBase<Physic
|
|||
protected PhysicalNetworkIsolationMethodDaoImpl() {
|
||||
super();
|
||||
IsolationMethodSearch = createSearchBuilder(String.class);
|
||||
IsolationMethodSearch.selectField(IsolationMethodSearch.entity().getIsolationMethod());
|
||||
IsolationMethodSearch.selectFields(IsolationMethodSearch.entity().getIsolationMethod());
|
||||
IsolationMethodSearch.and("physicalNetworkId", IsolationMethodSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
IsolationMethodSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class PhysicalNetworkTagDaoImpl extends GenericDaoBase<PhysicalNetworkTag
|
|||
protected PhysicalNetworkTagDaoImpl() {
|
||||
super();
|
||||
TagSearch = createSearchBuilder(String.class);
|
||||
TagSearch.selectField(TagSearch.entity().getTag());
|
||||
TagSearch.selectFields(TagSearch.entity().getTag());
|
||||
TagSearch.and("physicalNetworkId", TagSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
TagSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -52,31 +52,31 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNe
|
|||
kvmAllFieldsSearch = createSearchBuilder(String.class);
|
||||
kvmAllFieldsSearch.and("physicalNetworkId", kvmAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
kvmAllFieldsSearch.and("trafficType", kvmAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
kvmAllFieldsSearch.selectField(kvmAllFieldsSearch.entity().getKvmNetworkLabel());
|
||||
kvmAllFieldsSearch.selectFields(kvmAllFieldsSearch.entity().getKvmNetworkLabel());
|
||||
kvmAllFieldsSearch.done();
|
||||
|
||||
xenAllFieldsSearch = createSearchBuilder(String.class);
|
||||
xenAllFieldsSearch.and("physicalNetworkId", xenAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
xenAllFieldsSearch.and("trafficType", xenAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
xenAllFieldsSearch.selectField(xenAllFieldsSearch.entity().getXenNetworkLabel());
|
||||
xenAllFieldsSearch.selectFields(xenAllFieldsSearch.entity().getXenNetworkLabel());
|
||||
xenAllFieldsSearch.done();
|
||||
|
||||
vmWareAllFieldsSearch = createSearchBuilder(String.class);
|
||||
vmWareAllFieldsSearch.and("physicalNetworkId", vmWareAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
vmWareAllFieldsSearch.and("trafficType", vmWareAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
vmWareAllFieldsSearch.selectField(vmWareAllFieldsSearch.entity().getVmwareNetworkLabel());
|
||||
vmWareAllFieldsSearch.selectFields(vmWareAllFieldsSearch.entity().getVmwareNetworkLabel());
|
||||
vmWareAllFieldsSearch.done();
|
||||
|
||||
simulatorAllFieldsSearch = createSearchBuilder(String.class);
|
||||
simulatorAllFieldsSearch.and("physicalNetworkId", simulatorAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
simulatorAllFieldsSearch.and("trafficType", simulatorAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
simulatorAllFieldsSearch.selectField(simulatorAllFieldsSearch.entity().getSimulatorNetworkLabel());
|
||||
simulatorAllFieldsSearch.selectFields(simulatorAllFieldsSearch.entity().getSimulatorNetworkLabel());
|
||||
simulatorAllFieldsSearch.done();
|
||||
|
||||
ovmAllFieldsSearch = createSearchBuilder(String.class);
|
||||
ovmAllFieldsSearch.and("physicalNetworkId", ovmAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
ovmAllFieldsSearch.and("trafficType", ovmAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
ovmAllFieldsSearch.selectField(ovmAllFieldsSearch.entity().getSimulatorNetworkLabel());
|
||||
ovmAllFieldsSearch.selectFields(ovmAllFieldsSearch.entity().getSimulatorNetworkLabel());
|
||||
ovmAllFieldsSearch.done();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class RouterNetworkDaoImpl extends GenericDaoBase<RouterNetworkVO, Long>
|
|||
super();
|
||||
|
||||
RouterNetworksSearch = createSearchBuilder(Long.class);
|
||||
RouterNetworksSearch.selectField(RouterNetworksSearch.entity().getNetworkId());
|
||||
RouterNetworksSearch.selectFields(RouterNetworksSearch.entity().getNetworkId());
|
||||
RouterNetworksSearch.and("routerId", RouterNetworksSearch.entity().getRouterId(), Op.EQ);
|
||||
RouterNetworksSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import com.cloud.utils.db.SearchBuilder;
|
|||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.GenericQueryBuilder;
|
||||
|
||||
@Component
|
||||
@Local(value=UserIpv6AddressDao.class)
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ import java.util.List;
|
|||
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.element.VirtualRouterProviderVO;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface VirtualRouterProviderDao extends GenericDao<VirtualRouterProviderVO, Long> {
|
||||
public VirtualRouterProviderVO findByNspIdAndType(long nspId, VirtualRouterProviderType type);
|
||||
public List<VirtualRouterProviderVO> listByEnabledAndType(boolean enabled, VirtualRouterProviderType type);
|
||||
public VirtualRouterProviderVO findByIdAndEnabledAndType(long id, boolean enabled, VirtualRouterProviderType type);
|
||||
public List<VirtualRouterProviderVO> listByType(VirtualRouterProviderType type);
|
||||
public VirtualRouterProviderVO findByNspIdAndType(long nspId, Type type);
|
||||
public List<VirtualRouterProviderVO> listByEnabledAndType(boolean enabled, Type type);
|
||||
public VirtualRouterProviderVO findByIdAndEnabledAndType(long id, boolean enabled, Type type);
|
||||
public List<VirtualRouterProviderVO> listByType(Type type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import javax.ejb.Local;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.network.element.VirtualRouterProviderVO;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
|
|
@ -46,7 +46,7 @@ public class VirtualRouterProviderDaoImpl extends GenericDaoBase<VirtualRouterPr
|
|||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouterProviderVO findByNspIdAndType(long nspId, VirtualRouterProviderType type) {
|
||||
public VirtualRouterProviderVO findByNspIdAndType(long nspId, Type type) {
|
||||
SearchCriteria<VirtualRouterProviderVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("nsp_id", nspId);
|
||||
sc.setParameters("type", type);
|
||||
|
|
@ -54,7 +54,7 @@ public class VirtualRouterProviderDaoImpl extends GenericDaoBase<VirtualRouterPr
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<VirtualRouterProviderVO> listByEnabledAndType(boolean enabled, VirtualRouterProviderType type) {
|
||||
public List<VirtualRouterProviderVO> listByEnabledAndType(boolean enabled, Type type) {
|
||||
SearchCriteria<VirtualRouterProviderVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("enabled", enabled);
|
||||
sc.setParameters("type", type);
|
||||
|
|
@ -62,7 +62,7 @@ public class VirtualRouterProviderDaoImpl extends GenericDaoBase<VirtualRouterPr
|
|||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouterProviderVO findByIdAndEnabledAndType(long id, boolean enabled, VirtualRouterProviderType type) {
|
||||
public VirtualRouterProviderVO findByIdAndEnabledAndType(long id, boolean enabled, Type type) {
|
||||
SearchCriteria<VirtualRouterProviderVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("id", id);
|
||||
sc.setParameters("enabled", enabled);
|
||||
|
|
@ -71,7 +71,7 @@ public class VirtualRouterProviderDaoImpl extends GenericDaoBase<VirtualRouterPr
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<VirtualRouterProviderVO> listByType(VirtualRouterProviderType type) {
|
||||
public List<VirtualRouterProviderVO> listByType(Type type) {
|
||||
SearchCriteria<VirtualRouterProviderVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("type", type);
|
||||
return listBy(sc);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class VirtualRouterProviderVO implements VirtualRouterProvider {
|
|||
|
||||
@Column(name="type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private VirtualRouterProviderType type;
|
||||
private Type type;
|
||||
|
||||
@Column(name="enabled")
|
||||
private boolean enabled;
|
||||
|
|
@ -60,7 +60,7 @@ public class VirtualRouterProviderVO implements VirtualRouterProvider {
|
|||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public VirtualRouterProviderVO(long nspId, VirtualRouterProviderType type) {
|
||||
public VirtualRouterProviderVO(long nspId, Type type) {
|
||||
this.nspId = nspId;
|
||||
this.type = type;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
|
|
@ -81,7 +81,7 @@ public class VirtualRouterProviderVO implements VirtualRouterProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouterProviderType getType() {
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ public class VirtualRouterProviderVO implements VirtualRouterProvider {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public void setType(VirtualRouterProviderType type) {
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class SecurityGroupVMMapDaoImpl extends GenericDaoBase<SecurityGroupVMMap
|
|||
|
||||
ListVmIdBySecurityGroup = createSearchBuilder(Long.class);
|
||||
ListVmIdBySecurityGroup.and("securityGroupId", ListVmIdBySecurityGroup.entity().getSecurityGroupId(), SearchCriteria.Op.EQ);
|
||||
ListVmIdBySecurityGroup.selectField(ListVmIdBySecurityGroup.entity().getInstanceId());
|
||||
ListVmIdBySecurityGroup.selectFields(ListVmIdBySecurityGroup.entity().getInstanceId());
|
||||
ListVmIdBySecurityGroup.done();
|
||||
|
||||
ListBySecurityGroup = createSearchBuilder();
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class VpcServiceMapDaoImpl extends GenericDaoBase<VpcServiceMapVO, Long>
|
|||
DistinctProvidersSearch = createSearchBuilder(String.class);
|
||||
DistinctProvidersSearch.and("vpcId", DistinctProvidersSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
|
||||
DistinctProvidersSearch.selectFields(DistinctProvidersSearch.entity().getProvider());
|
||||
DistinctProvidersSearch.done();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
|
|||
AllFieldsSearch.done();
|
||||
|
||||
UpgradeSearch = createSearchBuilder(Long.class);
|
||||
UpgradeSearch.selectField(UpgradeSearch.entity().getId());
|
||||
UpgradeSearch.selectFields(UpgradeSearch.entity().getId());
|
||||
UpgradeSearch.and("physicalNetworkId", UpgradeSearch.entity().getId(), Op.NEQ);
|
||||
UpgradeSearch.and("physicalNetworkId", UpgradeSearch.entity().isSystemOnly(), Op.EQ);
|
||||
UpgradeSearch.and("trafficType", UpgradeSearch.entity().getTrafficType(), Op.EQ);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
|
|||
DistinctProvidersSearch = createSearchBuilder(String.class);
|
||||
DistinctProvidersSearch.and("offId", DistinctProvidersSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
|
||||
DistinctProvidersSearch.selectFields(DistinctProvidersSearch.entity().getProvider());
|
||||
DistinctProvidersSearch.done();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
|
|||
AllFieldsSearch.done();
|
||||
|
||||
AdminSearch = createSearchBuilder(Long.class);
|
||||
AdminSearch.selectField(AdminSearch.entity().getProjectId());
|
||||
AdminSearch.selectFields(AdminSearch.entity().getProjectId());
|
||||
AdminSearch.and("role", AdminSearch.entity().getAccountRole(), Op.EQ);
|
||||
AdminSearch.and("accountId", AdminSearch.entity().getAccountId(), Op.EQ);
|
||||
AdminSearch.done();
|
||||
|
||||
ProjectAccountSearch = createSearchBuilder(Long.class);
|
||||
ProjectAccountSearch.selectField(ProjectAccountSearch.entity().getProjectAccountId());
|
||||
ProjectAccountSearch.selectFields(ProjectAccountSearch.entity().getProjectAccountId());
|
||||
ProjectAccountSearch.and("accountId", ProjectAccountSearch.entity().getAccountId(), Op.EQ);
|
||||
ProjectAccountSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import javax.persistence.Transient;
|
|||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Entity
|
||||
@Table(name = "volumes")
|
||||
|
|
@ -573,4 +574,10 @@ public class VolumeVO implements Volume {
|
|||
public void setIsoId(long isoId) {
|
||||
this.isoId =isoId;
|
||||
}
|
||||
|
||||
// don't use this directly, use volume state machine instead
|
||||
// This method is used by UpdateVolume as a part of "Better control over first class objects in CS"
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class VersionDaoImpl extends GenericDaoBase<VersionVO, Long> implements V
|
|||
super();
|
||||
|
||||
CurrentVersionSearch = createSearchBuilder(String.class);
|
||||
CurrentVersionSearch.selectField(CurrentVersionSearch.entity().getVersion());
|
||||
CurrentVersionSearch.selectFields(CurrentVersionSearch.entity().getVersion());
|
||||
CurrentVersionSearch.and("step", CurrentVersionSearch.entity().getStep(), Op.EQ);
|
||||
CurrentVersionSearch.done();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,11 +27,10 @@ import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
|||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Local(value = {AccountDetailsDao.class})
|
||||
|
|
@ -46,8 +45,8 @@ public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long>
|
|||
|
||||
@Override
|
||||
public Map<String, String> findDetails(long accountId) {
|
||||
SearchCriteriaService<AccountDetailVO, AccountDetailVO> sc = SearchCriteria2.create(AccountDetailVO.class);
|
||||
sc.addAnd(sc.getEntity().getAccountId(), Op.EQ, accountId);
|
||||
QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
|
||||
sc.and(sc.entity().getAccountId(), Op.EQ, accountId);
|
||||
List<AccountDetailVO> results = sc.list();
|
||||
Map<String, String> details = new HashMap<String, String>(results.size());
|
||||
for (AccountDetailVO r : results) {
|
||||
|
|
@ -72,9 +71,9 @@ public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long>
|
|||
|
||||
@Override
|
||||
public AccountDetailVO findDetail(long accountId, String name) {
|
||||
SearchCriteriaService<AccountDetailVO, AccountDetailVO> sc = SearchCriteria2.create(AccountDetailVO.class);
|
||||
sc.addAnd(sc.getEntity().getAccountId(), Op.EQ, accountId);
|
||||
sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
|
||||
QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
|
||||
sc.and(sc.entity().getAccountId(), Op.EQ, accountId);
|
||||
sc.and(sc.entity().getName(), Op.EQ, name);
|
||||
return sc.find();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
|
|||
NonProjectAccountSearch.done();
|
||||
|
||||
AccountIdsSearch = createSearchBuilder(Long.class);
|
||||
AccountIdsSearch.selectField(AccountIdsSearch.entity().getId());
|
||||
AccountIdsSearch.selectFields(AccountIdsSearch.entity().getId());
|
||||
AccountIdsSearch.and("ids", AccountIdsSearch.entity().getDomainId(), Op.IN);
|
||||
AccountIdsSearch.done();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
HostNameSearch.done();
|
||||
|
||||
FindIdsOfVirtualRoutersByAccount = createSearchBuilder(Long.class);
|
||||
FindIdsOfVirtualRoutersByAccount.selectField(FindIdsOfVirtualRoutersByAccount.entity().getId());
|
||||
FindIdsOfVirtualRoutersByAccount.selectFields(FindIdsOfVirtualRoutersByAccount.entity().getId());
|
||||
FindIdsOfVirtualRoutersByAccount.and("account", FindIdsOfVirtualRoutersByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
FindIdsOfVirtualRoutersByAccount.and("type", FindIdsOfVirtualRoutersByAccount.entity().getType(), SearchCriteria.Op.EQ);
|
||||
FindIdsOfVirtualRoutersByAccount.and("state", FindIdsOfVirtualRoutersByAccount.entity().getState(), SearchCriteria.Op.NIN);
|
||||
|
|
@ -233,7 +233,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
|
||||
DistinctHostNameSearch = createSearchBuilder(String.class);
|
||||
DistinctHostNameSearch.selectField(DistinctHostNameSearch.entity().getHostName());
|
||||
DistinctHostNameSearch.selectFields(DistinctHostNameSearch.entity().getHostName());
|
||||
|
||||
DistinctHostNameSearch.and("types", DistinctHostNameSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
DistinctHostNameSearch.and("removed", DistinctHostNameSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
|
|||
ListVmIdByAffinityGroup = createSearchBuilder(Long.class);
|
||||
ListVmIdByAffinityGroup.and("affinityGroupId", ListVmIdByAffinityGroup.entity().getAffinityGroupId(),
|
||||
SearchCriteria.Op.EQ);
|
||||
ListVmIdByAffinityGroup.selectField(ListVmIdByAffinityGroup.entity().getInstanceId());
|
||||
ListVmIdByAffinityGroup.selectFields(ListVmIdByAffinityGroup.entity().getInstanceId());
|
||||
ListVmIdByAffinityGroup.done();
|
||||
|
||||
ListByAffinityGroup = createSearchBuilder();
|
||||
|
|
@ -89,7 +89,7 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
|
|||
ListAffinityGroupIdByVm = createSearchBuilder(Long.class);
|
||||
ListAffinityGroupIdByVm.and("instanceId", ListAffinityGroupIdByVm.entity().getInstanceId(),
|
||||
SearchCriteria.Op.EQ);
|
||||
ListAffinityGroupIdByVm.selectField(ListAffinityGroupIdByVm.entity().getAffinityGroupId());
|
||||
ListAffinityGroupIdByVm.selectFields(ListAffinityGroupIdByVm.entity().getAffinityGroupId());
|
||||
ListAffinityGroupIdByVm.done();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,12 +35,11 @@ import com.cloud.storage.StoragePoolStatus;
|
|||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
|
|
@ -316,10 +315,10 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
|
|||
public List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags) {
|
||||
List<StoragePoolVO> storagePools = null;
|
||||
if (tags == null || tags.length == 0) {
|
||||
SearchCriteriaService<StoragePoolVO, StoragePoolVO> sc = SearchCriteria2.create(StoragePoolVO.class);
|
||||
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
|
||||
sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
|
||||
sc.addAnd(sc.getEntity().getScope(), Op.EQ, ScopeType.ZONE);
|
||||
QueryBuilder<StoragePoolVO> sc = QueryBuilder.create(StoragePoolVO.class);
|
||||
sc.and(sc.entity().getDataCenterId(), Op.EQ,dcId);
|
||||
sc.and(sc.entity().getStatus(), Op.EQ,Status.Up);
|
||||
sc.and(sc.entity().getScope(), Op.EQ,ScopeType.ZONE);
|
||||
return sc.list();
|
||||
} else {
|
||||
Map<String, String> details = tagsToDetails(tags);
|
||||
|
|
@ -421,11 +420,11 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
|
|||
|
||||
@Override
|
||||
public List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType) {
|
||||
SearchCriteriaService<StoragePoolVO, StoragePoolVO> sc = SearchCriteria2.create(StoragePoolVO.class);
|
||||
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dataCenterId);
|
||||
sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
|
||||
sc.addAnd(sc.getEntity().getScope(), Op.EQ, ScopeType.ZONE);
|
||||
sc.addAnd(sc.getEntity().getHypervisor(), Op.EQ, hypervisorType);
|
||||
QueryBuilder<StoragePoolVO> sc = QueryBuilder.create(StoragePoolVO.class);
|
||||
sc.and(sc.entity().getDataCenterId(), Op.EQ,dataCenterId);
|
||||
sc.and(sc.entity().getStatus(), Op.EQ,Status.Up);
|
||||
sc.and(sc.entity().getScope(), Op.EQ,ScopeType.ZONE);
|
||||
sc.and(sc.entity().getHypervisor(), Op.EQ,hypervisorType);
|
||||
return sc.list();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,35 +18,46 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.cache.manager;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.*;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.storage.cache.allocator.StorageCacheAllocator;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
||||
private static final Logger s_logger = Logger.getLogger(StorageCacheManagerImpl.class);
|
||||
|
|
@ -79,8 +90,8 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
|||
}
|
||||
|
||||
protected List<DataStore> getCacheStores() {
|
||||
SearchCriteriaService<ImageStoreVO, ImageStoreVO> sc = SearchCriteria2.create(ImageStoreVO.class);
|
||||
sc.addAnd(sc.getEntity().getRole(), SearchCriteria.Op.EQ, DataStoreRole.ImageCache);
|
||||
QueryBuilder<ImageStoreVO> sc = QueryBuilder.create(ImageStoreVO.class);
|
||||
sc.and(sc.entity().getRole(), SearchCriteria.Op.EQ,DataStoreRole.ImageCache);
|
||||
List<ImageStoreVO> imageStoreVOs = sc.list();
|
||||
List<DataStore> stores = new ArrayList<DataStore>();
|
||||
for (ImageStoreVO vo : imageStoreVOs) {
|
||||
|
|
@ -232,7 +243,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
|||
|
||||
@Override
|
||||
public DataObject createCacheObject(DataObject data, Scope scope) {
|
||||
DataStore cacheStore = this.getCacheStorage(scope);
|
||||
DataStore cacheStore = getCacheStorage(scope);
|
||||
|
||||
if (cacheStore == null)
|
||||
{
|
||||
|
|
@ -244,7 +255,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
|||
|
||||
@Override
|
||||
public DataObject getCacheObject(DataObject data, Scope scope) {
|
||||
DataStore cacheStore = this.getCacheStorage(scope);
|
||||
DataStore cacheStore = getCacheStorage(scope);
|
||||
DataObject objOnCacheStore = cacheStore.create(data);
|
||||
objOnCacheStore.incRefCount();
|
||||
return objOnCacheStore;
|
||||
|
|
|
|||
|
|
@ -17,27 +17,29 @@
|
|||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.cache.manager;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.*;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
|
||||
|
||||
public class StorageCacheReplacementAlgorithmLRU implements StorageCacheReplacementAlgorithm {
|
||||
|
|
@ -72,33 +74,33 @@ public class StorageCacheReplacementAlgorithmLRU implements StorageCacheReplacem
|
|||
cal.add(Calendar.DAY_OF_MONTH, -unusedTimeInterval.intValue());
|
||||
Date bef = cal.getTime();
|
||||
|
||||
SearchCriteriaService<TemplateDataStoreVO, TemplateDataStoreVO> sc = SearchCriteria2.create(TemplateDataStoreVO.class);
|
||||
sc.addAnd(sc.getEntity().getLastUpdated(), SearchCriteria.Op.LT, bef);
|
||||
sc.addAnd(sc.getEntity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
|
||||
sc.addAnd(sc.getEntity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
|
||||
sc.addAnd(sc.getEntity().getDataStoreRole(), SearchCriteria.Op.EQ, store.getRole());
|
||||
sc.addAnd(sc.getEntity().getRefCnt(), SearchCriteria.Op.EQ, 0);
|
||||
QueryBuilder<TemplateDataStoreVO> sc = QueryBuilder.create(TemplateDataStoreVO.class);
|
||||
sc.and(sc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
|
||||
sc.and(sc.entity().getState(), SearchCriteria.Op.EQ,ObjectInDataStoreStateMachine.State.Ready);
|
||||
sc.and(sc.entity().getDataStoreId(), SearchCriteria.Op.EQ,store.getId());
|
||||
sc.and(sc.entity().getDataStoreRole(), SearchCriteria.Op.EQ,store.getRole());
|
||||
sc.and(sc.entity().getRefCnt(), SearchCriteria.Op.EQ,0);
|
||||
TemplateDataStoreVO template = sc.find();
|
||||
if (template != null) {
|
||||
return templateFactory.getTemplate(template.getTemplateId(), store);
|
||||
}
|
||||
|
||||
SearchCriteriaService<VolumeDataStoreVO, VolumeDataStoreVO> volSc = SearchCriteria2.create(VolumeDataStoreVO.class);
|
||||
volSc.addAnd(volSc.getEntity().getLastUpdated(), SearchCriteria.Op.LT, bef);
|
||||
volSc.addAnd(volSc.getEntity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
|
||||
volSc.addAnd(volSc.getEntity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
|
||||
volSc.addAnd(volSc.getEntity().getRefCnt(), SearchCriteria.Op.EQ, 0);
|
||||
QueryBuilder<VolumeDataStoreVO> volSc = QueryBuilder.create(VolumeDataStoreVO.class);
|
||||
volSc.and(volSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
|
||||
volSc.and(volSc.entity().getState(), SearchCriteria.Op.EQ,ObjectInDataStoreStateMachine.State.Ready);
|
||||
volSc.and(volSc.entity().getDataStoreId(), SearchCriteria.Op.EQ,store.getId());
|
||||
volSc.and(volSc.entity().getRefCnt(), SearchCriteria.Op.EQ,0);
|
||||
VolumeDataStoreVO volume = volSc.find();
|
||||
if (volume != null) {
|
||||
return volumeFactory.getVolume(volume.getVolumeId(), store);
|
||||
}
|
||||
|
||||
SearchCriteriaService<SnapshotDataStoreVO, SnapshotDataStoreVO> snapshotSc = SearchCriteria2.create(SnapshotDataStoreVO.class);
|
||||
snapshotSc.addAnd(snapshotSc.getEntity().getLastUpdated(), SearchCriteria.Op.LT, bef);
|
||||
snapshotSc.addAnd(snapshotSc.getEntity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
|
||||
snapshotSc.addAnd(snapshotSc.getEntity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
|
||||
snapshotSc.addAnd(snapshotSc.getEntity().getRole(), SearchCriteria.Op.EQ, store.getRole());
|
||||
snapshotSc.addAnd(snapshotSc.getEntity().getRefCnt(), SearchCriteria.Op.EQ, 0);
|
||||
QueryBuilder<SnapshotDataStoreVO> snapshotSc = QueryBuilder.create(SnapshotDataStoreVO.class);
|
||||
snapshotSc.and(snapshotSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
|
||||
snapshotSc.and(snapshotSc.entity().getState(), SearchCriteria.Op.EQ,ObjectInDataStoreStateMachine.State.Ready);
|
||||
snapshotSc.and(snapshotSc.entity().getDataStoreId(), SearchCriteria.Op.EQ,store.getId());
|
||||
snapshotSc.and(snapshotSc.entity().getRole(), SearchCriteria.Op.EQ,store.getRole());
|
||||
snapshotSc.and(snapshotSc.entity().getRefCnt(), SearchCriteria.Op.EQ,0);
|
||||
SnapshotDataStoreVO snapshot = snapshotSc.find();
|
||||
if (snapshot != null) {
|
||||
return snapshotFactory.getSnapshot(snapshot.getSnapshotId(), store);
|
||||
|
|
|
|||
|
|
@ -22,14 +22,21 @@ import java.util.Date;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectAnswer;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.to.DataObjectType;
|
||||
|
|
@ -42,9 +49,8 @@ import com.cloud.storage.VolumeVO;
|
|||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
|
|
@ -83,19 +89,19 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
}
|
||||
|
||||
public DataStore getStore() {
|
||||
return this.store;
|
||||
return store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotInfo getParent() {
|
||||
|
||||
SnapshotDataStoreVO snapStoreVO = this.snapshotStoreDao.findByStoreSnapshot(this.store.getRole(),
|
||||
this.store.getId(), this.snapshot.getId());
|
||||
SnapshotDataStoreVO snapStoreVO = snapshotStoreDao.findByStoreSnapshot(store.getRole(),
|
||||
store.getId(), snapshot.getId());
|
||||
Long parentId = null;
|
||||
if (snapStoreVO != null) {
|
||||
parentId = snapStoreVO.getParentSnapshotId();
|
||||
if (parentId != null && parentId != 0) {
|
||||
return this.snapshotFactory.getSnapshot(parentId, store);
|
||||
return snapshotFactory.getSnapshot(parentId, store);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,42 +110,41 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public SnapshotInfo getChild() {
|
||||
SearchCriteriaService<SnapshotDataStoreVO, SnapshotDataStoreVO> sc = SearchCriteria2
|
||||
.create(SnapshotDataStoreVO.class);
|
||||
sc.addAnd(sc.getEntity().getDataStoreId(), Op.EQ, this.store.getId());
|
||||
sc.addAnd(sc.getEntity().getRole(), Op.EQ, this.store.getRole());
|
||||
sc.addAnd(sc.getEntity().getState(), Op.NIN, State.Destroying, State.Destroyed, State.Error);
|
||||
sc.addAnd(sc.getEntity().getParentSnapshotId(), Op.EQ, this.getId());
|
||||
QueryBuilder<SnapshotDataStoreVO> sc = QueryBuilder.create(SnapshotDataStoreVO.class);
|
||||
sc.and(sc.entity().getDataStoreId(), Op.EQ,store.getId());
|
||||
sc.and(sc.entity().getRole(), Op.EQ,store.getRole());
|
||||
sc.and(sc.entity().getState(), Op.NIN, State.Destroying, State.Destroyed, State.Error);
|
||||
sc.and(sc.entity().getParentSnapshotId(), Op.EQ,getId());
|
||||
SnapshotDataStoreVO vo = sc.find();
|
||||
if (vo == null) {
|
||||
return null;
|
||||
}
|
||||
return this.snapshotFactory.getSnapshot(vo.getId(), store);
|
||||
return snapshotFactory.getSnapshot(vo.getId(), store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeInfo getBaseVolume() {
|
||||
return volFactory.getVolume(this.snapshot.getVolumeId());
|
||||
return volFactory.getVolume(snapshot.getVolumeId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return this.snapshot.getId();
|
||||
return snapshot.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUri() {
|
||||
return this.snapshot.getUuid();
|
||||
return snapshot.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataStore getDataStore() {
|
||||
return this.store;
|
||||
return store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSize() {
|
||||
return this.snapshot.getSize();
|
||||
return snapshot.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -149,7 +154,7 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return this.snapshot.getUuid();
|
||||
return snapshot.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -168,17 +173,17 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
return this.snapshot.getAccountId();
|
||||
return snapshot.getAccountId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolumeId() {
|
||||
return this.snapshot.getVolumeId();
|
||||
return snapshot.getVolumeId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
DataObjectInStore objectInStore = this.objectInStoreMgr.findObject(this, getDataStore());
|
||||
DataObjectInStore objectInStore = objectInStoreMgr.findObject(this, getDataStore());
|
||||
if (objectInStore != null) {
|
||||
return objectInStore.getInstallPath();
|
||||
}
|
||||
|
|
@ -187,60 +192,60 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.snapshot.getName();
|
||||
return snapshot.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreated() {
|
||||
return this.snapshot.getCreated();
|
||||
return snapshot.getCreated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getRecurringType() {
|
||||
return this.snapshot.getRecurringType();
|
||||
return snapshot.getRecurringType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return this.snapshot.getState();
|
||||
return snapshot.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
return this.snapshot.getHypervisorType();
|
||||
return snapshot.getHypervisorType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecursive() {
|
||||
return this.snapshot.isRecursive();
|
||||
return snapshot.isRecursive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getsnapshotType() {
|
||||
return this.snapshot.getsnapshotType();
|
||||
return snapshot.getsnapshotType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDomainId() {
|
||||
return this.snapshot.getDomainId();
|
||||
return snapshot.getDomainId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDataCenterId() {
|
||||
return this.snapshot.getDataCenterId();
|
||||
return snapshot.getDataCenterId();
|
||||
}
|
||||
|
||||
public void processEvent(Snapshot.Event event) throws NoTransitionException {
|
||||
stateMachineMgr.processEvent(this.snapshot, event);
|
||||
stateMachineMgr.processEvent(snapshot, event);
|
||||
}
|
||||
|
||||
public SnapshotVO getSnapshotVO() {
|
||||
return this.snapshot;
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataTO getTO() {
|
||||
DataTO to = this.store.getDriver().getTO(this);
|
||||
DataTO to = store.getDriver().getTO(this);
|
||||
if (to == null) {
|
||||
return new SnapshotObjectTO(this);
|
||||
}
|
||||
|
|
@ -250,28 +255,28 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
@Override
|
||||
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
|
||||
try {
|
||||
SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(
|
||||
this.getDataStore().getRole(), this.getDataStore().getId(), this.getId());
|
||||
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(
|
||||
getDataStore().getRole(), getDataStore().getId(), getId());
|
||||
if (answer instanceof CreateObjectAnswer) {
|
||||
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CreateObjectAnswer) answer).getData();
|
||||
snapshotStore.setInstallPath(snapshotTO.getPath());
|
||||
this.snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
|
||||
snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
|
||||
} else if (answer instanceof CopyCmdAnswer) {
|
||||
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CopyCmdAnswer) answer).getNewData();
|
||||
snapshotStore.setInstallPath(snapshotTO.getPath());
|
||||
if (snapshotTO.getParentSnapshotPath() == null) {
|
||||
snapshotStore.setParentSnapshotId(0L);
|
||||
}
|
||||
this.snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
|
||||
snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
|
||||
|
||||
// update side-effect of snapshot operation
|
||||
if(snapshotTO.getVolume() != null && snapshotTO.getVolume().getPath() != null) {
|
||||
VolumeVO vol = this.volumeDao.findByUuid(snapshotTO.getVolume().getUuid());
|
||||
VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid());
|
||||
if(vol != null) {
|
||||
s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: "
|
||||
+ vol.getPath() + "->" + snapshotTO.getVolume().getPath());
|
||||
vol.setPath(snapshotTO.getVolume().getPath());
|
||||
this.volumeDao.update(vol.getId(), vol);
|
||||
volumeDao.update(vol.getId(), vol);
|
||||
} else {
|
||||
s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid());
|
||||
}
|
||||
|
|
@ -290,13 +295,13 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public void incRefCount() {
|
||||
if (this.store == null) {
|
||||
if (store == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.store.getRole() == DataStoreRole.Image || this.store.getRole() == DataStoreRole.ImageCache) {
|
||||
if (store.getRole() == DataStoreRole.Image || store.getRole() == DataStoreRole.ImageCache) {
|
||||
SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(),
|
||||
this.getId());
|
||||
getId());
|
||||
store.incrRefCnt();
|
||||
store.setLastUpdated(new Date());
|
||||
snapshotStoreDao.update(store.getId(), store);
|
||||
|
|
@ -305,12 +310,12 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public void decRefCount() {
|
||||
if (this.store == null) {
|
||||
if (store == null) {
|
||||
return;
|
||||
}
|
||||
if (this.store.getRole() == DataStoreRole.Image || this.store.getRole() == DataStoreRole.ImageCache) {
|
||||
if (store.getRole() == DataStoreRole.Image || store.getRole() == DataStoreRole.ImageCache) {
|
||||
SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(),
|
||||
this.getId());
|
||||
getId());
|
||||
store.decrRefCnt();
|
||||
store.setLastUpdated(new Date());
|
||||
snapshotStoreDao.update(store.getId(), store);
|
||||
|
|
@ -319,12 +324,12 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public Long getRefCount() {
|
||||
if (this.store == null) {
|
||||
if (store == null) {
|
||||
return null;
|
||||
}
|
||||
if (this.store.getRole() == DataStoreRole.Image || this.store.getRole() == DataStoreRole.ImageCache) {
|
||||
if (store.getRole() == DataStoreRole.Image || store.getRole() == DataStoreRole.ImageCache) {
|
||||
SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(),
|
||||
this.getId());
|
||||
getId());
|
||||
return store.getRefCnt();
|
||||
}
|
||||
return null;
|
||||
|
|
@ -332,7 +337,7 @@ public class SnapshotObject implements SnapshotInfo {
|
|||
|
||||
@Override
|
||||
public ObjectInDataStoreStateMachine.State getStatus() {
|
||||
return this.objectInStoreMgr.findObject(this, store).getObjectInStoreState();
|
||||
return objectInStoreMgr.findObject(this, store).getObjectInStoreState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,15 +27,16 @@ import java.util.List;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.storage.RemoteHostEndPoint;
|
||||
import org.apache.cloudstack.storage.LocalHostEndpoint;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.apache.cloudstack.storage.RemoteHostEndPoint;
|
||||
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
|
|
@ -44,10 +45,9 @@ import com.cloud.host.dao.HostDao;
|
|||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
|
|
@ -55,7 +55,7 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
|||
private static final Logger s_logger = Logger.getLogger(DefaultEndPointSelector.class);
|
||||
@Inject
|
||||
HostDao hostDao;
|
||||
private String findOneHostOnPrimaryStorage = "select h.id from host h, storage_pool_host_ref s where h.status = 'Up' and h.type = 'Routing' and h.resource_state = 'Enabled' and" +
|
||||
private final String findOneHostOnPrimaryStorage = "select h.id from host h, storage_pool_host_ref s where h.status = 'Up' and h.type = 'Routing' and h.resource_state = 'Enabled' and" +
|
||||
" h.id = s.host_id and s.pool_id = ? ";
|
||||
|
||||
protected boolean moveBetweenPrimaryImage(DataStore srcStore, DataStore destStore) {
|
||||
|
|
@ -220,12 +220,12 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
|||
}
|
||||
|
||||
private List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
if (dcId != null) {
|
||||
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
|
||||
sc.and(sc.entity().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);
|
||||
sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
|
||||
sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
|
||||
return sc.list();
|
||||
}
|
||||
|
||||
|
|
@ -258,10 +258,10 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
|||
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(),
|
||||
host.getPublicIpAddress()));
|
||||
} else if (store.getScope().getScopeType() == ScopeType.CLUSTER) {
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getClusterId(), Op.EQ, store.getScope().getScopeId());
|
||||
sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
|
||||
List<HostVO> hosts = sc.find();
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getClusterId(), Op.EQ, store.getScope().getScopeId());
|
||||
sc.and(sc.entity().getStatus(), Op.EQ, Status.Up);
|
||||
List<HostVO> hosts = sc.list();
|
||||
for (HostVO host : hosts) {
|
||||
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(),
|
||||
host.getPublicIpAddress()));
|
||||
|
|
|
|||
|
|
@ -20,18 +20,18 @@ package org.apache.cloudstack.storage.volume.db;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
|
||||
@Component
|
||||
|
|
@ -50,20 +50,18 @@ public class TemplatePrimaryDataStoreDaoImpl extends GenericDaoBase<TemplatePrim
|
|||
|
||||
@Override
|
||||
public TemplatePrimaryDataStoreVO findByTemplateIdAndPoolId(long templateId, long poolId) {
|
||||
SearchCriteriaService<TemplatePrimaryDataStoreVO, TemplatePrimaryDataStoreVO> sc = SearchCriteria2
|
||||
.create(TemplatePrimaryDataStoreVO.class);
|
||||
sc.addAnd(sc.getEntity().getTemplateId(), Op.EQ, templateId);
|
||||
sc.addAnd(sc.getEntity().getPoolId(), Op.EQ, poolId);
|
||||
QueryBuilder<TemplatePrimaryDataStoreVO> sc = QueryBuilder.create(TemplatePrimaryDataStoreVO.class);
|
||||
sc.and(sc.entity().getTemplateId(), Op.EQ, templateId);
|
||||
sc.and(sc.entity().getPoolId(), Op.EQ, poolId);
|
||||
return sc.find();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplatePrimaryDataStoreVO findByTemplateIdAndPoolIdAndReady(long templateId, long poolId) {
|
||||
SearchCriteriaService<TemplatePrimaryDataStoreVO, TemplatePrimaryDataStoreVO> sc = SearchCriteria2
|
||||
.create(TemplatePrimaryDataStoreVO.class);
|
||||
sc.addAnd(sc.getEntity().getTemplateId(), Op.EQ, templateId);
|
||||
sc.addAnd(sc.getEntity().getPoolId(), Op.EQ, poolId);
|
||||
sc.addAnd(sc.getEntity().getState(), Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
|
||||
QueryBuilder<TemplatePrimaryDataStoreVO> sc = QueryBuilder.create(TemplatePrimaryDataStoreVO.class);
|
||||
sc.and(sc.entity().getTemplateId(), Op.EQ, templateId);
|
||||
sc.and(sc.entity().getPoolId(), Op.EQ, poolId);
|
||||
sc.and(sc.entity().getState(), Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
|
||||
return sc.find();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ import javax.annotation.PostConstruct;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigDepot;
|
||||
import org.apache.cloudstack.framework.config.ConfigDepotAdmin;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.Configurable;
|
||||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||
|
|
@ -97,10 +97,8 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemInt
|
|||
_configDao.persist(vo);
|
||||
} else {
|
||||
if (vo.isDynamic() != key.isDynamic() ||
|
||||
!vo.getDescription().equals(key.description()) ||
|
||||
((vo.getDefaultValue() != null && key.defaultValue() == null) ||
|
||||
(vo.getDefaultValue() == null && key.defaultValue() != null) ||
|
||||
!vo.getDefaultValue().equals(key.defaultValue()))) {
|
||||
!ObjectUtils.equals(vo.getDescription(), key.description()) ||
|
||||
!ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue())) {
|
||||
vo.setDynamic(key.isDynamic());
|
||||
vo.setDescription(key.description());
|
||||
vo.setDefaultValue(key.defaultValue());
|
||||
|
|
|
|||
|
|
@ -258,10 +258,6 @@ public interface GenericDao<T, ID extends Serializable> {
|
|||
|
||||
public <K> K getRandomlyIncreasingNextInSequence(Class<K> clazz, String name);
|
||||
|
||||
<K> SearchCriteria2 createSearchCriteria2(Class<K> resultType);
|
||||
|
||||
SearchCriteria2 createSearchCriteria2();
|
||||
|
||||
public T findOneBy(final SearchCriteria<T> sc);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ import net.sf.cglib.proxy.Callback;
|
|||
import net.sf.cglib.proxy.CallbackFilter;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.Factory;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.NoOp;
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
|
|
@ -169,11 +170,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
@Override
|
||||
@SuppressWarnings("unchecked") @DB(txn=false)
|
||||
public <J> GenericSearchBuilder<T, J> createSearchBuilder(Class<J> resultType) {
|
||||
final T entity = (T)_searchEnhancer.create();
|
||||
final Factory factory = (Factory)entity;
|
||||
GenericSearchBuilder<T, J> builder = new GenericSearchBuilder<T, J>(entity, resultType, _allAttributes);
|
||||
factory.setCallback(0, builder);
|
||||
return builder;
|
||||
return new GenericSearchBuilder<T, J>(_entityBeanType, resultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -181,6 +178,15 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
return _allAttributes;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T createSearchEntity(MethodInterceptor interceptor) {
|
||||
T entity = (T)_searchEnhancer.create();
|
||||
final Factory factory = (Factory)entity;
|
||||
factory.setCallback(0, interceptor);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected GenericDaoBase() {
|
||||
super();
|
||||
|
|
@ -922,7 +928,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
@SuppressWarnings("unchecked")
|
||||
public T findByUuid(final String uuid) {
|
||||
SearchCriteria<T> sc = createSearchCriteria();
|
||||
sc.addAnd("uuid", SearchCriteria.Op.EQ, uuid);
|
||||
|
|
@ -930,7 +935,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
@SuppressWarnings("unchecked")
|
||||
public T findByUuidIncludingRemoved(final String uuid) {
|
||||
SearchCriteria<T> sc = createSearchCriteria();
|
||||
sc.addAnd("uuid", SearchCriteria.Op.EQ, uuid);
|
||||
|
|
@ -1038,7 +1042,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
|
||||
@DB(txn=false)
|
||||
protected List<Object> addGroupBy(final StringBuilder sql, SearchCriteria<?> sc) {
|
||||
Pair<GroupBy<?, ?>, List<Object>> groupBys = sc.getGroupBy();
|
||||
Pair<GroupBy<?, ?, ?>, List<Object>> groupBys = sc.getGroupBy();
|
||||
if (groupBys != null) {
|
||||
groupBys.first().toSql(sql);
|
||||
return groupBys.second();
|
||||
|
|
@ -1362,7 +1366,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
Object obj = entry.getValue();
|
||||
|
||||
EcInfo ec = (EcInfo)attr.attache;
|
||||
Enumeration en = null;
|
||||
Enumeration<?> en = null;
|
||||
if (ec.rawClass == null) {
|
||||
en = Collections.enumeration(Arrays.asList((Object[])obj));
|
||||
} else {
|
||||
|
|
@ -1781,14 +1785,9 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
return (UpdateBuilder)factory.getCallback(1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override @DB(txn=false)
|
||||
public SearchBuilder<T> createSearchBuilder() {
|
||||
final T entity = (T)_searchEnhancer.create();
|
||||
final Factory factory = (Factory)entity;
|
||||
SearchBuilder<T> builder = new SearchBuilder<T>(entity, _allAttributes);
|
||||
factory.setCallback(0, builder);
|
||||
return builder;
|
||||
return new SearchBuilder<T>(_entityBeanType);
|
||||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
|
|
@ -1797,24 +1796,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
return builder.create();
|
||||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
public <K> SearchCriteria2 createSearchCriteria2(Class<K> resultType) {
|
||||
final T entity = (T)_searchEnhancer.create();
|
||||
final Factory factory = (Factory)entity;
|
||||
SearchCriteria2 sc = new SearchCriteria2(entity, resultType, _allAttributes, this);
|
||||
factory.setCallback(0, sc);
|
||||
return sc;
|
||||
}
|
||||
|
||||
@Override @DB(txn=false)
|
||||
public SearchCriteria2 createSearchCriteria2() {
|
||||
final T entity = (T)_searchEnhancer.create();
|
||||
final Factory factory = (Factory)entity;
|
||||
SearchCriteria2 sc = new SearchCriteria2(entity, entity.getClass(), _allAttributes, this);
|
||||
factory.setCallback(0, sc);
|
||||
return sc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegionId(){
|
||||
return Transaction.s_region_id;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,176 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
||||
/**
|
||||
* GenericQueryBuilder builds a search query during runtime. It allows the
|
||||
* search query to be built completely in Java rather than part SQL fragments
|
||||
* and part entity field like HQL or JPQL. This class is different from
|
||||
* GenericSearchBuilder in that it is used for building queries during runtime
|
||||
* where GenericSearchBuilder expects the query to be built during load time
|
||||
* and parameterized values to be set during runtime.
|
||||
*
|
||||
* GenericQueryBuilder allows results to be a native type, the entity bean,
|
||||
* and a composite type. If you are just retrieving the entity bean, there
|
||||
* is a simpler class called QueryBuilder that you can use. The usage
|
||||
* is approximately the same.
|
||||
*
|
||||
* <code>
|
||||
* // Note that in the following search, it selects a func COUNT to be the
|
||||
* // return result so for the second parameterized type is long.
|
||||
* // Note the entity object itself must have came from search and
|
||||
* // it uses the getters of the object to retrieve the field used in the search.
|
||||
*
|
||||
* GenericQueryBuilder<HostVO, Long> sc = GenericQueryBuilder.create(HostVO.class, Long.class);
|
||||
* HostVO entity = CountSearch.entity();
|
||||
* sc.select(null, FUNC.COUNT, null, null).where(entity.getType(), Op.EQ, Host.Type.Routing);
|
||||
* sc.and(entity.getCreated(), Op.LT, new Date());
|
||||
* Long count = sc.find();
|
||||
*
|
||||
* </code> *
|
||||
*
|
||||
* @see GenericSearchBuilder
|
||||
* @see QueryBuilder
|
||||
*
|
||||
* @param <T> Entity object to perform the search on
|
||||
* @param <K> Result object
|
||||
*/
|
||||
public class GenericQueryBuilder<T, K> extends SearchBase<GenericQueryBuilder<T, K>, T, K> {
|
||||
final HashMap<String, Object[]> _params = new HashMap<String, Object[]>();
|
||||
|
||||
protected GenericQueryBuilder(Class<T> entityType, Class<K> resultType) {
|
||||
super(entityType, resultType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creator method for GenericQueryBuilder.
|
||||
* @param entityType Entity to search on
|
||||
* @param resultType Result to return
|
||||
* @return GenericQueryBuilder
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static public <T, K> GenericQueryBuilder<T, K> create(Class<T> entityType, Class<K> resultType) {
|
||||
GenericDao<T, ? extends Serializable> dao = (GenericDao<T, ? extends Serializable>)GenericDaoBase.getDao(entityType);
|
||||
assert dao != null : "Can not find DAO for " + entityType.getName();
|
||||
return new GenericQueryBuilder<T, K>(entityType, resultType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds AND search condition
|
||||
*
|
||||
* @param field the field of the entity to perform the search on.
|
||||
* @param op operator
|
||||
* @param values parameterized values
|
||||
* @return this
|
||||
*/
|
||||
public GenericQueryBuilder<T, K> and(Object field, Op op, Object... values) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
constructCondition(uuid, " AND ", _specifiedAttrs.get(0), op);
|
||||
_params.put(uuid, values);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds OR search condition
|
||||
*
|
||||
* @param field the field of the entity to perform the search on.
|
||||
* @param op operator
|
||||
* @param values parameterized values
|
||||
* @return this
|
||||
*/
|
||||
public GenericQueryBuilder<T, K> or(Object field, Op op, Object... values) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
constructCondition(uuid, " OR ", _specifiedAttrs.get(0), op);
|
||||
_params.put(uuid, values);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected GenericQueryBuilder<T, K> left(Object field, Op op, Object... values) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
constructCondition(uuid, " ( ", _specifiedAttrs.get(0), op);
|
||||
_params.put(uuid, values);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds search condition that starts with an open parenthesis. Call cp()
|
||||
* to close the parenthesis.
|
||||
*
|
||||
* @param field the field of the entity to perform the search on.
|
||||
* @param op operator
|
||||
* @param values parameterized values
|
||||
* @return this
|
||||
*/
|
||||
public GenericQueryBuilder<T, K> op(Object field, Op op, Object... values) {
|
||||
return left(field, op, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the query is supposed to return a list, use this.
|
||||
* @return List of result objects
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<K> list() {
|
||||
finalize();
|
||||
if (isSelectAll()) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
SearchCriteria sc1 = create();
|
||||
return (List<K>)_dao.search(sc1, null);
|
||||
} else {
|
||||
SearchCriteria<K> sc1 = create();
|
||||
return _dao.customSearch(sc1, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SearchCriteria to be used with dao objects.
|
||||
*/
|
||||
@Override
|
||||
public SearchCriteria<K> create() {
|
||||
SearchCriteria<K> sc = super.create();
|
||||
sc.setParameters(_params);
|
||||
return sc;
|
||||
}
|
||||
|
||||
private boolean isSelectAll() {
|
||||
return _selects == null || _selects.size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to find the result so the result won't be a list.
|
||||
* @return result as specified.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public K find() {
|
||||
finalize();
|
||||
if (isSelectAll()) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
SearchCriteria sc1 = create();
|
||||
return (K)_dao.findOneBy(sc1);
|
||||
} else {
|
||||
List<K> lst = list();
|
||||
return lst.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,516 +16,216 @@
|
|||
// under the License.
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import net.sf.cglib.proxy.Factory;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria.SelectType;
|
||||
|
||||
/**
|
||||
* GenericSearchBuilder is used to build a search based on a VO object
|
||||
* a convenience class provided called SearchBuilder that provides
|
||||
* exactly that functionality.
|
||||
* GenericSearchBuilder is used to build a search based on a VO object. It
|
||||
* can select the result into a native type, the entity object, or a composite
|
||||
* object depending on what's needed.
|
||||
*
|
||||
* The way to use GenericSearchBuilder is to use it to build a search at load
|
||||
* time so it should be declared at class constructions. It allows queries to
|
||||
* be constructed completely in Java and parameters have String tokens that
|
||||
* can be replaced during runtime with SearchCriteria. Because
|
||||
* GenericSearchBuilder is created at load time and SearchCriteria is used
|
||||
* at runtime, the search query creation and the parameter value setting are
|
||||
* separated in the code. While that's tougher on the coder to maintain, what
|
||||
* you gain is that all string constructions are done at load time rather than
|
||||
* runtime and, more importantly, the proper construction can be checked when
|
||||
* components are being loaded. However, if you prefer to just construct
|
||||
* the entire search at runtime, you can use GenericQueryBuilder.
|
||||
*
|
||||
* <code>
|
||||
* // To specify the GenericSearchBuilder, you should do this at load time.
|
||||
* // Note that in the following search, it selects a func COUNT to be the
|
||||
* // return result so for the second parameterized type is long. It also
|
||||
* // presets the type in the search and declares created to be set during
|
||||
* // runtime. Note the entity object itself must have came from search and
|
||||
* // it uses the getters of the object to retrieve the field used in the search.
|
||||
*
|
||||
* GenericSearchBuilder<HostVO, Long> CountSearch = _hostDao.createSearchBuilder(Long.class);
|
||||
* HostVO entity = CountSearch.entity();
|
||||
* CountSearch.select(null, FUNC.COUNT, null, null).where(entity.getType(), Op.EQ).value(Host.Type.Routing);
|
||||
* CountSearch.and(entity.getCreated(), Op.LT, "create_date").done();
|
||||
*
|
||||
* // Later in the code during runtime
|
||||
* SearchCriteria<Long> sc = CountSearch.create();
|
||||
* sc.setParameter("create_date", new Date());
|
||||
* Long count = _hostDao.customizedSearch(sc, null);
|
||||
* </code>
|
||||
*
|
||||
* @see GenericQueryBuilder for runtime construction of search query
|
||||
* @see SearchBuilder for returning VO objects itself
|
||||
*
|
||||
* @param <T> VO object this Search is build for.
|
||||
* @param <K> Result object that should contain the results.
|
||||
*/
|
||||
public class GenericSearchBuilder<T, K> implements MethodInterceptor {
|
||||
final protected Map<String, Attribute> _attrs;
|
||||
|
||||
protected ArrayList<Condition> _conditions;
|
||||
protected HashMap<String, JoinBuilder<GenericSearchBuilder<?, ?>>> _joins;
|
||||
protected ArrayList<Select> _selects;
|
||||
protected GroupBy<T, K> _groupBy = null;
|
||||
protected Class<T> _entityBeanType;
|
||||
protected Class<K> _resultType;
|
||||
protected SelectType _selectType;
|
||||
|
||||
protected T _entity;
|
||||
protected ArrayList<Attribute> _specifiedAttrs;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected GenericSearchBuilder(T entity, Class<K> clazz, Map<String, Attribute> attrs) {
|
||||
_entityBeanType = (Class<T>)entity.getClass();
|
||||
_resultType = clazz;
|
||||
|
||||
_attrs = attrs;
|
||||
_entity = entity;
|
||||
_conditions = new ArrayList<Condition>();
|
||||
_joins = null;
|
||||
_specifiedAttrs = new ArrayList<Attribute>();
|
||||
public class GenericSearchBuilder<T, K> extends SearchBase<GenericSearchBuilder<T, K>, T, K> {
|
||||
protected GenericSearchBuilder(Class<T> entityType, Class<K> resultType) {
|
||||
super(entityType, resultType);
|
||||
}
|
||||
|
||||
public T entity() {
|
||||
return _entity;
|
||||
}
|
||||
|
||||
protected Attribute getSpecifiedAttribute() {
|
||||
if (_entity == null || _specifiedAttrs == null || _specifiedAttrs.size() != 1) {
|
||||
throw new RuntimeException("Now now, better specify an attribute or else we can't help you");
|
||||
}
|
||||
return _specifiedAttrs.get(0);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> selectField(Object... useless) {
|
||||
if (_entity == null) {
|
||||
throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
|
||||
}
|
||||
if (_specifiedAttrs.size() <= 0) {
|
||||
throw new RuntimeException("You didn't specify any attributes");
|
||||
}
|
||||
|
||||
if (_selects == null) {
|
||||
_selects = new ArrayList<Select>();
|
||||
}
|
||||
|
||||
for (Attribute attr : _specifiedAttrs) {
|
||||
Field field = null;
|
||||
try {
|
||||
field = _resultType.getDeclaredField(attr.field.getName());
|
||||
field.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
} catch (NoSuchFieldException e) {
|
||||
}
|
||||
_selects.add(new Select(Func.NATIVE, attr, field, null));
|
||||
}
|
||||
|
||||
_specifiedAttrs.clear();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// public GenericSearchBuilder<T, K> selectField(String joinName, Object... entityFields) {
|
||||
// JoinBuilder<GenericSearchBuilder<?, ?>> jb = _joins.get(joinName);
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* Specifies the field to select.
|
||||
*
|
||||
* @param fieldName The field name of the result object to put the value of the field selected. This can be null if you're selecting only one field and the result is not a complex object.
|
||||
* @param func function to place.
|
||||
* @param useless column to select. Call this with this.entity() method.
|
||||
* @param params parameters to the function.
|
||||
* @return a SearchBuilder to build more search parts.
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> select(String fieldName, Func func, Object useless, Object... params) {
|
||||
if (_entity == null) {
|
||||
throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
|
||||
}
|
||||
if (_specifiedAttrs.size() > 1) {
|
||||
throw new RuntimeException("You can't specify more than one field to search on");
|
||||
}
|
||||
if (func.getCount() != -1 && (func.getCount() != (params.length + 1))) {
|
||||
throw new RuntimeException("The number of parameters does not match the function param count for " + func);
|
||||
}
|
||||
|
||||
if (_selects == null) {
|
||||
_selects = new ArrayList<Select>();
|
||||
}
|
||||
|
||||
Field field = null;
|
||||
if (fieldName != null) {
|
||||
try {
|
||||
field = _resultType.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
throw new RuntimeException("Unable to find " + fieldName, e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException("Unable to find " + fieldName, e);
|
||||
}
|
||||
} else {
|
||||
if (_selects.size() != 0) {
|
||||
throw new RuntimeException(
|
||||
"You're selecting more than one item and yet is not providing a container class to put these items in. So what do you expect me to do. Spin magic?");
|
||||
}
|
||||
}
|
||||
|
||||
Select select = new Select(func, _specifiedAttrs.size() == 0 ? null : _specifiedAttrs.get(0), field, params);
|
||||
_selects.add(select);
|
||||
|
||||
_specifiedAttrs.clear();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
String name = method.getName();
|
||||
if (method.getAnnotation(Transient.class) == null) {
|
||||
if (name.startsWith("get")) {
|
||||
String fieldName = Character.toLowerCase(name.charAt(3)) + name.substring(4);
|
||||
set(fieldName);
|
||||
return null;
|
||||
} else if (name.startsWith("is")) {
|
||||
String fieldName = Character.toLowerCase(name.charAt(2)) + name.substring(3);
|
||||
set(fieldName);
|
||||
return null;
|
||||
} else {
|
||||
Column ann = method.getAnnotation(Column.class);
|
||||
if (ann != null) {
|
||||
String colName = ann.name();
|
||||
for (Map.Entry<String, Attribute> attr : _attrs.entrySet()) {
|
||||
if (colName.equals(attr.getValue().columnName)) {
|
||||
set(attr.getKey());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Perhaps you need to make the method start with get or is: " + method);
|
||||
}
|
||||
}
|
||||
return methodProxy.invokeSuper(object, args);
|
||||
}
|
||||
|
||||
protected void set(String name) {
|
||||
Attribute attr = _attrs.get(name);
|
||||
assert (attr != null) : "Searching for a field that's not there: " + name;
|
||||
_specifiedAttrs.add(attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an AND condition to the SearchBuilder.
|
||||
*
|
||||
* @param name param name you will use later to set the values in this search condition.
|
||||
* @param useless SearchBuilder.entity().get*() which refers to the field that you're searching on.
|
||||
* @param field SearchBuilder.entity().get*() which refers to the field that you're searching on.
|
||||
* @param op operation to apply to the field.
|
||||
* @return this
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> and(String name, Object useless, Op op) {
|
||||
public GenericSearchBuilder<T, K> and(String name, Object field, Op op) {
|
||||
constructCondition(name, " AND ", _specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> and(Object useless, Op op, String name) {
|
||||
/**
|
||||
* Adds an AND condition. Some prefer this method because it looks like
|
||||
* the actual SQL query.
|
||||
*
|
||||
* @param field field of entity object
|
||||
* @param op operator of the search condition
|
||||
* @param name param name used to later to set parameter value
|
||||
* @return this
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> and(Object field, Op op, String name) {
|
||||
constructCondition(name, " AND ", _specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Preset and(Object useless, Op op) {
|
||||
/**
|
||||
* Adds an AND condition but allows for a preset value to be set for this conditio.
|
||||
*
|
||||
* @param field field of the entity object
|
||||
* @param op operator of the search condition
|
||||
* @return Preset which allows you to set the values
|
||||
*/
|
||||
public Preset and(Object field, Op op) {
|
||||
Condition condition = constructCondition(UUID.randomUUID().toString(), " AND ", _specifiedAttrs.get(0), op);
|
||||
return new Preset(this, condition);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> and() {
|
||||
constructCondition(null, " AND ", null, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> where() {
|
||||
return and();
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> or() {
|
||||
constructCondition(null, " OR ", null, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> where(String name, Object useless, Op op) {
|
||||
return and(name, useless, op);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> where(Object useless, Op op, String name) {
|
||||
return and(name, useless, op);
|
||||
/**
|
||||
* Starts the search
|
||||
*
|
||||
* @param field field of the entity object
|
||||
* @param op operator
|
||||
* @param name param name to refer to the value later.
|
||||
* @return this
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> where(Object field, Op op, String name) {
|
||||
return and(name, field, op);
|
||||
}
|
||||
|
||||
public Preset where(Object useless, Op op) {
|
||||
return and(useless, op);
|
||||
/**
|
||||
* Starts the search but the value is already set during construction.
|
||||
*
|
||||
* @param field field of the entity object
|
||||
* @param op operator of the search condition
|
||||
* @return Preset which allows you to set the values
|
||||
*/
|
||||
public Preset where(Object field, Op op) {
|
||||
return and(field, op);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> left(String name, Object useless, Op op) {
|
||||
constructCondition(name, " ( ", _specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> left(Object useless, Op op, String name) {
|
||||
protected GenericSearchBuilder<T, K> left(Object field, Op op, String name) {
|
||||
constructCondition(name, " ( ", _specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Preset left(Object useless, Op op) {
|
||||
protected Preset left(Object field, Op op) {
|
||||
Condition condition = constructCondition(UUID.randomUUID().toString(), " ( ", _specifiedAttrs.get(0), op);
|
||||
return new Preset(this, condition);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> op(Object useless, Op op, String name) {
|
||||
return left(useless, op, name);
|
||||
/**
|
||||
* Adds an condition that starts with open parenthesis. Use cp() to close
|
||||
* the parenthesis.
|
||||
*
|
||||
* @param field field of the entity object
|
||||
* @param op operator
|
||||
* @param name parameter name used to set the value later
|
||||
* @return this
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> op(Object field, Op op, String name) {
|
||||
return left(field, op, name);
|
||||
}
|
||||
|
||||
public Preset op(Object useless, Op op) {
|
||||
return left(useless, op);
|
||||
public Preset op(Object field, Op op) {
|
||||
return left(field, op);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> op(String name, Object useless, Op op) {
|
||||
return left(name, useless, op);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> openParen(Object useless, Op op, String name) {
|
||||
return left(name, useless, op);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> openParen(String name, Object useless, Op op) {
|
||||
return left(name, useless, op);
|
||||
}
|
||||
|
||||
public Preset openParen(Object useless, Op op) {
|
||||
return left(useless, op);
|
||||
}
|
||||
|
||||
public GroupBy<T, K> groupBy(Object... useless) {
|
||||
assert _groupBy == null : "Can't do more than one group bys";
|
||||
_groupBy = new GroupBy<T, K>(this);
|
||||
|
||||
return _groupBy;
|
||||
}
|
||||
|
||||
protected List<Attribute> getSpecifiedAttributes() {
|
||||
return _specifiedAttrs;
|
||||
/**
|
||||
* Adds an condition that starts with open parenthesis. Use cp() to close
|
||||
* the parenthesis.
|
||||
*
|
||||
* @param name parameter name used to set the parameter value later.
|
||||
* @param field field of the entity object
|
||||
* @param op operator
|
||||
* @return this
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> op(String name, Object field, Op op) {
|
||||
return left(field, op, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an OR condition to the SearchBuilder.
|
||||
*
|
||||
* @param name param name you will use later to set the values in this search condition.
|
||||
* @param useless SearchBuilder.entity().get*() which refers to the field that you're searching on.
|
||||
* @param field SearchBuilder.entity().get*() which refers to the field that you're searching on.
|
||||
* @param op operation to apply to the field.
|
||||
* @return this
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> or(String name, Object useless, Op op) {
|
||||
public GenericSearchBuilder<T, K> or(String name, Object field, Op op) {
|
||||
constructCondition(name, " OR ", _specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> or(Object useless, Op op, String name) {
|
||||
/**
|
||||
* Adds an OR condition
|
||||
*
|
||||
* @param field field of the entity object
|
||||
* @param op operator
|
||||
* @param name parameter name
|
||||
* @return this
|
||||
*/
|
||||
public GenericSearchBuilder<T, K> or(Object field, Op op, String name) {
|
||||
constructCondition(name, " OR ", _specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Preset or(Object useless, Op op) {
|
||||
/**
|
||||
* Adds an OR condition but the values can be preset
|
||||
*
|
||||
* @param field field of the entity object
|
||||
* @param op operator
|
||||
* @return Preset
|
||||
*/
|
||||
public Preset or(Object field, Op op) {
|
||||
Condition condition = constructCondition(UUID.randomUUID().toString(), " OR ", _specifiedAttrs.get(0), op);
|
||||
return new Preset(this, condition);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> join(String name, GenericSearchBuilder<?, ?> builder, Object useless, Object useless2, JoinBuilder.JoinType joinType) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert builder._entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert builder._specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert builder != this : "You can't add yourself, can you? Really think about it!";
|
||||
|
||||
JoinBuilder<GenericSearchBuilder<?, ?>> t = new JoinBuilder<GenericSearchBuilder<?, ?>>(builder, _specifiedAttrs.get(0), builder._specifiedAttrs.get(0), joinType);
|
||||
if (_joins == null) {
|
||||
_joins = new HashMap<String, JoinBuilder<GenericSearchBuilder<?, ?>>>();
|
||||
}
|
||||
_joins.put(name, t);
|
||||
|
||||
builder._specifiedAttrs.clear();
|
||||
_specifiedAttrs.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Condition constructCondition(String conditionName, String cond, Attribute attr, Op op) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert op == null || _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert op != Op.SC : "Call join";
|
||||
|
||||
Condition condition = new Condition(conditionName, cond, attr, op);
|
||||
_conditions.add(condition);
|
||||
_specifiedAttrs.clear();
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the SearchCriteria so the actual values can be filled in.
|
||||
* Convenience method to create the search criteria and set a
|
||||
* parameter in the search.
|
||||
*
|
||||
* @param name parameter name set during construction
|
||||
* @param values values to be inserted for that parameter
|
||||
* @return SearchCriteria
|
||||
*/
|
||||
public SearchCriteria<K> create() {
|
||||
if (_entity != null) {
|
||||
done();
|
||||
}
|
||||
return new SearchCriteria<K>(this);
|
||||
}
|
||||
|
||||
public SearchCriteria<K> create(String name, Object... values) {
|
||||
SearchCriteria<K> sc = create();
|
||||
sc.setParameters(name, values);
|
||||
return sc;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> right() {
|
||||
Condition condition = new Condition("rp", " ) ", null, Op.RP);
|
||||
_conditions.add(condition);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> cp() {
|
||||
return right();
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> closeParen() {
|
||||
return right();
|
||||
}
|
||||
|
||||
public SelectType getSelectType() {
|
||||
return _selectType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the SearchBuilder as completed in building the search conditions.
|
||||
*/
|
||||
public synchronized void done() {
|
||||
if (_entity != null) {
|
||||
Factory factory = (Factory)_entity;
|
||||
factory.setCallback(0, null);
|
||||
_entity = null;
|
||||
}
|
||||
|
||||
if (_joins != null) {
|
||||
for (JoinBuilder<GenericSearchBuilder<?, ?>> join : _joins.values()) {
|
||||
join.getT().done();
|
||||
}
|
||||
}
|
||||
|
||||
if (_selects == null || _selects.size() == 0) {
|
||||
_selectType = SelectType.Entity;
|
||||
assert _entityBeanType.equals(_resultType) : "Expecting " + _entityBeanType + " because you didn't specify any selects but instead got " + _resultType;
|
||||
return;
|
||||
}
|
||||
|
||||
for (Select select : _selects) {
|
||||
if (select.field == null) {
|
||||
assert (_selects.size() == 1) : "You didn't specify any fields to put the result in but you're specifying more than one select so where should I put the selects?";
|
||||
_selectType = SelectType.Single;
|
||||
return;
|
||||
}
|
||||
if (select.func != null) {
|
||||
_selectType = SelectType.Result;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_selectType = SelectType.Fields;
|
||||
}
|
||||
|
||||
protected static class Condition {
|
||||
protected final String name;
|
||||
protected final String cond;
|
||||
protected final Op op;
|
||||
protected final Attribute attr;
|
||||
protected Object[] presets;
|
||||
|
||||
protected Condition(String name) {
|
||||
this(name, null, null, null);
|
||||
}
|
||||
|
||||
public Condition(String name, String cond, Attribute attr, Op op) {
|
||||
this.name = name;
|
||||
this.attr = attr;
|
||||
this.cond = cond;
|
||||
this.op = op;
|
||||
this.presets = null;
|
||||
}
|
||||
|
||||
public boolean isPreset() {
|
||||
return presets != null;
|
||||
}
|
||||
|
||||
public void setPresets(Object... presets) {
|
||||
this.presets = presets;
|
||||
}
|
||||
|
||||
public Object[] getPresets() {
|
||||
return presets;
|
||||
}
|
||||
|
||||
public void toSql(StringBuilder sql, Object[] params, int count) {
|
||||
if (count > 0) {
|
||||
sql.append(cond);
|
||||
}
|
||||
|
||||
if (op == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (op == Op.SC) {
|
||||
sql.append(" (").append(((SearchCriteria<?>)params[0]).getWhereClause()).append(") ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (attr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
sql.append(attr.table).append(".").append(attr.columnName).append(op.toString());
|
||||
if (op == Op.IN && params.length == 1) {
|
||||
sql.delete(sql.length() - op.toString().length(), sql.length());
|
||||
sql.append("=?");
|
||||
} else if (op == Op.NIN && params.length == 1) {
|
||||
sql.delete(sql.length() - op.toString().length(), sql.length());
|
||||
sql.append("!=?");
|
||||
} else if (op.getParams() == -1) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
sql.insert(sql.length() - 2, "?,");
|
||||
}
|
||||
sql.delete(sql.length() - 3, sql.length() - 2); // remove the last ,
|
||||
} else if (op == Op.EQ && (params == null || params.length == 0 || params[0] == null)) {
|
||||
sql.delete(sql.length() - 4, sql.length());
|
||||
sql.append(" IS NULL ");
|
||||
} else if (op == Op.NEQ && (params == null || params.length == 0 || params[0] == null)) {
|
||||
sql.delete(sql.length() - 5, sql.length());
|
||||
sql.append(" IS NOT NULL ");
|
||||
} else {
|
||||
if ((op.getParams() != 0 || params != null) && (params.length != op.getParams())) {
|
||||
throw new RuntimeException("Problem with condition: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Condition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Condition condition = (Condition)obj;
|
||||
return name.equals(condition.name);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class Select {
|
||||
public Func func;
|
||||
public Attribute attr;
|
||||
public Object[] params;
|
||||
public Field field;
|
||||
|
||||
protected Select() {
|
||||
}
|
||||
|
||||
public Select(Func func, Attribute attr, Field field, Object[] params) {
|
||||
this.func = func;
|
||||
this.attr = attr;
|
||||
this.params = params;
|
||||
this.field = field;
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
public class Preset {
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ import com.cloud.utils.Pair;
|
|||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
||||
public class GroupBy<T, R> {
|
||||
GenericSearchBuilder<T, R> _builder;
|
||||
public class GroupBy<J extends SearchBase<?, T, R>, T, R> {
|
||||
J _builder;
|
||||
List<Pair<Func, Attribute>> _groupBys;
|
||||
Having _having;
|
||||
|
||||
public GroupBy(GenericSearchBuilder<T, R> builder) {
|
||||
public GroupBy(J builder) {
|
||||
_builder = builder;
|
||||
_groupBys = new ArrayList<Pair<Func, Attribute>>();
|
||||
_having = null;
|
||||
|
|
@ -38,19 +38,19 @@ public class GroupBy<T, R> {
|
|||
_builder.getSpecifiedAttributes().clear();
|
||||
}
|
||||
|
||||
public GroupBy<T, R> group(Object useless) {
|
||||
public GroupBy<J, T, R> group(Object useless) {
|
||||
_groupBys.add(new Pair<Func, Attribute>(null, _builder.getSpecifiedAttributes().get(0)));
|
||||
_builder.getSpecifiedAttributes().clear();
|
||||
return this;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GroupBy<T, R> group(Func func, Object useless) {
|
||||
public GroupBy<J, T, R> group(Func func, Object useless) {
|
||||
_groupBys.add(new Pair<Func, Attribute>(func, _builder.getSpecifiedAttributes().get(0)));
|
||||
_builder.getSpecifiedAttributes().clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, R> having(Func func, Object obj, Op op, Object value) {
|
||||
public J having(Func func, Object obj, Op op, Object value) {
|
||||
assert(_having == null) : "You can only specify one having in a group by";
|
||||
List<Attribute> attrs = _builder.getSpecifiedAttributes();
|
||||
assert attrs.size() == 1 : "You didn't specified an attribute";
|
||||
|
|
|
|||
|
|
@ -16,64 +16,65 @@
|
|||
// under the License.
|
||||
package com.cloud.utils.db;
|
||||
|
||||
|
||||
public class JoinBuilder<T> {
|
||||
|
||||
public enum JoinType {
|
||||
INNER ("INNER JOIN"),
|
||||
LEFT ("LEFT JOIN"),
|
||||
RIGHT ("RIGHT JOIN"),
|
||||
RIGHTOUTER ("RIGHT OUTER JOIN"),
|
||||
LEFTOUTER ("LEFT OUTER JOIN");
|
||||
|
||||
private final String _name;
|
||||
|
||||
JoinType(String name) {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public String getName() { return _name; }
|
||||
}
|
||||
|
||||
|
||||
private T t;
|
||||
private JoinType type;
|
||||
private Attribute firstAttribute;
|
||||
private Attribute secondAttribute;
|
||||
|
||||
public JoinBuilder(T t, Attribute firstAttribute,
|
||||
Attribute secondAttribute, JoinType type) {
|
||||
this.t = t;
|
||||
this.firstAttribute = firstAttribute;
|
||||
this.secondAttribute = secondAttribute;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public T getT() {
|
||||
return t;
|
||||
}
|
||||
public void setT(T t) {
|
||||
this.t = t;
|
||||
}
|
||||
public JoinType getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(JoinType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public Attribute getFirstAttribute() {
|
||||
return firstAttribute;
|
||||
}
|
||||
public void setFirstAttribute(Attribute firstAttribute) {
|
||||
this.firstAttribute = firstAttribute;
|
||||
}
|
||||
public Attribute getSecondAttribute() {
|
||||
return secondAttribute;
|
||||
}
|
||||
public void setSecondAttribute(Attribute secondAttribute) {
|
||||
this.secondAttribute = secondAttribute;
|
||||
}
|
||||
public enum JoinType {
|
||||
INNER("INNER JOIN"),
|
||||
LEFT("LEFT JOIN"),
|
||||
RIGHT("RIGHT JOIN"),
|
||||
RIGHTOUTER("RIGHT OUTER JOIN"),
|
||||
LEFTOUTER("LEFT OUTER JOIN");
|
||||
|
||||
private final String _name;
|
||||
|
||||
JoinType(String name) {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
private final T t;
|
||||
private JoinType type;
|
||||
private Attribute firstAttribute;
|
||||
private Attribute secondAttribute;
|
||||
|
||||
public JoinBuilder(T t, Attribute firstAttribute,
|
||||
Attribute secondAttribute, JoinType type) {
|
||||
this.t = t;
|
||||
this.firstAttribute = firstAttribute;
|
||||
this.secondAttribute = secondAttribute;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public T getT() {
|
||||
return t;
|
||||
}
|
||||
|
||||
public JoinType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(JoinType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Attribute getFirstAttribute() {
|
||||
return firstAttribute;
|
||||
}
|
||||
|
||||
public void setFirstAttribute(Attribute firstAttribute) {
|
||||
this.firstAttribute = firstAttribute;
|
||||
}
|
||||
|
||||
public Attribute getSecondAttribute() {
|
||||
return secondAttribute;
|
||||
}
|
||||
|
||||
public void setSecondAttribute(Attribute secondAttribute) {
|
||||
this.secondAttribute = secondAttribute;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
20
framework/db/src/com/cloud/utils/db/SearchCriteriaService.java → framework/db/src/com/cloud/utils/db/QueryBuilder.java
Executable file → Normal file
20
framework/db/src/com/cloud/utils/db/SearchCriteriaService.java → framework/db/src/com/cloud/utils/db/QueryBuilder.java
Executable file → Normal file
|
|
@ -4,9 +4,9 @@
|
|||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// the License. You may obtain a copy of the License at
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
|
|
@ -16,14 +16,14 @@
|
|||
// under the License.
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.util.List;
|
||||
public class QueryBuilder<T> extends GenericQueryBuilder<T, T> {
|
||||
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
public static <T> QueryBuilder<T> create(Class<T> entityType) {
|
||||
return new QueryBuilder<T>(entityType);
|
||||
}
|
||||
|
||||
protected QueryBuilder(Class<T> entityType) {
|
||||
super(entityType, entityType);
|
||||
}
|
||||
|
||||
public interface SearchCriteriaService<T, K> {
|
||||
public void selectField(Object... useless);
|
||||
public void addAnd(Object useless, Op op, Object...values);
|
||||
public List<K> list();
|
||||
public T getEntity();
|
||||
public <K> K find();
|
||||
}
|
||||
|
|
@ -0,0 +1,499 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import net.sf.cglib.proxy.Factory;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria.SelectType;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
* SearchBase contains the methods that are used to build up search
|
||||
* queries. While this class is public it's not really meant for public
|
||||
* consumption. Unfortunately, it has to be public for methods to be mocked.
|
||||
*
|
||||
* @see GenericSearchBuilder
|
||||
* @see GenericQueryBuilder
|
||||
*
|
||||
* @param <J> Child class that inherited from SearchBase
|
||||
* @param <T> Entity Type to perform the searches on
|
||||
* @param <K> Type to place the search results. This can be a native type,
|
||||
* composite object, or the entity type itself.
|
||||
*/
|
||||
public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
||||
|
||||
final Map<String, Attribute> _attrs;
|
||||
final Class<T> _entityBeanType;
|
||||
final Class<K> _resultType;
|
||||
final GenericDaoBase<? extends T, ? extends Serializable> _dao;
|
||||
|
||||
final ArrayList<Condition> _conditions;
|
||||
final ArrayList<Attribute> _specifiedAttrs;
|
||||
|
||||
protected HashMap<String, JoinBuilder<SearchBase<?, ?, ?>>> _joins;
|
||||
protected ArrayList<Select> _selects;
|
||||
protected GroupBy<J, T, K> _groupBy = null;
|
||||
protected SelectType _selectType;
|
||||
T _entity;
|
||||
|
||||
SearchBase(Class<T> entityType, Class<K> resultType) {
|
||||
_dao = (GenericDaoBase<? extends T, ? extends Serializable>)GenericDaoBase.getDao(entityType);
|
||||
if (_dao == null) {
|
||||
throw new CloudRuntimeException("Unable to find DAO for " + entityType);
|
||||
}
|
||||
|
||||
_entityBeanType = entityType;
|
||||
_resultType = resultType;
|
||||
_attrs = _dao.getAllAttributes();
|
||||
|
||||
_entity = _dao.createSearchEntity(new Interceptor());
|
||||
_conditions = new ArrayList<Condition>();
|
||||
_joins = null;
|
||||
_specifiedAttrs = new ArrayList<Attribute>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies how the search query should be grouped
|
||||
*
|
||||
* @param fields fields of the entity object that should be grouped on. The order is important.
|
||||
* @return GroupBy object to perform more operations on.
|
||||
* @see GroupBy
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public GroupBy<J, T, K> groupBy(Object... fields) {
|
||||
assert _groupBy == null : "Can't do more than one group bys";
|
||||
_groupBy = new GroupBy<J, T, K>((J)this);
|
||||
return _groupBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies what to select in the search.
|
||||
*
|
||||
* @param fieldName The field name of the result object to put the value of the field selected. This can be null if you're selecting only one field and the result is not a complex object.
|
||||
* @param func function to place.
|
||||
* @param field column to select. Call this with this.entity() method.
|
||||
* @param params parameters to the function.
|
||||
* @return itself to build more search parts.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J select(String fieldName, Func func, Object field, Object... params) {
|
||||
if (_entity == null) {
|
||||
throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
|
||||
}
|
||||
if (_specifiedAttrs.size() > 1) {
|
||||
throw new RuntimeException("You can't specify more than one field to search on");
|
||||
}
|
||||
if (func.getCount() != -1 && (func.getCount() != (params.length + 1))) {
|
||||
throw new RuntimeException("The number of parameters does not match the function param count for " + func);
|
||||
}
|
||||
|
||||
if (_selects == null) {
|
||||
_selects = new ArrayList<Select>();
|
||||
}
|
||||
|
||||
Field declaredField = null;
|
||||
if (fieldName != null) {
|
||||
try {
|
||||
declaredField = _resultType.getDeclaredField(fieldName);
|
||||
declaredField.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
throw new RuntimeException("Unable to find " + fieldName, e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException("Unable to find " + fieldName, e);
|
||||
}
|
||||
} else {
|
||||
if (_selects.size() != 0) {
|
||||
throw new RuntimeException(
|
||||
"You're selecting more than one item and yet is not providing a container class to put these items in. So what do you expect me to do. Spin magic?");
|
||||
}
|
||||
}
|
||||
|
||||
Select select = new Select(func, _specifiedAttrs.size() == 0 ? null : _specifiedAttrs.get(0), declaredField, params);
|
||||
_selects.add(select);
|
||||
|
||||
_specifiedAttrs.clear();
|
||||
|
||||
return (J)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select fields from the entity object to be selected in the search query.
|
||||
*
|
||||
* @param fields fields from the entity object
|
||||
* @return itself
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J selectFields(Object... fields) {
|
||||
if (_entity == null) {
|
||||
throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
|
||||
}
|
||||
if (_specifiedAttrs.size() <= 0) {
|
||||
throw new RuntimeException("You didn't specify any attributes");
|
||||
}
|
||||
|
||||
if (_selects == null) {
|
||||
_selects = new ArrayList<Select>();
|
||||
}
|
||||
|
||||
for (Attribute attr : _specifiedAttrs) {
|
||||
Field field = null;
|
||||
try {
|
||||
field = _resultType.getDeclaredField(attr.field.getName());
|
||||
field.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
} catch (NoSuchFieldException e) {
|
||||
}
|
||||
_selects.add(new Select(Func.NATIVE, attr, field, null));
|
||||
}
|
||||
|
||||
_specifiedAttrs.clear();
|
||||
|
||||
return (J)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* joins this search with another search
|
||||
*
|
||||
* @param name name given to the other search. used for setJoinParameters.
|
||||
* @param builder The other search
|
||||
* @param joinField1 field of the first table used to perform the join
|
||||
* @param joinField2 field of the second table used to perform the join
|
||||
* @param joinType type of join
|
||||
* @return itself
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J join(String name, SearchBase<?, ?, ?> builder, Object joinField1, Object joinField2, JoinBuilder.JoinType joinType) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert builder._entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert builder._specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert builder != this : "You can't add yourself, can you? Really think about it!";
|
||||
|
||||
JoinBuilder<SearchBase<?, ?, ?>> t = new JoinBuilder<SearchBase<?, ?, ?>>(builder, _specifiedAttrs.get(0), builder._specifiedAttrs.get(0), joinType);
|
||||
if (_joins == null) {
|
||||
_joins = new HashMap<String, JoinBuilder<SearchBase<?, ?, ?>>>();
|
||||
}
|
||||
_joins.put(name, t);
|
||||
|
||||
builder._specifiedAttrs.clear();
|
||||
_specifiedAttrs.clear();
|
||||
return (J)this;
|
||||
}
|
||||
|
||||
public SelectType getSelectType() {
|
||||
return _selectType;
|
||||
}
|
||||
|
||||
protected void set(String name) {
|
||||
Attribute attr = _attrs.get(name);
|
||||
assert (attr != null) : "Searching for a field that's not there: " + name;
|
||||
_specifiedAttrs.add(attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return entity object. This allows the caller to use the entity return
|
||||
* to specify the field to be selected in many of the search parameters.
|
||||
*/
|
||||
public T entity() {
|
||||
return _entity;
|
||||
}
|
||||
|
||||
protected Attribute getSpecifiedAttribute() {
|
||||
if (_entity == null || _specifiedAttrs == null || _specifiedAttrs.size() != 1) {
|
||||
throw new RuntimeException("Now now, better specify an attribute or else we can't help you");
|
||||
}
|
||||
return _specifiedAttrs.get(0);
|
||||
}
|
||||
|
||||
protected List<Attribute> getSpecifiedAttributes() {
|
||||
return _specifiedAttrs;
|
||||
}
|
||||
|
||||
protected Condition constructCondition(String conditionName, String cond, Attribute attr, Op op) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert op == null || _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert op != Op.SC : "Call join";
|
||||
|
||||
Condition condition = new Condition(conditionName, cond, attr, op);
|
||||
_conditions.add(condition);
|
||||
_specifiedAttrs.clear();
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the SearchCriteria so the actual values can be filled in.
|
||||
*
|
||||
* @return SearchCriteria
|
||||
*/
|
||||
public SearchCriteria<K> create() {
|
||||
if (_entity != null) {
|
||||
finalize();
|
||||
}
|
||||
return new SearchCriteria<K>(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an OR condition to the search. Normally you should use this to
|
||||
* perform an 'OR' with a big conditional in parenthesis. For example,
|
||||
*
|
||||
* search.or().op(entity.getId(), Op.Eq, "abc").cp()
|
||||
*
|
||||
* The above fragment produces something similar to
|
||||
*
|
||||
* "OR (id = $abc) where abc is the token to be replaced by a value later.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J or() {
|
||||
constructCondition(null, " OR ", null, null);
|
||||
return (J)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an AND condition to the search. Normally you should use this to
|
||||
* perform an 'AND' with a big conditional in parenthesis. For example,
|
||||
*
|
||||
* search.and().op(entity.getId(), Op.Eq, "abc").cp()
|
||||
*
|
||||
* The above fragment produces something similar to
|
||||
*
|
||||
* "AND (id = $abc) where abc is the token to be replaced by a value later.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J and() {
|
||||
constructCondition(null, " AND ", null, null);
|
||||
return (J)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a parenthesis that's started by op()
|
||||
* @return this
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J cp() {
|
||||
Condition condition = new Condition(null, " ) ", null, Op.RP);
|
||||
_conditions.add(condition);
|
||||
return (J)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an open parenthesis into the search
|
||||
* @return this
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J op() {
|
||||
Condition condition = new Condition(null, " ( ", null, Op.RP);
|
||||
_conditions.add(condition);
|
||||
return (J)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the SearchBuilder as completed in building the search conditions.
|
||||
*/
|
||||
@Override
|
||||
protected synchronized void finalize() {
|
||||
if (_entity != null) {
|
||||
Factory factory = (Factory)_entity;
|
||||
factory.setCallback(0, null);
|
||||
_entity = null;
|
||||
}
|
||||
|
||||
if (_joins != null) {
|
||||
for (JoinBuilder<SearchBase<?, ?, ?>> join : _joins.values()) {
|
||||
join.getT().finalize();
|
||||
}
|
||||
}
|
||||
|
||||
if (_selects == null || _selects.size() == 0) {
|
||||
_selectType = SelectType.Entity;
|
||||
assert _entityBeanType.equals(_resultType) : "Expecting " + _entityBeanType + " because you didn't specify any selects but instead got " + _resultType;
|
||||
return;
|
||||
}
|
||||
|
||||
for (Select select : _selects) {
|
||||
if (select.field == null) {
|
||||
assert (_selects.size() == 1) : "You didn't specify any fields to put the result in but you're specifying more than one select so where should I put the selects?";
|
||||
_selectType = SelectType.Single;
|
||||
return;
|
||||
}
|
||||
if (select.func != null) {
|
||||
_selectType = SelectType.Result;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_selectType = SelectType.Fields;
|
||||
}
|
||||
|
||||
protected static class Condition {
|
||||
protected final String name;
|
||||
protected final String cond;
|
||||
protected final Op op;
|
||||
protected final Attribute attr;
|
||||
protected Object[] presets;
|
||||
|
||||
protected Condition(String name) {
|
||||
this(name, null, null, null);
|
||||
}
|
||||
|
||||
public Condition(String name, String cond, Attribute attr, Op op) {
|
||||
this.name = name;
|
||||
this.attr = attr;
|
||||
this.cond = cond;
|
||||
this.op = op;
|
||||
this.presets = null;
|
||||
}
|
||||
|
||||
public boolean isPreset() {
|
||||
return presets != null;
|
||||
}
|
||||
|
||||
public void setPresets(Object... presets) {
|
||||
this.presets = presets;
|
||||
}
|
||||
|
||||
public Object[] getPresets() {
|
||||
return presets;
|
||||
}
|
||||
|
||||
public void toSql(StringBuilder sql, Object[] params, int count) {
|
||||
if (count > 0) {
|
||||
sql.append(cond);
|
||||
}
|
||||
|
||||
if (op == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (op == Op.SC) {
|
||||
sql.append(" (").append(((SearchCriteria<?>)params[0]).getWhereClause()).append(") ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (attr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
sql.append(attr.table).append(".").append(attr.columnName).append(op.toString());
|
||||
if (op == Op.IN && params.length == 1) {
|
||||
sql.delete(sql.length() - op.toString().length(), sql.length());
|
||||
sql.append("=?");
|
||||
} else if (op == Op.NIN && params.length == 1) {
|
||||
sql.delete(sql.length() - op.toString().length(), sql.length());
|
||||
sql.append("!=?");
|
||||
} else if (op.getParams() == -1) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
sql.insert(sql.length() - 2, "?,");
|
||||
}
|
||||
sql.delete(sql.length() - 3, sql.length() - 2); // remove the last ,
|
||||
} else if (op == Op.EQ && (params == null || params.length == 0 || params[0] == null)) {
|
||||
sql.delete(sql.length() - 4, sql.length());
|
||||
sql.append(" IS NULL ");
|
||||
} else if (op == Op.NEQ && (params == null || params.length == 0 || params[0] == null)) {
|
||||
sql.delete(sql.length() - 5, sql.length());
|
||||
sql.append(" IS NOT NULL ");
|
||||
} else {
|
||||
if ((op.getParams() != 0 || params != null) && (params.length != op.getParams())) {
|
||||
throw new RuntimeException("Problem with condition: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Condition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Condition condition = (Condition)obj;
|
||||
return name.equals(condition.name);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class Select {
|
||||
public Func func;
|
||||
public Attribute attr;
|
||||
public Object[] params;
|
||||
public Field field;
|
||||
|
||||
protected Select() {
|
||||
}
|
||||
|
||||
public Select(Func func, Attribute attr, Field field, Object[] params) {
|
||||
this.func = func;
|
||||
this.attr = attr;
|
||||
this.params = params;
|
||||
this.field = field;
|
||||
}
|
||||
}
|
||||
|
||||
protected class Interceptor implements MethodInterceptor {
|
||||
@Override
|
||||
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
String name = method.getName();
|
||||
if (method.getAnnotation(Transient.class) == null) {
|
||||
if (name.startsWith("get")) {
|
||||
String fieldName = Character.toLowerCase(name.charAt(3)) + name.substring(4);
|
||||
set(fieldName);
|
||||
return null;
|
||||
} else if (name.startsWith("is")) {
|
||||
String fieldName = Character.toLowerCase(name.charAt(2)) + name.substring(3);
|
||||
set(fieldName);
|
||||
return null;
|
||||
} else {
|
||||
Column ann = method.getAnnotation(Column.class);
|
||||
if (ann != null) {
|
||||
String colName = ann.name();
|
||||
for (Map.Entry<String, Attribute> attr : _attrs.entrySet()) {
|
||||
if (colName.equals(attr.getValue().columnName)) {
|
||||
set(attr.getKey());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Perhaps you need to make the method start with get or is: " + method);
|
||||
}
|
||||
}
|
||||
return methodProxy.invokeSuper(object, args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
// under the License.
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SearchBuilder is meant as a static query construct. Often times in DAO code,
|
||||
|
|
@ -57,8 +56,7 @@ import java.util.Map;
|
|||
*/
|
||||
public class SearchBuilder<T> extends GenericSearchBuilder<T, T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SearchBuilder(T entity, Map<String, Attribute> attrs) {
|
||||
super(entity, (Class<T>)entity.getClass(), attrs);
|
||||
public SearchBuilder(Class<T> entityType) {
|
||||
super(entityType, entityType);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.GenericSearchBuilder.Condition;
|
||||
import com.cloud.utils.db.GenericSearchBuilder.Select;
|
||||
import com.cloud.utils.db.SearchBase.Condition;
|
||||
import com.cloud.utils.db.SearchBase.Select;
|
||||
|
||||
/**
|
||||
* big joins or high performance searches, it is much better to
|
||||
|
|
@ -56,6 +56,7 @@ public class SearchCriteria<K> {
|
|||
|
||||
private final String op;
|
||||
int params;
|
||||
|
||||
Op(String op, int params) {
|
||||
this.op = op;
|
||||
this.params = params;
|
||||
|
|
@ -113,26 +114,12 @@ public class SearchCriteria<K> {
|
|||
private int _counter;
|
||||
private HashMap<String, JoinBuilder<SearchCriteria<?>>> _joins;
|
||||
private final ArrayList<Select> _selects;
|
||||
private final GroupBy<?, K> _groupBy;
|
||||
private final GroupBy<? extends SearchBase<?, ?, K>, ?, K> _groupBy;
|
||||
private final List<Object> _groupByValues;
|
||||
private final Class<K> _resultType;
|
||||
private final SelectType _selectType;
|
||||
|
||||
protected SearchCriteria(final Map<String, Attribute> attrs, ArrayList<GenericSearchBuilder.Condition> conditions, ArrayList<Select> selects, SelectType selectType, Class<K> resultType, HashMap<String, Object[]> params) {
|
||||
this._attrs = attrs;
|
||||
this._conditions = conditions;
|
||||
this._selects = selects;
|
||||
this._selectType = selectType;
|
||||
this._resultType = resultType;
|
||||
this._params = params;
|
||||
this._additionals = new ArrayList<Condition>();
|
||||
this._counter = 0;
|
||||
this._joins = null;
|
||||
this._groupBy = null;
|
||||
this._groupByValues = null;
|
||||
}
|
||||
|
||||
protected SearchCriteria(GenericSearchBuilder<?, K> sb) {
|
||||
protected SearchCriteria(SearchBase<?, ?, K> sb) {
|
||||
this._attrs = sb._attrs;
|
||||
this._conditions = sb._conditions;
|
||||
this._additionals = new ArrayList<Condition>();
|
||||
|
|
@ -140,9 +127,9 @@ public class SearchCriteria<K> {
|
|||
this._joins = null;
|
||||
if (sb._joins != null) {
|
||||
_joins = new HashMap<String, JoinBuilder<SearchCriteria<?>>>(sb._joins.size());
|
||||
for (Map.Entry<String, JoinBuilder<GenericSearchBuilder<?, ?>>> entry : sb._joins.entrySet()) {
|
||||
JoinBuilder<GenericSearchBuilder<?, ?>> value = entry.getValue();
|
||||
_joins.put(entry.getKey(), new JoinBuilder<SearchCriteria<?>>(value.getT().create(),value.getFirstAttribute(), value.getSecondAttribute(), value.getType()));
|
||||
for (Map.Entry<String, JoinBuilder<SearchBase<?, ?, ?>>> entry : sb._joins.entrySet()) {
|
||||
JoinBuilder<SearchBase<?, ?, ?>> value = entry.getValue();
|
||||
_joins.put(entry.getKey(), new JoinBuilder<SearchCriteria<?>>(value.getT().create(), value.getFirstAttribute(), value.getSecondAttribute(), value.getType()));
|
||||
}
|
||||
}
|
||||
_selects = sb._selects;
|
||||
|
|
@ -156,6 +143,10 @@ public class SearchCriteria<K> {
|
|||
_selectType = sb._selectType;
|
||||
}
|
||||
|
||||
protected void setParameters(HashMap<String, Object[]> parameters) {
|
||||
_params = parameters;
|
||||
}
|
||||
|
||||
public SelectType getSelectType() {
|
||||
return _selectType;
|
||||
}
|
||||
|
|
@ -201,22 +192,22 @@ public class SearchCriteria<K> {
|
|||
}
|
||||
|
||||
protected JoinBuilder<SearchCriteria<?>> findJoin(Map<String, JoinBuilder<SearchCriteria<?>>> jbmap, String joinName) {
|
||||
JoinBuilder<SearchCriteria<?>> jb = jbmap.get(joinName);
|
||||
if (jb != null) {
|
||||
return jb;
|
||||
}
|
||||
|
||||
for (JoinBuilder<SearchCriteria<?>> j2 : jbmap.values()) {
|
||||
SearchCriteria<?> sc = j2.getT();
|
||||
if(sc._joins != null)
|
||||
jb = findJoin(sc._joins, joinName);
|
||||
if (jb != null) {
|
||||
return jb;
|
||||
}
|
||||
}
|
||||
|
||||
assert (false) : "Unable to find a join by the name " + joinName;
|
||||
return null;
|
||||
JoinBuilder<SearchCriteria<?>> jb = jbmap.get(joinName);
|
||||
if (jb != null) {
|
||||
return jb;
|
||||
}
|
||||
|
||||
for (JoinBuilder<SearchCriteria<?>> j2 : jbmap.values()) {
|
||||
SearchCriteria<?> sc = j2.getT();
|
||||
if (sc._joins != null)
|
||||
jb = findJoin(sc._joins, joinName);
|
||||
if (jb != null) {
|
||||
return jb;
|
||||
}
|
||||
}
|
||||
|
||||
assert (false) : "Unable to find a join by the name " + joinName;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setJoinParameters(String joinName, String conditionName, Object... params) {
|
||||
|
|
@ -226,24 +217,12 @@ public class SearchCriteria<K> {
|
|||
|
||||
}
|
||||
|
||||
public void addJoinAnd(String joinName, String field, Op op, Object... values) {
|
||||
JoinBuilder<SearchCriteria<?>> join = _joins.get(joinName);
|
||||
assert (join != null) : "Incorrect join name specified: " + joinName;
|
||||
join.getT().addAnd(field, op, values);
|
||||
}
|
||||
|
||||
public void addJoinOr(String joinName, String field, Op op, Object... values) {
|
||||
JoinBuilder<SearchCriteria<?>> join = _joins.get(joinName);
|
||||
assert (join != null) : "Incorrect join name specified: " + joinName;
|
||||
join.getT().addOr(field, op, values);
|
||||
}
|
||||
|
||||
public SearchCriteria<?> getJoin(String joinName) {
|
||||
return _joins.get(joinName).getT();
|
||||
}
|
||||
|
||||
public Pair<GroupBy<?, ?>, List<Object>> getGroupBy() {
|
||||
return _groupBy == null ? null : new Pair<GroupBy<?, ?>, List<Object>>(_groupBy, _groupByValues);
|
||||
public Pair<GroupBy<?, ?, ?>, List<Object>> getGroupBy() {
|
||||
return _groupBy == null ? null : new Pair<GroupBy<?, ?, ?>, List<Object>>(_groupBy, _groupByValues);
|
||||
}
|
||||
|
||||
public void setGroupByValues(Object... values) {
|
||||
|
|
@ -256,30 +235,27 @@ public class SearchCriteria<K> {
|
|||
return _resultType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addAnd(String field, Op op, Object... values) {
|
||||
String name = Integer.toString(_counter++);
|
||||
addCondition(name, " AND ", field, op);
|
||||
setParameters(name, values);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addAnd(Attribute attr, Op op, Object... values) {
|
||||
String name = Integer.toString(_counter++);
|
||||
addCondition(name, " AND ", attr, op);
|
||||
setParameters(name, values);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addOr(String field, Op op, Object... values) {
|
||||
String name = Integer.toString(_counter++);
|
||||
addCondition(name, " OR ", field, op);
|
||||
setParameters(name, values);
|
||||
}
|
||||
|
||||
public void addOr(Attribute attr, Op op, Object... values) {
|
||||
String name = Integer.toString(_counter++);
|
||||
addCondition(name, " OR ", attr, op);
|
||||
setParameters(name, values);
|
||||
}
|
||||
|
||||
protected void addCondition(String conditionName, String cond, String fieldName, Op op) {
|
||||
Attribute attr = _attrs.get(fieldName);
|
||||
assert attr != null : "Unable to find field: " + fieldName;
|
||||
|
|
|
|||
|
|
@ -1,213 +0,0 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import net.sf.cglib.proxy.Factory;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
|
||||
import com.cloud.utils.db.GenericSearchBuilder.Condition;
|
||||
import com.cloud.utils.db.GenericSearchBuilder.Select;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria.SelectType;
|
||||
|
||||
public class SearchCriteria2<T, K> implements SearchCriteriaService<T, K>, MethodInterceptor{
|
||||
GenericDao<? extends Serializable, ? extends Serializable> _dao;
|
||||
final protected Map<String, Attribute> _attrs;
|
||||
protected ArrayList<Attribute> _specifiedAttrs;
|
||||
protected T _entity;
|
||||
protected ArrayList<GenericSearchBuilder.Condition> _conditions;
|
||||
protected ArrayList<Select> _selects;
|
||||
private final HashMap<String, Object[]> _params = new HashMap<String, Object[]>();
|
||||
protected Class<K> _resultType;
|
||||
protected SelectType _selectType;
|
||||
protected Class<T> _entityBeanType;
|
||||
|
||||
protected SearchCriteria2(T entity, Class<K> resultType, final Map<String, Attribute> attrs, GenericDao<? extends Serializable, ? extends Serializable> dao) {
|
||||
_entityBeanType = (Class<T>)entity.getClass();
|
||||
_dao = dao;
|
||||
_resultType = resultType;
|
||||
_attrs = attrs;
|
||||
_entity = entity;
|
||||
_conditions = new ArrayList<Condition>();
|
||||
_specifiedAttrs = new ArrayList<Attribute>();
|
||||
}
|
||||
|
||||
static public <T, K> SearchCriteria2<T, K> create(Class<T> entityType, Class<K> resultType) {
|
||||
GenericDao<? extends Serializable, ? extends Serializable> dao = (GenericDao<? extends Serializable, ? extends Serializable>)GenericDaoBase.getDao(entityType);
|
||||
assert dao != null : "Can not find DAO for " + entityType.getName();
|
||||
SearchCriteria2<T, K> sc = dao.createSearchCriteria2(resultType);
|
||||
return sc;
|
||||
}
|
||||
|
||||
static public <T, K> SearchCriteria2<T, K> create(Class<T> entityType) {
|
||||
GenericDao<? extends Serializable, ? extends Serializable> dao = (GenericDao<? extends Serializable, ? extends Serializable>)GenericDaoBase.getDao(entityType);
|
||||
assert dao != null : "Can not find DAO for " + entityType.getName();
|
||||
SearchCriteria2<T, K> sc = dao.createSearchCriteria2();
|
||||
return sc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectField(Object... useless) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert _specifiedAttrs.size() > 0 : "You didn't specify any attributes";
|
||||
|
||||
if (_selects == null) {
|
||||
_selects = new ArrayList<Select>();
|
||||
}
|
||||
|
||||
for (Attribute attr : _specifiedAttrs) {
|
||||
Field field = null;
|
||||
try {
|
||||
field = _resultType.getDeclaredField(attr.field.getName());
|
||||
field.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
} catch (NoSuchFieldException e) {
|
||||
}
|
||||
_selects.add(new Select(Func.NATIVE, attr, field, null));
|
||||
}
|
||||
|
||||
_specifiedAttrs.clear();
|
||||
}
|
||||
|
||||
private void constructCondition(String conditionName, String cond, Attribute attr, Op op) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert op == null || _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert op != Op.SC : "Call join";
|
||||
|
||||
GenericSearchBuilder.Condition condition = new GenericSearchBuilder.Condition(conditionName, cond, attr, op);
|
||||
_conditions.add(condition);
|
||||
_specifiedAttrs.clear();
|
||||
}
|
||||
|
||||
private void setParameters(String conditionName, Object... params) {
|
||||
assert _conditions.contains(new Condition(conditionName)) : "Couldn't find " + conditionName;
|
||||
_params.put(conditionName, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnd(Object useless, Op op, Object...values) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
constructCondition(uuid, " AND ", _specifiedAttrs.get(0), op);
|
||||
setParameters(uuid, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<K> list() {
|
||||
done();
|
||||
SearchCriteria sc1 = createSearchCriteria();
|
||||
if (isSelectAll()) {
|
||||
return (List<K>)_dao.search(sc1, null);
|
||||
} else {
|
||||
return _dao.customSearch(sc1, null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSelectAll() {
|
||||
return _selects == null || _selects.size() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getEntity() {
|
||||
return _entity;
|
||||
}
|
||||
|
||||
private SearchCriteria<K> createSearchCriteria() {
|
||||
return new SearchCriteria<K>(_attrs, _conditions, _selects, _selectType, _resultType, _params);
|
||||
}
|
||||
|
||||
private void set(String name) {
|
||||
Attribute attr = _attrs.get(name);
|
||||
assert (attr != null) : "Searching for a field that's not there: " + name;
|
||||
_specifiedAttrs.add(attr);
|
||||
}
|
||||
|
||||
private void done() {
|
||||
if (_entity != null) {
|
||||
Factory factory = (Factory)_entity;
|
||||
factory.setCallback(0, null);
|
||||
_entity = null;
|
||||
}
|
||||
|
||||
if (_selects == null || _selects.size() == 0) {
|
||||
_selectType = SelectType.Entity;
|
||||
assert _entityBeanType.equals(_resultType) : "Expecting " + _entityBeanType + " because you didn't specify any selects but instead got " + _resultType;
|
||||
return;
|
||||
}
|
||||
|
||||
for (Select select : _selects) {
|
||||
if (select.field == null) {
|
||||
assert (_selects.size() == 1) : "You didn't specify any fields to put the result in but you're specifying more than one select so where should I put the selects?";
|
||||
_selectType = SelectType.Single;
|
||||
return;
|
||||
}
|
||||
if (select.func != null) {
|
||||
_selectType = SelectType.Result;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_selectType = SelectType.Fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
String name = method.getName();
|
||||
if (method.getAnnotation(Transient.class) == null) {
|
||||
if (name.startsWith("get")) {
|
||||
String fieldName = Character.toLowerCase(name.charAt(3)) + name.substring(4);
|
||||
set(fieldName);
|
||||
return null;
|
||||
} else if (name.startsWith("is")) {
|
||||
String fieldName = Character.toLowerCase(name.charAt(2)) + name.substring(3);
|
||||
set(fieldName);
|
||||
return null;
|
||||
} else {
|
||||
name = name.toLowerCase();
|
||||
for (String fieldName : _attrs.keySet()) {
|
||||
if (name.endsWith(fieldName.toLowerCase())) {
|
||||
set(fieldName);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
assert false : "Perhaps you need to make the method start with get or is?";
|
||||
}
|
||||
}
|
||||
return methodProxy.invokeSuper(object, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> K find() {
|
||||
assert isSelectAll() : "find doesn't support select search";
|
||||
done();
|
||||
SearchCriteria sc1 = createSearchCriteria();
|
||||
return (K)_dao.findOneBy(sc1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ public class SyncQueueItemDaoImpl extends GenericDaoBase<SyncQueueItemVO, Long>
|
|||
queueIdSearch = createSearchBuilder(Long.class);
|
||||
queueIdSearch.and("contentId", queueIdSearch.entity().getContentId(), Op.EQ);
|
||||
queueIdSearch.and("contentType", queueIdSearch.entity().getContentType(), Op.EQ);
|
||||
queueIdSearch.selectField(queueIdSearch.entity().getId());
|
||||
queueIdSearch.selectFields(queueIdSearch.entity().getId());
|
||||
queueIdSearch.done();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -898,13 +898,13 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager,
|
|||
|
||||
JoinJobSearch = _joinMapDao.createSearchBuilder(Long.class);
|
||||
JoinJobSearch.and(JoinJobSearch.entity().getJoinJobId(), Op.EQ, "joinJobId");
|
||||
JoinJobSearch.selectField(JoinJobSearch.entity().getJobId());
|
||||
JoinJobSearch.selectFields(JoinJobSearch.entity().getJobId());
|
||||
JoinJobSearch.done();
|
||||
|
||||
JoinJobTimeSearch = _joinMapDao.createSearchBuilder(Long.class);
|
||||
JoinJobTimeSearch.and(JoinJobTimeSearch.entity().getNextWakeupTime(), Op.LT, "beginTime");
|
||||
JoinJobTimeSearch.and(JoinJobTimeSearch.entity().getExpiration(), Op.GT, "endTime");
|
||||
JoinJobTimeSearch.selectField(JoinJobTimeSearch.entity().getJobId()).done();
|
||||
JoinJobTimeSearch.selectFields(JoinJobTimeSearch.entity().getJobId()).done();
|
||||
|
||||
JobIdsSearch = _jobDao.createSearchBuilder();
|
||||
JobIdsSearch.and(JobIdsSearch.entity().getId(), Op.IN, "ids").done();
|
||||
|
|
@ -913,13 +913,13 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager,
|
|||
QueueJobIdsSearch.and(QueueJobIdsSearch.entity().getContentId(), Op.IN, "contentIds").done();
|
||||
|
||||
JoinJobIdsSearch = _joinMapDao.createSearchBuilder(Long.class);
|
||||
JoinJobIdsSearch.selectField(JoinJobIdsSearch.entity().getJobId());
|
||||
JoinJobIdsSearch.selectFields(JoinJobIdsSearch.entity().getJobId());
|
||||
JoinJobIdsSearch.and(JoinJobIdsSearch.entity().getJoinJobId(), Op.EQ, "joinJobId");
|
||||
JoinJobIdsSearch.and(JoinJobIdsSearch.entity().getJobId(), Op.NIN, "jobIds");
|
||||
JoinJobIdsSearch.done();
|
||||
|
||||
ContentIdsSearch = _queueItemDao.createSearchBuilder(Long.class);
|
||||
ContentIdsSearch.selectField(ContentIdsSearch.entity().getContentId()).done();
|
||||
ContentIdsSearch.selectFields(ContentIdsSearch.entity().getContentId()).done();
|
||||
|
||||
AsyncJobExecutionContext.init(this, _joinMapDao);
|
||||
OutcomeImpl.init(this);
|
||||
|
|
|
|||
|
|
@ -61,8 +61,7 @@ PCP=`ls /usr/share/cloudstack-agent/plugins/*.jar 2>/dev/null | tr '\n' ':' | se
|
|||
|
||||
# We need to append the JSVC daemon JAR to the classpath
|
||||
# AgentShell implements the JSVC daemon methods
|
||||
# We also need JNA in the classpath (from the distribution) for the Libvirt Java bindings
|
||||
export CLASSPATH="/usr/share/java/commons-daemon.jar:/usr/share/java/jna.jar:$ACP:$PCP:/etc/cloudstack/agent:/usr/share/cloudstack-common/scripts"
|
||||
export CLASSPATH="/usr/share/java/commons-daemon.jar:$ACP:$PCP:/etc/cloudstack/agent:/usr/share/cloudstack-common/scripts"
|
||||
|
||||
start() {
|
||||
echo -n $"Starting $PROGNAME: "
|
||||
|
|
|
|||
|
|
@ -112,7 +112,6 @@ The Apache CloudStack files shared between agent and management server
|
|||
%package agent
|
||||
Summary: CloudStack Agent for KVM hypervisors
|
||||
Requires: java >= 1.6.0
|
||||
Requires: jna >= 3.2.4
|
||||
Requires: %{name}-common = %{_ver}
|
||||
Requires: libvirt
|
||||
Requires: bridge-utils
|
||||
|
|
|
|||
|
|
@ -60,8 +60,7 @@ PCP=`ls /usr/share/cloudstack-agent/plugins/*.jar 2>/dev/null | tr '\n' ':' | se
|
|||
|
||||
# We need to append the JSVC daemon JAR to the classpath
|
||||
# AgentShell implements the JSVC daemon methods
|
||||
# We also need JNA in the classpath (from the distribution) for the Libvirt Java bindings
|
||||
export CLASSPATH="/usr/share/java/commons-daemon.jar:/usr/share/java/jna.jar:$ACP:$PCP:/etc/cloudstack/agent"
|
||||
export CLASSPATH="/usr/share/java/commons-daemon.jar:$ACP:$PCP:/etc/cloudstack/agent"
|
||||
|
||||
wait_for_network() {
|
||||
i=1
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC
|
|||
private static Map<RoleType, Set<String>> s_roleBasedApisMap =
|
||||
new HashMap<RoleType, Set<String>>();
|
||||
|
||||
@Inject List<PluggableService> _services;
|
||||
List<PluggableService> _services;
|
||||
@Inject AccountService _accountService;
|
||||
|
||||
protected StaticRoleBasedAPIAccessChecker() {
|
||||
|
|
@ -95,4 +95,13 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<PluggableService> getServices() {
|
||||
return _services;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setServices(List<PluggableService> _services) {
|
||||
this._services = _services;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import com.cloud.utils.db.GenericDaoBase;
|
|||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.GenericQueryBuilder;
|
||||
|
||||
@Component
|
||||
@Local(value=BaremetalDhcpDao.class)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import com.cloud.utils.db.GenericDaoBase;
|
|||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.GenericQueryBuilder;
|
||||
|
||||
@Component
|
||||
@Local(value = {BaremetalPxeDao.class})
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
package com.cloud.baremetal.networkservice;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -36,7 +35,6 @@ import org.apache.log4j.Logger;
|
|||
import org.apache.cloudstack.api.AddBaremetalPxeCmd;
|
||||
import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd;
|
||||
import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
|
||||
|
|
@ -62,9 +60,8 @@ import com.cloud.resource.ResourceManager;
|
|||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
|
@ -84,9 +81,9 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements
|
|||
|
||||
@Override
|
||||
public boolean prepare(VirtualMachineProfile profile, NicProfile pxeNic, DeployDestination dest, ReservationContext context) {
|
||||
SearchCriteriaService<BaremetalPxeVO, BaremetalPxeVO> sc = SearchCriteria2.create(BaremetalPxeVO.class);
|
||||
sc.addAnd(sc.getEntity().getDeviceType(), Op.EQ, BaremetalPxeType.PING.toString());
|
||||
sc.addAnd(sc.getEntity().getPodId(), Op.EQ, dest.getPod().getId());
|
||||
QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
|
||||
sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.PING.toString());
|
||||
sc.and(sc.entity().getPodId(), Op.EQ, dest.getPod().getId());
|
||||
BaremetalPxeVO pxeVo = sc.find();
|
||||
if (pxeVo == null) {
|
||||
throw new CloudRuntimeException("No PING PXE server found in pod: " + dest.getPod().getId() + ", you need to add it before starting VM");
|
||||
|
|
|
|||
|
|
@ -5,19 +5,28 @@
|
|||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
//
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 01/29/2013
|
||||
package com.cloud.baremetal.networkservice;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.baremetal.database.BaremetalDhcpVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.Pod;
|
||||
|
|
@ -39,20 +48,15 @@ import com.cloud.network.element.NetworkElement;
|
|||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.vm.*;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Local(value = NetworkElement.class)
|
||||
public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProvider {
|
||||
|
|
@ -84,8 +88,8 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv
|
|||
private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType) {
|
||||
Pod pod = dest.getPod();
|
||||
if (pod != null && dest.getDataCenter().getNetworkType() == NetworkType.Basic && trafficType == TrafficType.Guest) {
|
||||
SearchCriteriaService<BaremetalDhcpVO, BaremetalDhcpVO> sc = SearchCriteria2.create(BaremetalDhcpVO.class);
|
||||
sc.addAnd(sc.getEntity().getPodId(), Op.EQ, pod.getId());
|
||||
QueryBuilder<BaremetalDhcpVO> sc = QueryBuilder.create(BaremetalDhcpVO.class);
|
||||
sc.and(sc.entity().getPodId(), Op.EQ,pod.getId());
|
||||
return sc.find() != null;
|
||||
}
|
||||
|
||||
|
|
@ -159,6 +163,7 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest,
|
||||
ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
if (vm.getHypervisorType() != HypervisorType.BareMetal || !canHandle(dest, network.getTrafficType(), network.getGuestType())) {
|
||||
|
|
|
|||
|
|
@ -5,20 +5,20 @@
|
|||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
//
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 01/29/2013
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
//
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.baremetal.networkservice;
|
||||
|
||||
|
|
@ -32,9 +32,10 @@ import javax.ejb.Local;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.AddBaremetalDhcpCmd;
|
||||
import org.apache.cloudstack.api.ListBaremetalDhcpCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
|
@ -45,7 +46,6 @@ import com.cloud.baremetal.database.BaremetalDhcpDao;
|
|||
import com.cloud.baremetal.database.BaremetalDhcpVO;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
|
|
@ -67,14 +67,12 @@ import com.cloud.resource.ServerResource;
|
|||
import com.cloud.resource.UnableDeleteHostException;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
|
@ -311,9 +309,9 @@ public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDh
|
|||
return responses;
|
||||
}
|
||||
|
||||
SearchCriteriaService<BaremetalDhcpVO, BaremetalDhcpVO> sc = SearchCriteria2.create(BaremetalDhcpVO.class);
|
||||
QueryBuilder<BaremetalDhcpVO> sc = QueryBuilder.create(BaremetalDhcpVO.class);
|
||||
if (cmd.getDeviceType() != null) {
|
||||
sc.addAnd(sc.getEntity().getDeviceType(), Op.EQ, cmd.getDeviceType());
|
||||
sc.and(sc.entity().getDeviceType(), Op.EQ, cmd.getDeviceType());
|
||||
}
|
||||
|
||||
List<BaremetalDhcpVO> vos = sc.list();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import org.apache.log4j.Logger;
|
|||
import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
|
||||
import org.apache.cloudstack.api.AddBaremetalPxeCmd;
|
||||
import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
|
||||
|
|
@ -57,9 +56,8 @@ import com.cloud.storage.VMTemplateVO;
|
|||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
|
@ -87,9 +85,9 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
|
|||
@Override
|
||||
public boolean prepare(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context) {
|
||||
NetworkVO nwVO = _nwDao.findById(nic.getNetworkId());
|
||||
SearchCriteriaService<BaremetalPxeVO, BaremetalPxeVO> sc = SearchCriteria2.create(BaremetalPxeVO.class);
|
||||
sc.addAnd(sc.getEntity().getDeviceType(), Op.EQ, BaremetalPxeType.KICK_START.toString());
|
||||
sc.addAnd(sc.getEntity().getPhysicalNetworkId(), Op.EQ, nwVO.getPhysicalNetworkId());
|
||||
QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
|
||||
sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.KICK_START.toString());
|
||||
sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, nwVO.getPhysicalNetworkId());
|
||||
BaremetalPxeVO pxeVo = sc.find();
|
||||
if (pxeVo == null) {
|
||||
throw new CloudRuntimeException("No kickstart PXE server found in pod: " + dest.getPod().getId() + ", you need to add it before starting VM");
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@
|
|||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
//
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 01/29/2013
|
||||
package com.cloud.baremetal.networkservice;
|
||||
|
||||
|
|
@ -46,16 +46,14 @@ import com.cloud.network.element.NetworkElement;
|
|||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
|
|
@ -91,8 +89,8 @@ public class BaremetalPxeElement extends AdapterBase implements NetworkElement {
|
|||
private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType) {
|
||||
Pod pod = dest.getPod();
|
||||
if (pod != null && dest.getDataCenter().getNetworkType() == NetworkType.Basic && trafficType == TrafficType.Guest) {
|
||||
SearchCriteriaService<BaremetalPxeVO, BaremetalPxeVO> sc = SearchCriteria2.create(BaremetalPxeVO.class);
|
||||
sc.addAnd(sc.getEntity().getPodId(), Op.EQ, pod.getId());
|
||||
QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
|
||||
sc.and(sc.entity().getPodId(), Op.EQ, pod.getId());
|
||||
return sc.find() != null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,9 +36,8 @@ import org.apache.log4j.Logger;
|
|||
import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
|
||||
import org.apache.cloudstack.api.AddBaremetalPxeCmd;
|
||||
import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
|
@ -62,9 +61,8 @@ import com.cloud.service.dao.ServiceOfferingDao;
|
|||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
|
|
@ -220,10 +218,10 @@ public class BaremetalPxeManagerImpl extends ManagerBase implements BaremetalPxe
|
|||
}
|
||||
PhysicalNetworkVO phy = phys.get(0);
|
||||
|
||||
SearchCriteriaService<BaremetalPxeVO, BaremetalPxeVO> sc = SearchCriteria2.create(BaremetalPxeVO.class);
|
||||
QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
|
||||
//TODO: handle both kickstart and PING
|
||||
//sc.addAnd(sc.getEntity().getPodId(), Op.EQ, vm.getPodIdToDeployIn());
|
||||
sc.addAnd(sc.getEntity().getPhysicalNetworkId(), Op.EQ, phy.getId());
|
||||
sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, phy.getId());
|
||||
BaremetalPxeVO pxeVo = sc.find();
|
||||
if (pxeVo == null) {
|
||||
throw new CloudRuntimeException("No PXE server found in pod: " + vm.getPodIdToDeployIn() + ", you need to add it before starting VM");
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ import javax.naming.ConfigurationException;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
|
|
@ -48,244 +48,214 @@ import com.cloud.resource.ResourceManager;
|
|||
import com.cloud.resource.ResourceStateAdapter;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.UnableDeleteHostException;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
|
||||
@Local(value = Discoverer.class)
|
||||
public class OvmDiscoverer extends DiscovererBase implements Discoverer,
|
||||
ResourceStateAdapter {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(OvmDiscoverer.class);
|
||||
protected String _publicNetworkDevice;
|
||||
protected String _privateNetworkDevice;
|
||||
protected String _guestNetworkDevice;
|
||||
public class OvmDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter {
|
||||
private static final Logger s_logger = Logger.getLogger(OvmDiscoverer.class);
|
||||
protected String _publicNetworkDevice;
|
||||
protected String _privateNetworkDevice;
|
||||
protected String _guestNetworkDevice;
|
||||
|
||||
@Inject
|
||||
ClusterDao _clusterDao;
|
||||
@Inject
|
||||
ResourceManager _resourceMgr;
|
||||
@Inject
|
||||
ClusterDao _clusterDao;
|
||||
@Inject
|
||||
ResourceManager _resourceMgr;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
_publicNetworkDevice = _params.get(Config.OvmPublicNetwork.key());
|
||||
_privateNetworkDevice = _params.get(Config.OvmPrivateNetwork.key());
|
||||
_guestNetworkDevice = _params.get(Config.OvmGuestNetwork.key());
|
||||
_resourceMgr.registerResourceStateAdapter(this.getClass()
|
||||
.getSimpleName(), this);
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
_publicNetworkDevice = _params.get(Config.OvmPublicNetwork.key());
|
||||
_privateNetworkDevice = _params.get(Config.OvmPrivateNetwork.key());
|
||||
_guestNetworkDevice = _params.get(Config.OvmGuestNetwork.key());
|
||||
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected OvmDiscoverer() {
|
||||
}
|
||||
protected OvmDiscoverer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
_resourceMgr.unregisterResourceStateAdapter(this.getClass()
|
||||
.getSimpleName());
|
||||
return super.stop();
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
|
||||
return super.stop();
|
||||
}
|
||||
|
||||
private boolean checkIfExisted(String guid) {
|
||||
SearchCriteria2<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getGuid(), SearchCriteria.Op.EQ, guid);
|
||||
sc.addAnd(sc.getEntity().getHypervisorType(), SearchCriteria.Op.EQ,
|
||||
HypervisorType.Ovm);
|
||||
List<HostVO> hosts = sc.list();
|
||||
return !hosts.isEmpty();
|
||||
}
|
||||
private boolean checkIfExisted(String guid) {
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getGuid(), SearchCriteria.Op.EQ, guid);
|
||||
sc.and(sc.entity().getHypervisorType(), SearchCriteria.Op.EQ, HypervisorType.Ovm);
|
||||
List<HostVO> hosts = sc.list();
|
||||
return !hosts.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
|
||||
Long podId, Long clusterId, URI url, String username,
|
||||
String password, List<String> hostTags) throws DiscoveryException {
|
||||
Connection conn = null;
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags)
|
||||
throws DiscoveryException {
|
||||
Connection conn = null;
|
||||
|
||||
if (!url.getScheme().equals("http")) {
|
||||
String msg = "urlString is not http so we're not taking care of the discovery for this: "
|
||||
+ url;
|
||||
s_logger.debug(msg);
|
||||
return null;
|
||||
}
|
||||
if (clusterId == null) {
|
||||
String msg = "must specify cluster Id when add host";
|
||||
s_logger.debug(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
if (!url.getScheme().equals("http")) {
|
||||
String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
|
||||
s_logger.debug(msg);
|
||||
return null;
|
||||
}
|
||||
if (clusterId == null) {
|
||||
String msg = "must specify cluster Id when add host";
|
||||
s_logger.debug(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
|
||||
if (podId == null) {
|
||||
String msg = "must specify pod Id when add host";
|
||||
s_logger.debug(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
if (podId == null) {
|
||||
String msg = "must specify pod Id when add host";
|
||||
s_logger.debug(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
|
||||
ClusterVO cluster = _clusterDao.findById(clusterId);
|
||||
if (cluster == null
|
||||
|| (cluster.getHypervisorType() != HypervisorType.Ovm)) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors");
|
||||
return null;
|
||||
}
|
||||
ClusterVO cluster = _clusterDao.findById(clusterId);
|
||||
if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm)) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors");
|
||||
return null;
|
||||
}
|
||||
|
||||
String agentUsername = _params.get("agentusername");
|
||||
if (agentUsername == null) {
|
||||
throw new CloudRuntimeException("Agent user name must be specified");
|
||||
}
|
||||
String agentUsername = _params.get("agentusername");
|
||||
if (agentUsername == null) {
|
||||
throw new CloudRuntimeException("Agent user name must be specified");
|
||||
}
|
||||
|
||||
String agentPassword = _params.get("agentpassword");
|
||||
if (agentPassword == null) {
|
||||
throw new CloudRuntimeException("Agent password must be specified");
|
||||
}
|
||||
String agentPassword = _params.get("agentpassword");
|
||||
if (agentPassword == null) {
|
||||
throw new CloudRuntimeException("Agent password must be specified");
|
||||
}
|
||||
|
||||
try {
|
||||
String hostname = url.getHost();
|
||||
InetAddress ia = InetAddress.getByName(hostname);
|
||||
String hostIp = ia.getHostAddress();
|
||||
String guid = UUID.nameUUIDFromBytes(hostIp.getBytes()).toString();
|
||||
try {
|
||||
String hostname = url.getHost();
|
||||
InetAddress ia = InetAddress.getByName(hostname);
|
||||
String hostIp = ia.getHostAddress();
|
||||
String guid = UUID.nameUUIDFromBytes(hostIp.getBytes()).toString();
|
||||
|
||||
if (checkIfExisted(guid)) {
|
||||
throw new CloudRuntimeException("The host " + hostIp
|
||||
+ " has been added before");
|
||||
}
|
||||
if (checkIfExisted(guid)) {
|
||||
throw new CloudRuntimeException("The host " + hostIp + " has been added before");
|
||||
}
|
||||
|
||||
s_logger.debug("Ovm discover is going to disover host having guid "
|
||||
+ guid);
|
||||
s_logger.debug("Ovm discover is going to disover host having guid " + guid);
|
||||
|
||||
ClusterVO clu = _clusterDao.findById(clusterId);
|
||||
if (clu.getGuid() == null) {
|
||||
clu.setGuid(UUID.randomUUID().toString());
|
||||
_clusterDao.update(clusterId, clu);
|
||||
}
|
||||
ClusterVO clu = _clusterDao.findById(clusterId);
|
||||
if (clu.getGuid() == null) {
|
||||
clu.setGuid(UUID.randomUUID().toString());
|
||||
_clusterDao.update(clusterId, clu);
|
||||
}
|
||||
|
||||
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(
|
||||
hostIp, 22);
|
||||
sshConnection.connect(null, 60000, 60000);
|
||||
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp,
|
||||
username, password);
|
||||
if (sshConnection == null) {
|
||||
throw new DiscoveryException(
|
||||
String.format(
|
||||
"Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed",
|
||||
hostIp, username, password));
|
||||
}
|
||||
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hostIp, 22);
|
||||
sshConnection.connect(null, 60000, 60000);
|
||||
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password);
|
||||
if (sshConnection == null) {
|
||||
throw new DiscoveryException(String.format("Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed", hostIp, username, password));
|
||||
}
|
||||
|
||||
if (!SSHCmdHelper.sshExecuteCmd(sshConnection,
|
||||
"[ -f '/etc/ovs-agent/agent.ini' ]")) {
|
||||
throw new DiscoveryException(
|
||||
"Can not find /etc/ovs-agent/agent.ini " + hostIp);
|
||||
}
|
||||
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/etc/ovs-agent/agent.ini' ]")) {
|
||||
throw new DiscoveryException("Can not find /etc/ovs-agent/agent.ini " + hostIp);
|
||||
}
|
||||
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
OvmResourceBase ovmResource = new OvmResourceBase();
|
||||
details.put("ip", hostIp);
|
||||
details.put("username", username);
|
||||
details.put("password", password);
|
||||
details.put("zone", Long.toString(dcId));
|
||||
details.put("guid", guid);
|
||||
details.put("pod", Long.toString(podId));
|
||||
details.put("cluster", Long.toString(clusterId));
|
||||
details.put("agentusername", agentUsername);
|
||||
details.put("agentpassword", agentPassword);
|
||||
if (_publicNetworkDevice != null) {
|
||||
details.put("public.network.device", _publicNetworkDevice);
|
||||
}
|
||||
if (_privateNetworkDevice != null) {
|
||||
details.put("private.network.device", _privateNetworkDevice);
|
||||
}
|
||||
if (_guestNetworkDevice != null) {
|
||||
details.put("guest.network.device", _guestNetworkDevice);
|
||||
}
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
OvmResourceBase ovmResource = new OvmResourceBase();
|
||||
details.put("ip", hostIp);
|
||||
details.put("username", username);
|
||||
details.put("password", password);
|
||||
details.put("zone", Long.toString(dcId));
|
||||
details.put("guid", guid);
|
||||
details.put("pod", Long.toString(podId));
|
||||
details.put("cluster", Long.toString(clusterId));
|
||||
details.put("agentusername", agentUsername);
|
||||
details.put("agentpassword", agentPassword);
|
||||
if (_publicNetworkDevice != null) {
|
||||
details.put("public.network.device", _publicNetworkDevice);
|
||||
}
|
||||
if (_privateNetworkDevice != null) {
|
||||
details.put("private.network.device", _privateNetworkDevice);
|
||||
}
|
||||
if (_guestNetworkDevice != null) {
|
||||
details.put("guest.network.device", _guestNetworkDevice);
|
||||
}
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.putAll(details);
|
||||
ovmResource.configure("Ovm Server", params);
|
||||
ovmResource.start();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.putAll(details);
|
||||
ovmResource.configure("Ovm Server", params);
|
||||
ovmResource.start();
|
||||
|
||||
conn = new Connection(hostIp, "oracle", agentPassword);
|
||||
/* After resource start, we are able to execute our agent api */
|
||||
OvmHost.Details d = OvmHost.getDetails(conn);
|
||||
details.put("agentVersion", d.agentVersion);
|
||||
details.put(HostInfo.HOST_OS_KERNEL_VERSION, d.dom0KernelVersion);
|
||||
details.put(HostInfo.HYPERVISOR_VERSION, d.hypervisorVersion);
|
||||
conn = new Connection(hostIp, "oracle", agentPassword);
|
||||
/* After resource start, we are able to execute our agent api */
|
||||
OvmHost.Details d = OvmHost.getDetails(conn);
|
||||
details.put("agentVersion", d.agentVersion);
|
||||
details.put(HostInfo.HOST_OS_KERNEL_VERSION, d.dom0KernelVersion);
|
||||
details.put(HostInfo.HYPERVISOR_VERSION, d.hypervisorVersion);
|
||||
|
||||
Map<OvmResourceBase, Map<String, String>> resources = new HashMap<OvmResourceBase, Map<String, String>>();
|
||||
resources.put(ovmResource, details);
|
||||
return resources;
|
||||
} catch (XmlRpcException e) {
|
||||
s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url,
|
||||
e);
|
||||
return null;
|
||||
} catch (UnknownHostException e) {
|
||||
s_logger.debug(
|
||||
"Host name resolve failed exception, Unable to discover OVM: "
|
||||
+ url, e);
|
||||
return null;
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.debug(
|
||||
"Configure resource failed, Unable to discover OVM: " + url,
|
||||
e);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Unable to discover OVM: " + url, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Map<OvmResourceBase, Map<String, String>> resources = new HashMap<OvmResourceBase, Map<String, String>>();
|
||||
resources.put(ovmResource, details);
|
||||
return resources;
|
||||
} catch (XmlRpcException e) {
|
||||
s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url, e);
|
||||
return null;
|
||||
} catch (UnknownHostException e) {
|
||||
s_logger.debug("Host name resolve failed exception, Unable to discover OVM: " + url, e);
|
||||
return null;
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.debug("Configure resource failed, Unable to discover OVM: " + url, e);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Unable to discover OVM: " + url, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postDiscovery(List<HostVO> hosts, long msId)
|
||||
throws DiscoveryException {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void postDiscovery(List<HostVO> hosts, long msId) throws DiscoveryException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchHypervisor(String hypervisor) {
|
||||
return HypervisorType.Ovm.toString().equalsIgnoreCase(hypervisor);
|
||||
}
|
||||
@Override
|
||||
public boolean matchHypervisor(String hypervisor) {
|
||||
return HypervisorType.Ovm.toString().equalsIgnoreCase(hypervisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
return HypervisorType.Ovm;
|
||||
}
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
return HypervisorType.Ovm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host,
|
||||
StartupCommand[] cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForDirectConnectAgent(HostVO host,
|
||||
StartupCommand[] startup, ServerResource resource,
|
||||
Map<String, String> details, List<String> hostTags) {
|
||||
StartupCommand firstCmd = startup[0];
|
||||
if (!(firstCmd instanceof StartupRoutingCommand)) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
|
||||
StartupCommand firstCmd = startup[0];
|
||||
if (!(firstCmd instanceof StartupRoutingCommand)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
|
||||
if (ssCmd.getHypervisorType() != HypervisorType.Ovm) {
|
||||
return null;
|
||||
}
|
||||
StartupRoutingCommand ssCmd = ((StartupRoutingCommand)firstCmd);
|
||||
if (ssCmd.getHypervisorType() != HypervisorType.Ovm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Ovm,
|
||||
details, hostTags);
|
||||
}
|
||||
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Ovm, details, hostTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
|
||||
boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
if (host.getType() != com.cloud.host.Host.Type.Routing
|
||||
|| host.getHypervisorType() != HypervisorType.Ovm) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
if (host.getType() != com.cloud.host.Host.Type.Routing || host.getHypervisorType() != HypervisorType.Ovm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
|
||||
return new DeleteHostAnswer(true);
|
||||
}
|
||||
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
|
||||
return new DeleteHostAnswer(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import com.cloud.utils.db.GenericDao;
|
|||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.GenericQueryBuilder;
|
||||
|
||||
public interface UcsManagerDao extends GenericDao<UcsManagerVO, Long> {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,11 @@ import javax.ejb.Local;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.AddUcsManagerCmd;
|
||||
import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd;
|
||||
import org.apache.cloudstack.api.DeleteUcsManagerCmd;
|
||||
import org.apache.cloudstack.api.ListUcsBladeCmd;
|
||||
import org.apache.cloudstack.api.ListUcsManagerCmd;
|
||||
import org.apache.cloudstack.api.ListUcsProfileCmd;
|
||||
|
|
@ -40,8 +43,6 @@ import org.apache.cloudstack.api.response.UcsBladeResponse;
|
|||
import org.apache.cloudstack.api.response.UcsManagerResponse;
|
||||
import org.apache.cloudstack.api.response.UcsProfileResponse;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.api.DeleteUcsManagerCmd;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
|
|
@ -60,9 +61,8 @@ import com.cloud.ucs.structure.UcsCookie;
|
|||
import com.cloud.ucs.structure.UcsProfile;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.xmlobject.XmlObject;
|
||||
|
|
@ -132,8 +132,8 @@ public class UcsManagerImpl implements UcsManager {
|
|||
}
|
||||
|
||||
private void syncBlades(UcsManagerVO mgr) {
|
||||
SearchCriteriaService<UcsBladeVO, UcsBladeVO> q = SearchCriteria2.create(UcsBladeVO.class);
|
||||
q.addAnd(q.getEntity().getUcsManagerId(), Op.EQ, mgr.getId());
|
||||
QueryBuilder<UcsBladeVO> q = QueryBuilder.create(UcsBladeVO.class);
|
||||
q.and(q.entity().getUcsManagerId(), Op.EQ, mgr.getId());
|
||||
List<UcsBladeVO> pblades = q.list();
|
||||
if (pblades.isEmpty()) {
|
||||
return;
|
||||
|
|
@ -210,8 +210,8 @@ public class UcsManagerImpl implements UcsManager {
|
|||
@Override
|
||||
@DB
|
||||
public UcsManagerResponse addUcsManager(AddUcsManagerCmd cmd) {
|
||||
SearchCriteriaService<UcsManagerVO, UcsManagerVO> q = SearchCriteria2.create(UcsManagerVO.class);
|
||||
q.addAnd(q.getEntity().getUrl(), Op.EQ, cmd.getUrl());
|
||||
QueryBuilder<UcsManagerVO> q = QueryBuilder.create(UcsManagerVO.class);
|
||||
q.and(q.entity().getUrl(), Op.EQ, cmd.getUrl());
|
||||
UcsManagerVO mgrvo = q.find();
|
||||
if (mgrvo != null) {
|
||||
throw new IllegalArgumentException(String.format("duplicate UCS manager. url[%s] is used by another UCS manager already", cmd.getUrl()));
|
||||
|
|
@ -342,9 +342,9 @@ public class UcsManagerImpl implements UcsManager {
|
|||
|
||||
@Override
|
||||
public UcsBladeResponse associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd) {
|
||||
SearchCriteriaService<UcsBladeVO, UcsBladeVO> q = SearchCriteria2.create(UcsBladeVO.class);
|
||||
q.addAnd(q.getEntity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
|
||||
q.addAnd(q.getEntity().getId(), Op.EQ, cmd.getBladeId());
|
||||
QueryBuilder<UcsBladeVO> q = QueryBuilder.create(UcsBladeVO.class);
|
||||
q.and(q.entity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
|
||||
q.and(q.entity().getId(), Op.EQ, cmd.getBladeId());
|
||||
UcsBladeVO bvo = q.find();
|
||||
if (bvo == null) {
|
||||
throw new IllegalArgumentException(String.format("cannot find UCS blade[id:%s, ucs manager id:%s]", cmd.getBladeId(), cmd.getUcsManagerId()));
|
||||
|
|
@ -424,8 +424,8 @@ public class UcsManagerImpl implements UcsManager {
|
|||
return response;
|
||||
}
|
||||
|
||||
SearchCriteriaService<UcsManagerVO, UcsManagerVO> serv = SearchCriteria2.create(UcsManagerVO.class);
|
||||
serv.addAnd(serv.getEntity().getZoneId(), Op.EQ, cmd.getZoneId());
|
||||
QueryBuilder<UcsManagerVO> serv = QueryBuilder.create(UcsManagerVO.class);
|
||||
serv.and(serv.entity().getZoneId(), Op.EQ, cmd.getZoneId());
|
||||
List<UcsManagerVO> vos = serv.list();
|
||||
|
||||
for (UcsManagerVO vo : vos) {
|
||||
|
|
@ -454,8 +454,8 @@ public class UcsManagerImpl implements UcsManager {
|
|||
|
||||
@Override
|
||||
public ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd) {
|
||||
SearchCriteriaService<UcsBladeVO, UcsBladeVO> serv = SearchCriteria2.create(UcsBladeVO.class);
|
||||
serv.addAnd(serv.getEntity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
|
||||
QueryBuilder<UcsBladeVO> serv = QueryBuilder.create(UcsBladeVO.class);
|
||||
serv.and(serv.entity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
|
||||
List<UcsBladeVO> vos = serv.list();
|
||||
|
||||
List<UcsBladeResponse> rsps = new ArrayList<UcsBladeResponse>(vos.size());
|
||||
|
|
@ -509,8 +509,8 @@ public class UcsManagerImpl implements UcsManager {
|
|||
|
||||
@Override
|
||||
public void deleteUcsManager(Long id) {
|
||||
SearchCriteriaService<UcsBladeVO, UcsBladeVO> serv = SearchCriteria2.create(UcsBladeVO.class);
|
||||
serv.addAnd(serv.getEntity().getUcsManagerId(), Op.EQ, id);
|
||||
QueryBuilder<UcsBladeVO> serv = QueryBuilder.create(UcsBladeVO.class);
|
||||
serv.and(serv.entity().getUcsManagerId(), Op.EQ, id);
|
||||
List<UcsBladeVO> vos = serv.list();
|
||||
for (UcsBladeVO vo : vos) {
|
||||
bladeDao.remove(vo.getId());
|
||||
|
|
|
|||
|
|
@ -16,6 +16,31 @@
|
|||
// under the License.
|
||||
package com.cloud.hypervisor.xen.discoverer;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.persistence.EntityExistsException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
|
||||
import com.xensource.xenapi.Connection;
|
||||
import com.xensource.xenapi.Host;
|
||||
import com.xensource.xenapi.Pool;
|
||||
import com.xensource.xenapi.Session;
|
||||
import com.xensource.xenapi.Types.SessionAuthenticationFailed;
|
||||
import com.xensource.xenapi.Types.XenAPIException;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.Listener;
|
||||
import com.cloud.agent.api.AgentControlAnswer;
|
||||
|
|
@ -69,33 +94,10 @@ import com.cloud.storage.VMTemplateVO;
|
|||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.exception.HypervisorVersionChangedException;
|
||||
import com.xensource.xenapi.Connection;
|
||||
import com.xensource.xenapi.Host;
|
||||
import com.xensource.xenapi.Pool;
|
||||
import com.xensource.xenapi.Session;
|
||||
import com.xensource.xenapi.Types.SessionAuthenticationFailed;
|
||||
import com.xensource.xenapi.Types.XenAPIException;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.persistence.EntityExistsException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
@Local(value=Discoverer.class)
|
||||
public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
|
||||
|
|
@ -126,8 +128,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
|
|||
try {
|
||||
_clusterDao.update(cluster.getId(), cluster);
|
||||
} catch (EntityExistsException e) {
|
||||
SearchCriteriaService<ClusterVO, ClusterVO> sc = SearchCriteria2.create(ClusterVO.class);
|
||||
sc.addAnd(sc.getEntity().getGuid(), Op.EQ, guid);
|
||||
QueryBuilder<ClusterVO> sc = QueryBuilder.create(ClusterVO.class);
|
||||
sc.and(sc.entity().getGuid(), Op.EQ, guid);
|
||||
List<ClusterVO> clusters = sc.list();
|
||||
ClusterVO clu = clusters.get(0);
|
||||
List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clu.getId());
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ import com.cloud.network.NetworkModel;
|
|||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.IPAddressVO;
|
||||
|
|
@ -506,7 +506,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
|
|||
if (provider == null) {
|
||||
throw new CloudRuntimeException("Cannot find service provider " + typeString + " in physical network " + physicalNetworkId);
|
||||
}
|
||||
VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), VirtualRouterProviderType.ElasticLoadBalancerVm);
|
||||
VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), Type.ElasticLoadBalancerVm);
|
||||
if (vrProvider == null) {
|
||||
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ import com.cloud.network.Networks.TrafficType;
|
|||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.dao.NetworkServiceMapDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
|
||||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
|
|
@ -73,9 +73,8 @@ import com.cloud.user.AccountManager;
|
|||
import com.cloud.user.User;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
|
|
@ -270,7 +269,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
@Override
|
||||
public boolean isReady(PhysicalNetworkServiceProvider provider) {
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
|
||||
VirtualRouterProviderType.InternalLbVm);
|
||||
Type.InternalLbVm);
|
||||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -282,7 +281,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
|
||||
VirtualRouterProviderType.InternalLbVm);
|
||||
Type.InternalLbVm);
|
||||
if (element == null) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -467,7 +466,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
@Override
|
||||
public VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable) {
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findById(id);
|
||||
if (element == null || element.getType() != VirtualRouterProviderType.InternalLbVm) {
|
||||
if (element == null || element.getType() != Type.InternalLbVm) {
|
||||
throw new InvalidParameterValueException("Can't find " + getName() + " element with network service provider id " + id +
|
||||
" to be used as a provider for " + getName());
|
||||
}
|
||||
|
|
@ -480,7 +479,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
|
||||
@Override
|
||||
public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) {
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, VirtualRouterProviderType.InternalLbVm);
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, Type.InternalLbVm);
|
||||
if (element != null) {
|
||||
s_logger.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId);
|
||||
return null;
|
||||
|
|
@ -491,7 +490,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
throw new InvalidParameterValueException("Invalid network service provider is specified");
|
||||
}
|
||||
|
||||
element = new VirtualRouterProviderVO(ntwkSvcProviderId, VirtualRouterProviderType.InternalLbVm);
|
||||
element = new VirtualRouterProviderVO(ntwkSvcProviderId, Type.InternalLbVm);
|
||||
element = _vrProviderDao.persist(element);
|
||||
return element;
|
||||
}
|
||||
|
|
@ -500,7 +499,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
@Override
|
||||
public VirtualRouterProvider getInternalLoadBalancerElement(long id) {
|
||||
VirtualRouterProvider provider = _vrProviderDao.findById(id);
|
||||
if (provider == null || provider.getType() != VirtualRouterProviderType.InternalLbVm) {
|
||||
if (provider == null || provider.getType() != Type.InternalLbVm) {
|
||||
throw new InvalidParameterValueException("Unable to find " + getName() + " by id");
|
||||
}
|
||||
return provider;
|
||||
|
|
@ -509,19 +508,19 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
@Override
|
||||
public List<? extends VirtualRouterProvider> searchForInternalLoadBalancerElements(Long id, Long ntwkSvsProviderId, Boolean enabled) {
|
||||
|
||||
SearchCriteriaService<VirtualRouterProviderVO, VirtualRouterProviderVO> sc = SearchCriteria2.create(VirtualRouterProviderVO.class);
|
||||
QueryBuilder<VirtualRouterProviderVO> sc = QueryBuilder.create(VirtualRouterProviderVO.class);
|
||||
if (id != null) {
|
||||
sc.addAnd(sc.getEntity().getId(), Op.EQ, id);
|
||||
sc.and(sc.entity().getId(), Op.EQ, id);
|
||||
}
|
||||
if (ntwkSvsProviderId != null) {
|
||||
sc.addAnd(sc.getEntity().getNspId(), Op.EQ, ntwkSvsProviderId);
|
||||
sc.and(sc.entity().getNspId(), Op.EQ, ntwkSvsProviderId);
|
||||
}
|
||||
if (enabled != null) {
|
||||
sc.addAnd(sc.getEntity().isEnabled(), Op.EQ, enabled);
|
||||
sc.and(sc.entity().isEnabled(), Op.EQ, enabled);
|
||||
}
|
||||
|
||||
//return only Internal LB elements
|
||||
sc.addAnd(sc.getEntity().getType(), Op.EQ, VirtualRouterProvider.VirtualRouterProviderType.InternalLbVm);
|
||||
sc.and(sc.entity().getType(), Op.EQ, VirtualRouterProvider.Type.InternalLbVm);
|
||||
|
||||
return sc.list();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ import com.cloud.network.NetworkModel;
|
|||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
|
||||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
|
|
@ -310,7 +310,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
|
|||
|
||||
VirtualRouterProvider lbProvider = _vrProviderDao.findById(internalLbVm.getElementId());
|
||||
if (lbProvider == null) {
|
||||
throw new CloudRuntimeException("Cannot find related element " + VirtualRouterProviderType.InternalLbVm + " of vm: " + internalLbVm.getHostName());
|
||||
throw new CloudRuntimeException("Cannot find related element " + Type.InternalLbVm + " of vm: " + internalLbVm.getHostName());
|
||||
}
|
||||
|
||||
Provider provider = Network.Provider.getProvider(lbProvider.getType().toString());
|
||||
|
|
@ -629,7 +629,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
|
|||
}
|
||||
|
||||
protected long getInternalLbProviderId(Network guestNetwork) {
|
||||
VirtualRouterProviderType type = VirtualRouterProviderType.InternalLbVm;
|
||||
Type type = Type.InternalLbVm;
|
||||
long physicalNetworkId = _ntwkModel.getPhysicalNetworkId(guestNetwork);
|
||||
|
||||
PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
|
||||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
|
|
@ -65,15 +65,15 @@ public class InternalLbElementServiceTest {
|
|||
public void setUp() {
|
||||
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
|
||||
VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.VirtualRouter);
|
||||
VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, Type.InternalLbVm);
|
||||
VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, Type.VirtualRouter);
|
||||
|
||||
Mockito.when(_vrProviderDao.findById(validElId)).thenReturn(validElement);
|
||||
Mockito.when(_vrProviderDao.findById(invalidElId)).thenReturn(invalidElement);
|
||||
|
||||
Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
|
||||
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, Type.InternalLbVm)).thenReturn(validElement);
|
||||
|
||||
PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
|
||||
PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ import com.cloud.dc.DataCenterVO;
|
|||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
|
||||
|
|
@ -91,18 +91,18 @@ public class InternalLbElementTest {
|
|||
public void setUp() {
|
||||
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
|
||||
VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, Type.InternalLbVm);
|
||||
validElement.setEnabled(true);
|
||||
VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.VirtualRouter);
|
||||
VirtualRouterProviderVO notEnabledElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
|
||||
VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, Type.VirtualRouter);
|
||||
VirtualRouterProviderVO notEnabledElement = new VirtualRouterProviderVO(1, Type.InternalLbVm);
|
||||
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(validElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(invalidElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(invalidElement);
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(notEnabledElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(notEnabledElement);
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(validElId, Type.InternalLbVm)).thenReturn(validElement);
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(invalidElId, Type.InternalLbVm)).thenReturn(invalidElement);
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(notEnabledElId, Type.InternalLbVm)).thenReturn(notEnabledElement);
|
||||
|
||||
Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
|
||||
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
|
||||
Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, Type.InternalLbVm)).thenReturn(validElement);
|
||||
|
||||
PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
|
||||
PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package org.apache.cloudstack.ldap;
|
|||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -47,15 +46,6 @@ public class LdapAuthenticator extends DefaultUserAuthenticator {
|
|||
_userAccountDao = userAccountDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
if (name == null) {
|
||||
name = "LDAP";
|
||||
}
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authenticate(final String username, final String password,
|
||||
final Long domainId, final Map<String, Object[]> requestParameters) {
|
||||
|
|
|
|||
|
|
@ -22,12 +22,11 @@ import java.util.Map;
|
|||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.UserAccount;
|
||||
import com.cloud.user.dao.UserAccountDao;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
|
|
@ -59,17 +58,6 @@ public class MD5UserAuthenticator extends DefaultUserAuthenticator {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
if(name == null) {
|
||||
name = "MD5";
|
||||
}
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encode(String password) {
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -15,20 +15,15 @@
|
|||
|
||||
package com.cloud.server.auth;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.UserAccount;
|
||||
import com.cloud.user.dao.UserAccountDao;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
|
||||
@Local(value={UserAuthenticator.class})
|
||||
|
|
@ -56,16 +51,6 @@ public class PlainTextUserAuthenticator extends DefaultUserAuthenticator {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
if (name == null) {
|
||||
name = "PLAINTEXT";
|
||||
}
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encode(String password) {
|
||||
// Plaintext so no encoding at all
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import java.util.Map;
|
|||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
|
|
@ -42,16 +41,6 @@ public class SHA256SaltedUserAuthenticator extends DefaultUserAuthenticator {
|
|||
private UserAccountDao _userAccountDao;
|
||||
private static final int s_saltlen = 32;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
if (name == null) {
|
||||
name = "SHA256SALT";
|
||||
}
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.server.auth.UserAuthenticator#authenticate(java.lang.String, java.lang.String, java.lang.Long, java.util.Map)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2681,8 +2681,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
@Override
|
||||
public VirtualRouterProviderResponse createVirtualRouterProviderResponse(VirtualRouterProvider result) {
|
||||
//generate only response of the VR/VPCVR provider type
|
||||
if (!(result.getType() == VirtualRouterProvider.VirtualRouterProviderType.VirtualRouter
|
||||
|| result.getType() == VirtualRouterProvider.VirtualRouterProviderType.VPCVirtualRouter)) {
|
||||
if (!(result.getType() == VirtualRouterProvider.Type.VirtualRouter
|
||||
|| result.getType() == VirtualRouterProvider.Type.VPCVirtualRouter)) {
|
||||
return null;
|
||||
}
|
||||
VirtualRouterProviderResponse response = new VirtualRouterProviderResponse();
|
||||
|
|
@ -3734,7 +3734,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
@Override
|
||||
public InternalLoadBalancerElementResponse createInternalLbElementResponse(VirtualRouterProvider result) {
|
||||
if (result.getType() != VirtualRouterProvider.VirtualRouterProviderType.InternalLbVm) {
|
||||
if (result.getType() != VirtualRouterProvider.Type.InternalLbVm) {
|
||||
return null;
|
||||
}
|
||||
InternalLoadBalancerElementResponse response = new InternalLoadBalancerElementResponse();
|
||||
|
|
|
|||
|
|
@ -169,8 +169,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
|
|||
@Inject
|
||||
private EntityManager _entityMgr;
|
||||
|
||||
@Inject List<PluggableService> _pluggableServices;
|
||||
@Inject List<APIChecker> _apiAccessCheckers;
|
||||
List<PluggableService> _pluggableServices;
|
||||
List<APIChecker> _apiAccessCheckers;
|
||||
|
||||
@Inject
|
||||
protected ApiAsyncJobDispatcher _asyncDispatcher;
|
||||
|
|
@ -1096,4 +1096,22 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
|
|||
}
|
||||
return responseText;
|
||||
}
|
||||
|
||||
public List<PluggableService> getPluggableServices() {
|
||||
return _pluggableServices;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setPluggableServices(List<PluggableService> _pluggableServices) {
|
||||
this._pluggableServices = _pluggableServices;
|
||||
}
|
||||
|
||||
public List<APIChecker> getApiAccessCheckers() {
|
||||
return _apiAccessCheckers;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setApiAccessCheckers(List<APIChecker> _apiAccessCheckers) {
|
||||
this._apiAccessCheckers = _apiAccessCheckers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,20 +21,17 @@ import java.util.List;
|
|||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.api.response.DiskOfferingResponse;
|
||||
|
||||
import com.cloud.api.query.vo.DiskOfferingJoinVO;
|
||||
import org.apache.cloudstack.api.response.DiskOfferingResponse;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.DiskOfferingVO.Type;
|
||||
import com.cloud.utils.db.Attribute;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Local(value={DiskOfferingJoinDao.class})
|
||||
|
|
@ -42,7 +39,7 @@ public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO,
|
|||
public static final Logger s_logger = Logger.getLogger(DiskOfferingJoinDaoImpl.class);
|
||||
|
||||
|
||||
private SearchBuilder<DiskOfferingJoinVO> dofIdSearch;
|
||||
private final SearchBuilder<DiskOfferingJoinVO> dofIdSearch;
|
||||
private final Attribute _typeAttr;
|
||||
|
||||
protected DiskOfferingJoinDaoImpl() {
|
||||
|
|
@ -53,7 +50,7 @@ public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO,
|
|||
|
||||
_typeAttr = _allAttributes.get("type");
|
||||
|
||||
this._count = "select count(distinct id) from disk_offering_view WHERE ";
|
||||
_count = "select count(distinct id) from disk_offering_view WHERE ";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -96,16 +93,4 @@ public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO,
|
|||
assert offerings != null && offerings.size() == 1 : "No disk offering found for offering id " + offering.getId();
|
||||
return offerings.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DiskOfferingJoinVO> searchIncludingRemoved(SearchCriteria<DiskOfferingJoinVO> sc, final Filter filter, final Boolean lock, final boolean cache) {
|
||||
sc.addAnd(_typeAttr, Op.EQ, Type.Disk);
|
||||
return super.searchIncludingRemoved(sc, filter, lock, cache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> List<K> customSearchIncludingRemoved(SearchCriteria<K> sc, final Filter filter) {
|
||||
sc.addAnd(_typeAttr, Op.EQ, Type.Disk);
|
||||
return super.customSearchIncludingRemoved(sc, filter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,7 +250,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
@Inject
|
||||
AlertManager _alertMgr;
|
||||
// @com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
|
||||
@Inject
|
||||
List<SecurityChecker> _secChecker;
|
||||
|
||||
@Inject
|
||||
|
|
@ -4934,5 +4933,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
return false;
|
||||
}
|
||||
|
||||
public List<SecurityChecker> getSecChecker() {
|
||||
return _secChecker;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSecChecker(List<SecurityChecker> secChecker) {
|
||||
this._secChecker = secChecker;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,9 +117,8 @@ import com.cloud.utils.Pair;
|
|||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.events.SubscriptionMgr;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
|
@ -167,7 +166,6 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
|
|||
|
||||
private int _mgmt_port = 8250;
|
||||
|
||||
@Inject
|
||||
private List<ConsoleProxyAllocator> _consoleProxyAllocators;
|
||||
|
||||
@Inject
|
||||
|
|
@ -1693,9 +1691,9 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
|
|||
}
|
||||
|
||||
protected HostVO findConsoleProxyHostByName(String name) {
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.ConsoleProxy);
|
||||
sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getType(), Op.EQ, Host.Type.ConsoleProxy);
|
||||
sc.and(sc.entity().getName(), Op.EQ, name);
|
||||
return sc.find();
|
||||
}
|
||||
|
||||
|
|
@ -1703,4 +1701,13 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
|
|||
public void prepareStop(VirtualMachineProfile profile) {
|
||||
}
|
||||
|
||||
public List<ConsoleProxyAllocator> getConsoleProxyAllocators() {
|
||||
return _consoleProxyAllocators;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setConsoleProxyAllocators(List<ConsoleProxyAllocator> consoleProxyAllocators) {
|
||||
this._consoleProxyAllocators = consoleProxyAllocators;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
|
|
@ -38,16 +37,15 @@ import com.cloud.host.Status;
|
|||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
|
||||
public abstract class AbstractInvestigatorImpl extends AdapterBase implements Investigator {
|
||||
private static final Logger s_logger = Logger.getLogger(AbstractInvestigatorImpl.class);
|
||||
|
||||
@Inject private HostDao _hostDao = null;
|
||||
@Inject private AgentManager _agentMgr = null;
|
||||
@Inject private ResourceManager _resourceMgr = null;
|
||||
@Inject private final HostDao _hostDao = null;
|
||||
@Inject private final AgentManager _agentMgr = null;
|
||||
@Inject private final ResourceManager _resourceMgr = null;
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -68,10 +66,10 @@ public abstract class AbstractInvestigatorImpl extends AdapterBase implements In
|
|||
|
||||
// Host.status is up and Host.type is routing
|
||||
protected List<Long> findHostByPod(long podId, Long excludeHostId) {
|
||||
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
|
||||
sc.addAnd(sc.getEntity().getType(), Op.EQ, Type.Routing);
|
||||
sc.addAnd(sc.getEntity().getPodId(), Op.EQ, podId);
|
||||
sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
|
||||
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
|
||||
sc.and(sc.entity().getType(), Op.EQ, Type.Routing);
|
||||
sc.and(sc.entity().getPodId(), Op.EQ, podId);
|
||||
sc.and(sc.entity().getStatus(), Op.EQ, Status.Up);
|
||||
List<HostVO> hosts = sc.list();
|
||||
|
||||
List<Long> hostIds = new ArrayList<Long>(hosts.size());
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.hypervisor;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
|
|
@ -26,6 +27,7 @@ import javax.inject.Inject;
|
|||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -43,8 +45,8 @@ public class HypervisorGuruManagerImpl extends ManagerBase implements Hypervisor
|
|||
|
||||
@Inject HostDao _hostDao;
|
||||
|
||||
@Inject List<HypervisorGuru> _hvGuruList;
|
||||
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
|
||||
List<HypervisorGuru> _hvGuruList;
|
||||
Map<HypervisorType, HypervisorGuru> _hvGurus = new ConcurrentHashMap<HypervisorType, HypervisorGuru>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
|
@ -55,7 +57,19 @@ public class HypervisorGuruManagerImpl extends ManagerBase implements Hypervisor
|
|||
|
||||
@Override
|
||||
public HypervisorGuru getGuru(HypervisorType hypervisorType) {
|
||||
return _hvGurus.get(hypervisorType);
|
||||
HypervisorGuru result = _hvGurus.get(hypervisorType);
|
||||
|
||||
if ( result == null ) {
|
||||
for ( HypervisorGuru guru : _hvGuruList ) {
|
||||
if ( guru.getHypervisorType() == hypervisorType ) {
|
||||
_hvGurus.put(hypervisorType, guru);
|
||||
result = guru;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -68,4 +82,14 @@ public class HypervisorGuruManagerImpl extends ManagerBase implements Hypervisor
|
|||
}
|
||||
return hostId;
|
||||
}
|
||||
|
||||
public List<HypervisorGuru> getHvGuruList() {
|
||||
return _hvGuruList;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setHvGuruList(List<HypervisorGuru> hvGuruList) {
|
||||
this._hvGuruList = hvGuruList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ import com.cloud.network.Network.Service;
|
|||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetwork.BroadcastDomainRange;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.AccountGuestVlanMapDao;
|
||||
import com.cloud.network.dao.AccountGuestVlanMapVO;
|
||||
|
|
@ -230,7 +230,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
@Inject
|
||||
UsageEventDao _usageEventDao;
|
||||
|
||||
@Inject List<NetworkGuru> _networkGurus;
|
||||
List<NetworkGuru> _networkGurus;
|
||||
|
||||
@Inject
|
||||
NetworkDomainDao _networkDomainDao;
|
||||
|
|
@ -3685,7 +3685,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
}
|
||||
|
||||
VirtualRouterElement element = (VirtualRouterElement)networkElement;
|
||||
element.addElement(nsp.getId(), VirtualRouterProviderType.VirtualRouter);
|
||||
element.addElement(nsp.getId(), Type.VirtualRouter);
|
||||
|
||||
return nsp;
|
||||
}
|
||||
|
|
@ -3701,7 +3701,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
}
|
||||
|
||||
VpcVirtualRouterElement element = (VpcVirtualRouterElement)networkElement;
|
||||
element.addElement(nsp.getId(), VirtualRouterProviderType.VPCVirtualRouter);
|
||||
element.addElement(nsp.getId(), Type.VPCVirtualRouter);
|
||||
|
||||
return nsp;
|
||||
}
|
||||
|
|
@ -3944,4 +3944,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
return _networkMgr.listVmNics(vmId, nicId);
|
||||
}
|
||||
|
||||
public List<NetworkGuru> getNetworkGurus() {
|
||||
return _networkGurus;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setNetworkGurus(List<NetworkGuru> networkGurus) {
|
||||
this._networkGurus = networkGurus;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,18 +20,17 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.api.command.admin.network.CreateStorageNetworkIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.DeleteStorageNetworkIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.ListStorageNetworkIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.UpdateStorageNetworkIpRangeCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.StorageNetworkIpAddressVO;
|
||||
|
|
@ -46,9 +45,8 @@ import com.cloud.network.dao.NetworkDao;
|
|||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
|
@ -339,8 +337,8 @@ public class StorageNetworkManagerImpl extends ManagerBase implements StorageNet
|
|||
|
||||
@Override
|
||||
public boolean isStorageIpRangeAvailable(long zoneId) {
|
||||
SearchCriteriaService<StorageNetworkIpRangeVO, StorageNetworkIpRangeVO> sc = SearchCriteria2.create(StorageNetworkIpRangeVO.class);
|
||||
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, zoneId);
|
||||
QueryBuilder<StorageNetworkIpRangeVO> sc = QueryBuilder.create(StorageNetworkIpRangeVO.class);
|
||||
sc.and(sc.entity().getDataCenterId(), Op.EQ, zoneId);
|
||||
List<StorageNetworkIpRangeVO> entries = sc.list();
|
||||
return entries.size() > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
|
|
@ -25,13 +25,15 @@ import java.util.Set;
|
|||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.dc.DataCenter;
|
||||
|
|
@ -55,7 +57,7 @@ import com.cloud.network.PhysicalNetworkServiceProvider;
|
|||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.RemoteAccessVpn;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VirtualRouterProvider.Type;
|
||||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
|
|
@ -77,12 +79,10 @@ import com.cloud.offering.NetworkOffering;
|
|||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
|
@ -91,19 +91,16 @@ import com.cloud.vm.UserVmManager;
|
|||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
|
||||
DhcpServiceProvider.class, UserDataServiceProvider.class,
|
||||
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
|
||||
DhcpServiceProvider.class, UserDataServiceProvider.class,
|
||||
StaticNatServiceProvider.class, LoadBalancingServiceProvider.class,
|
||||
PortForwardingServiceProvider.class, IpDeployer.class,
|
||||
RemoteAccessVPNServiceProvider.class, NetworkMigrationResponder.class} )
|
||||
public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider,
|
||||
public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider,
|
||||
UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider,
|
||||
LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer,
|
||||
NetworkMigrationResponder {
|
||||
|
|
@ -166,7 +163,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
} else {
|
||||
if (!_networkMgr.isProviderSupportServiceInNetwork(network.getId(), service, getProvider())) {
|
||||
s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName()
|
||||
s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName()
|
||||
+ " in the network " + network);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -187,19 +184,19 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
|
||||
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest,
|
||||
_accountMgr.getAccount(network.getAccountId()), params,
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest,
|
||||
_accountMgr.getAccount(network.getAccountId()), params,
|
||||
offering.getRedundantRouter());
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!",
|
||||
DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm,
|
||||
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm,
|
||||
DeployDestination dest, ReservationContext context)
|
||||
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
if (vm.getType() != VirtualMachine.Type.User || vm.getHypervisorType() == HypervisorType.BareMetal) {
|
||||
|
|
@ -219,15 +216,15 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = (VirtualMachineProfile) vm;
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest,
|
||||
VirtualMachineProfile uservm = vm;
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest,
|
||||
_accountMgr.getAccount(network.getAccountId()),
|
||||
uservm.getParameters(), offering.getRedundantRouter());
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!",
|
||||
DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -306,11 +303,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
expire = value;
|
||||
}
|
||||
if ((expire != null) && !containsOnlyNumbers(expire, timeEndChar)) {
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
" Cause: expire is not in timeformat: " + expire);
|
||||
}
|
||||
if ((tablesize != null) && !containsOnlyNumbers(tablesize, "kmg")) {
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
" Cause: tablesize is not in size format: " + tablesize);
|
||||
|
||||
}
|
||||
|
|
@ -337,11 +334,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
if ((length != null) && (!containsOnlyNumbers(length, null))) {
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
" Cause: length is not a number: " + length);
|
||||
}
|
||||
if ((holdTime != null) && (!containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null))) {
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() +
|
||||
" Cause: holdtime is not in timeformat: " + holdTime);
|
||||
}
|
||||
}
|
||||
|
|
@ -400,7 +397,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
return _routerMgr.applyVpnUsers(network, users, routers);
|
||||
} else {
|
||||
s_logger.debug("Element " + this.getName() + " doesn't handle applyVpnUsers command");
|
||||
s_logger.debug("Element " + getName() + " doesn't handle applyVpnUsers command");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -416,7 +413,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
return _routerMgr.startRemoteAccessVpn(network, vpn, routers);
|
||||
} else {
|
||||
s_logger.debug("Element " + this.getName() + " doesn't handle createVpn command");
|
||||
s_logger.debug("Element " + getName() + " doesn't handle createVpn command");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -432,13 +429,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
return _routerMgr.deleteRemoteAccessVpn(network, vpn, routers);
|
||||
} else {
|
||||
s_logger.debug("Element " + this.getName() + " doesn't handle removeVpn command");
|
||||
s_logger.debug("Element " + getName() + " doesn't handle removeVpn command");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services)
|
||||
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services)
|
||||
throws ResourceUnavailableException {
|
||||
boolean canHandle = true;
|
||||
for (Service service : services) {
|
||||
|
|
@ -636,7 +633,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shutdown(Network network, ReservationContext context, boolean cleanup)
|
||||
public boolean shutdown(Network network, ReservationContext context, boolean cleanup)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
|
|
@ -672,7 +669,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm)
|
||||
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm)
|
||||
throws ResourceUnavailableException {
|
||||
if (!canHandle(network, null)) {
|
||||
return false;
|
||||
|
|
@ -684,7 +681,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = (VirtualMachineProfile) vm;
|
||||
VirtualMachineProfile uservm = vm;
|
||||
|
||||
return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
|
||||
}
|
||||
|
|
@ -702,7 +699,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = (VirtualMachineProfile) vm;
|
||||
VirtualMachineProfile uservm = vm;
|
||||
|
||||
return _routerMgr.saveSSHPublicKeyToRouter(network, nic, uservm, routers, SSHPublicKey);
|
||||
}
|
||||
|
|
@ -720,7 +717,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = (VirtualMachineProfile) vm;
|
||||
VirtualMachineProfile uservm = vm;
|
||||
|
||||
return _routerMgr.saveUserDataToRouter(network, nic, uservm, routers);
|
||||
}
|
||||
|
|
@ -737,7 +734,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
@Override
|
||||
public VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd) {
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findById(cmd.getId());
|
||||
if (element == null || !(element.getType() == VirtualRouterProviderType.VirtualRouter || element.getType() == VirtualRouterProviderType.VPCVirtualRouter)) {
|
||||
if (element == null || !(element.getType() == Type.VirtualRouter || element.getType() == Type.VPCVirtualRouter)) {
|
||||
s_logger.debug("Can't find Virtual Router element with network service provider id " + cmd.getId());
|
||||
return null;
|
||||
}
|
||||
|
|
@ -749,10 +746,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType) {
|
||||
if (!(providerType == VirtualRouterProviderType.VirtualRouter || providerType == VirtualRouterProviderType.VPCVirtualRouter)) {
|
||||
throw new InvalidParameterValueException("Element " + this.getName() + " supports only providerTypes: " +
|
||||
VirtualRouterProviderType.VirtualRouter.toString() + " and " + VirtualRouterProviderType.VPCVirtualRouter);
|
||||
public VirtualRouterProvider addElement(Long nspId, Type providerType) {
|
||||
if (!(providerType == Type.VirtualRouter || providerType == Type.VPCVirtualRouter)) {
|
||||
throw new InvalidParameterValueException("Element " + getName() + " supports only providerTypes: " +
|
||||
Type.VirtualRouter.toString() + " and " + Type.VPCVirtualRouter);
|
||||
}
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, providerType);
|
||||
if (element != null) {
|
||||
|
|
@ -786,7 +783,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
|
||||
@Override
|
||||
public boolean isReady(PhysicalNetworkServiceProvider provider) {
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
|
||||
getVirtualRouterProvider());
|
||||
if (element == null) {
|
||||
return false;
|
||||
|
|
@ -795,10 +792,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context)
|
||||
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context)
|
||||
throws ConcurrentOperationException,
|
||||
ResourceUnavailableException {
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
|
||||
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
|
||||
getVirtualRouterProvider());
|
||||
if (element == null) {
|
||||
return true;
|
||||
|
|
@ -821,14 +818,14 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
public Long getIdByNspId(Long nspId) {
|
||||
VirtualRouterProviderVO vr = _vrProviderDao.findByNspIdAndType(nspId, VirtualRouterProviderType.VirtualRouter);
|
||||
VirtualRouterProviderVO vr = _vrProviderDao.findByNspIdAndType(nspId, Type.VirtualRouter);
|
||||
return vr.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouterProvider getCreatedElement(long id) {
|
||||
VirtualRouterProvider provider = _vrProviderDao.findById(id);
|
||||
if (!(provider.getType() == VirtualRouterProviderType.VirtualRouter || provider.getType() == VirtualRouterProviderType.VPCVirtualRouter)) {
|
||||
if (!(provider.getType() == Type.VirtualRouter || provider.getType() == Type.VPCVirtualRouter)) {
|
||||
throw new InvalidParameterValueException("Unable to find provider by id");
|
||||
}
|
||||
return provider;
|
||||
|
|
@ -849,7 +846,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = (VirtualMachineProfile) vm;
|
||||
VirtualMachineProfile uservm = vm;
|
||||
|
||||
List<DomainRouterVO> routers = getRouters(network, dest);
|
||||
|
||||
|
|
@ -880,7 +877,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm,
|
||||
public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm,
|
||||
DeployDestination dest, ReservationContext context)
|
||||
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
if (canHandle(network, Service.Dhcp)) {
|
||||
|
|
@ -889,7 +886,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = (VirtualMachineProfile) vm;
|
||||
VirtualMachineProfile uservm = vm;
|
||||
|
||||
List<DomainRouterVO> routers = getRouters(network, dest);
|
||||
|
||||
|
|
@ -917,7 +914,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile uservm = (VirtualMachineProfile) vm;
|
||||
VirtualMachineProfile uservm = vm;
|
||||
|
||||
List<DomainRouterVO> routers = getRouters(network, dest);
|
||||
|
||||
|
|
@ -935,7 +932,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
|
||||
publicNetwork = true;
|
||||
}
|
||||
boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic
|
||||
boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic
|
||||
|| _networkMgr.isSecurityGroupSupportedInNetwork(network)) &&
|
||||
network.getTrafficType() == TrafficType.Guest;
|
||||
|
||||
|
|
@ -969,19 +966,19 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
Long nspId = cmd.getNspId();
|
||||
Boolean enabled = cmd.getEnabled();
|
||||
|
||||
SearchCriteriaService<VirtualRouterProviderVO, VirtualRouterProviderVO> sc = SearchCriteria2.create(VirtualRouterProviderVO.class);
|
||||
QueryBuilder<VirtualRouterProviderVO> sc = QueryBuilder.create(VirtualRouterProviderVO.class);
|
||||
if (id != null) {
|
||||
sc.addAnd(sc.getEntity().getId(), Op.EQ, id);
|
||||
sc.and(sc.entity().getId(), Op.EQ, id);
|
||||
}
|
||||
if (nspId != null) {
|
||||
sc.addAnd(sc.getEntity().getNspId(), Op.EQ, nspId);
|
||||
sc.and(sc.entity().getNspId(), Op.EQ, nspId);
|
||||
}
|
||||
if (enabled != null) {
|
||||
sc.addAnd(sc.getEntity().isEnabled(), Op.EQ, enabled);
|
||||
sc.and(sc.entity().isEnabled(), Op.EQ, enabled);
|
||||
}
|
||||
|
||||
//return only VR and VPC VR
|
||||
sc.addAnd(sc.getEntity().getType(), Op.IN, VirtualRouterProvider.VirtualRouterProviderType.VPCVirtualRouter, VirtualRouterProvider.VirtualRouterProviderType.VirtualRouter);
|
||||
sc.and(sc.entity().getType(), Op.IN, VirtualRouterProvider.Type.VPCVirtualRouter, VirtualRouterProvider.Type.VirtualRouter);
|
||||
|
||||
return sc.list();
|
||||
}
|
||||
|
|
@ -989,7 +986,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
@Override
|
||||
public boolean verifyServicesCombination(Set<Service> services) {
|
||||
if (!services.contains(Service.SourceNat)) {
|
||||
if (services.contains(Service.StaticNat) || services.contains(Service.Firewall) || services.contains(Service.Lb) ||
|
||||
if (services.contains(Service.StaticNat) || services.contains(Service.Firewall) || services.contains(Service.Lb) ||
|
||||
services.contains(Service.PortForwarding) || services.contains(Service.Vpn)) {
|
||||
String servicesList = "[";
|
||||
for (Service service : services) {
|
||||
|
|
@ -1008,8 +1005,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
return this;
|
||||
}
|
||||
|
||||
protected VirtualRouterProviderType getVirtualRouterProvider() {
|
||||
return VirtualRouterProviderType.VirtualRouter;
|
||||
protected VirtualRouterProvider.Type getVirtualRouterProvider() {
|
||||
return VirtualRouterProvider.Type.VirtualRouter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1019,13 +1016,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
return null;
|
||||
}
|
||||
private boolean canHandleLbRules(List<LoadBalancingRule> rules) {
|
||||
Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb);
|
||||
Map<Capability, String> lbCaps = getCapabilities().get(Service.Lb);
|
||||
if (!lbCaps.isEmpty()) {
|
||||
String schemeCaps = lbCaps.get(Capability.LbSchemes);
|
||||
if (schemeCaps != null) {
|
||||
for (LoadBalancingRule rule : rules) {
|
||||
if (!schemeCaps.contains(rule.getScheme().toString())) {
|
||||
s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + this.getName());
|
||||
s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1041,11 +1038,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
|
||||
return true;
|
||||
}
|
||||
if (vm.getType() == Type.DomainRouter) {
|
||||
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
assert vm instanceof DomainRouterVO;
|
||||
DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine();
|
||||
_routerMgr.setupDhcpForPvlan(false, router, router.getHostId(), nic);
|
||||
} else if (vm.getType() == Type.User){
|
||||
} else if (vm.getType() == VirtualMachine.Type.User) {
|
||||
assert vm instanceof UserVmVO;
|
||||
UserVmVO userVm = (UserVmVO)vm.getVirtualMachine();
|
||||
_userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic);
|
||||
|
|
@ -1060,11 +1057,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
|
||||
return;
|
||||
}
|
||||
if (vm.getType() == Type.DomainRouter) {
|
||||
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
assert vm instanceof DomainRouterVO;
|
||||
DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine();
|
||||
_routerMgr.setupDhcpForPvlan(true, router, router.getHostId(), nic);
|
||||
} else if (vm.getType() == Type.User){
|
||||
} else if (vm.getType() == VirtualMachine.Type.User) {
|
||||
assert vm instanceof UserVmVO;
|
||||
UserVmVO userVm = (UserVmVO)vm.getVirtualMachine();
|
||||
_userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
|
||||
|
|
@ -1078,11 +1075,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
|
||||
return;
|
||||
}
|
||||
if (vm.getType() == Type.DomainRouter) {
|
||||
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
assert vm instanceof DomainRouterVO;
|
||||
DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine();
|
||||
_routerMgr.setupDhcpForPvlan(true, router, router.getHostId(), nic);
|
||||
} else if (vm.getType() == Type.User){
|
||||
} else if (vm.getType() == VirtualMachine.Type.User) {
|
||||
assert vm instanceof UserVmVO;
|
||||
UserVmVO userVm = (UserVmVO)vm.getVirtualMachine();
|
||||
_userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue