use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testModifyStoragePoolCommand.
@Test
public void testModifyStoragePoolCommand() {
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final ModifyStoragePoolCommand modifyStorageCommand = new ModifyStoragePoolCommand(false, poolVO);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
final Answer answer = wrapper.execute(modifyStorageCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testDestroyCommand.
@Test
public void testDestroyCommand() {
final VMTemplateStorageResourceAssoc templateStorage = Mockito.mock(VMTemplateStorageResourceAssoc.class);
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final DestroyCommand destroyCommand = new DestroyCommand(poolVO, templateStorage);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(destroyCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.
the class ApiDBUtils method findJobInstanceUuid.
public static String findJobInstanceUuid(final AsyncJob job) {
if (job == null) {
return null;
}
String jobInstanceId = null;
final ApiCommandJobType jobInstanceType = EnumUtils.fromString(ApiCommandJobType.class, job.getInstanceType(), ApiCommandJobType.None);
if (job.getInstanceId() == null) {
// when assert is hit, implement 'getInstanceId' of BaseAsyncCmd and return appropriate instance id
assert (false);
return null;
}
if (jobInstanceType == ApiCommandJobType.Volume) {
final VolumeVO volume = ApiDBUtils.findVolumeById(job.getInstanceId());
if (volume != null) {
jobInstanceId = volume.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Template || jobInstanceType == ApiCommandJobType.Iso) {
final VMTemplateVO template = ApiDBUtils.findTemplateById(job.getInstanceId());
if (template != null) {
jobInstanceId = template.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.VirtualMachine || jobInstanceType == ApiCommandJobType.ConsoleProxy || jobInstanceType == ApiCommandJobType.SystemVm || jobInstanceType == ApiCommandJobType.DomainRouter) {
final VMInstanceVO vm = ApiDBUtils.findVMInstanceById(job.getInstanceId());
if (vm != null) {
jobInstanceId = vm.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Snapshot) {
final Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId());
if (snapshot != null) {
jobInstanceId = snapshot.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Host) {
final Host host = ApiDBUtils.findHostById(job.getInstanceId());
if (host != null) {
jobInstanceId = host.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StoragePool) {
final StoragePoolVO spool = ApiDBUtils.findStoragePoolById(job.getInstanceId());
if (spool != null) {
jobInstanceId = spool.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.IpAddress) {
final IPAddressVO ip = ApiDBUtils.findIpAddressById(job.getInstanceId());
if (ip != null) {
jobInstanceId = ip.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetwork) {
final PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(job.getInstanceId());
if (pnet != null) {
jobInstanceId = pnet.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.TrafficType) {
final PhysicalNetworkTrafficTypeVO trafficType = ApiDBUtils.findPhysicalNetworkTrafficTypeById(job.getInstanceId());
if (trafficType != null) {
jobInstanceId = trafficType.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetworkServiceProvider) {
final PhysicalNetworkServiceProvider sp = ApiDBUtils.findPhysicalNetworkServiceProviderById(job.getInstanceId());
if (sp != null) {
jobInstanceId = sp.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.FirewallRule) {
final FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(job.getInstanceId());
if (fw != null) {
jobInstanceId = fw.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Account) {
final Account acct = ApiDBUtils.findAccountById(job.getInstanceId());
if (acct != null) {
jobInstanceId = acct.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.User) {
final User usr = ApiDBUtils.findUserById(job.getInstanceId());
if (usr != null) {
jobInstanceId = usr.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StaticRoute) {
final StaticRouteVO route = ApiDBUtils.findStaticRouteById(job.getInstanceId());
if (route != null) {
jobInstanceId = route.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PrivateGateway) {
final VpcGatewayVO gateway = ApiDBUtils.findVpcGatewayById(job.getInstanceId());
if (gateway != null) {
jobInstanceId = gateway.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Network) {
final NetworkVO networkVO = ApiDBUtils.findNetworkById(job.getInstanceId());
if (networkVO != null) {
jobInstanceId = networkVO.getUuid();
}
} else if (jobInstanceType != ApiCommandJobType.None) {
// entity table mapping
assert (false);
}
return jobInstanceId;
}
use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createTemplateResponses.
@Override
public List<TemplateResponse> createTemplateResponses(final ResponseView view, final long templateId, final Long snapshotId, final Long volumeId, final boolean readyOnly) {
Long zoneId = null;
if (snapshotId != null) {
final Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId);
final VolumeVO volume = findVolumeById(snapshot.getVolumeId());
// if volume comes back null, use another technique to try to discover the zone
if (volume == null) {
final SnapshotDataStoreVO snapshotStore = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
if (snapshotStore != null) {
final long storagePoolId = snapshotStore.getDataStoreId();
final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
if (storagePool != null) {
zoneId = storagePool.getDataCenterId();
}
}
} else {
zoneId = volume.getDataCenterId();
}
} else {
final VolumeVO volume = findVolumeById(volumeId);
zoneId = volume.getDataCenterId();
}
if (zoneId == null) {
throw new CloudRuntimeException("Unable to determine the zone ID");
}
return createTemplateResponses(view, templateId, zoneId, readyOnly);
}
use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.
the class RandomStoragePoolAllocator method select.
@Override
public List<StoragePool> select(final DiskProfile dskCh, final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid, final int returnUpTo) {
final List<StoragePool> suitablePools = new ArrayList<>();
final long dcId = plan.getDataCenterId();
final Long podId = plan.getPodId();
final Long clusterId = plan.getClusterId();
if (podId == null) {
return null;
}
s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
final List<StoragePoolVO> pools = _storagePoolDao.listBy(dcId, podId, clusterId, ScopeType.CLUSTER);
if (pools.size() == 0) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No storage pools available for allocation, returning");
}
return suitablePools;
}
Collections.shuffle(pools);
if (s_logger.isDebugEnabled()) {
s_logger.debug("RandomStoragePoolAllocator has " + pools.size() + " pools to check for allocation");
}
for (final StoragePoolVO pool : pools) {
if (suitablePools.size() == returnUpTo) {
break;
}
final StoragePool pol = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(pool.getId());
if (filter(avoid, pol, dskCh, plan)) {
suitablePools.add(pol);
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("RandomStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
}
return suitablePools;
}
Aggregations