use of com.cloud.user.Account in project cloudstack by apache.
the class SnapshotTestWithFakeData method testConcurrentSnapshot.
@Test
public void testConcurrentSnapshot() throws URISyntaxException, InterruptedException, ExecutionException {
DataStore store = createDataStore();
final FakePrimaryDataStoreDriver dataStoreDriver = (FakePrimaryDataStoreDriver) store.getDriver();
dataStoreDriver.makeTakeSnapshotSucceed(true);
final VolumeInfo volumeInfo = createVolume(1L, store);
Assert.assertTrue(volumeInfo.getState() == Volume.State.Ready);
vol = volumeInfo;
// final SnapshotPolicyVO policyVO = createSnapshotPolicy(vol.getId());
ExecutorService pool = Executors.newFixedThreadPool(2);
boolean result = false;
List<Future<Boolean>> future = new ArrayList<Future<Boolean>>();
for (int i = 0; i < 12; i++) {
final int cnt = i;
Future<Boolean> task = pool.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
boolean r = true;
try {
SnapshotVO snapshotVO = createSnapshotInDb(vol.getId());
VolumeObject volumeObject = (VolumeObject) vol;
Account account = mock(Account.class);
when(account.getId()).thenReturn(1L);
CreateSnapshotPayload createSnapshotPayload = mock(CreateSnapshotPayload.class);
when(createSnapshotPayload.getAccount()).thenReturn(account);
when(createSnapshotPayload.getSnapshotId()).thenReturn(snapshotVO.getId());
when(createSnapshotPayload.getSnapshotPolicyId()).thenReturn(0L);
volumeObject.addPayload(createSnapshotPayload);
if (cnt > 8) {
mockStorageMotionStrategy.makeBackupSnapshotSucceed(false);
}
SnapshotInfo newSnapshot = volumeService.takeSnapshot(vol);
if (newSnapshot == null) {
r = false;
}
} catch (Exception e) {
r = false;
}
return r;
}
});
Assert.assertTrue(task.get());
}
}
use of com.cloud.user.Account in project cloudstack by apache.
the class EndpointSelectorTest method setUp.
@Before
public void setUp() {
// create data center
DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, DataCenter.NetworkType.Basic, null, null, true, true, null, null);
dc = dcDao.persist(dc);
dcId = dc.getId();
// create pod
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "10.223.0.1", "10.233.2.2/25", 8, "test");
pod = podDao.persist(pod);
podId = pod.getId();
// create xenserver cluster
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
cluster.setHypervisorType(Hypervisor.HypervisorType.XenServer.toString());
cluster.setClusterType(Cluster.ClusterType.CloudManaged);
cluster.setManagedState(Managed.ManagedState.Managed);
cluster = clusterDao.persist(cluster);
clusterId = cluster.getId();
imageStore = new ImageStoreVO();
imageStore.setName(UUID.randomUUID().toString());
imageStore.setDataCenterId(dcId);
imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
imageStore.setRole(DataStoreRole.Image);
imageStore.setUrl(UUID.randomUUID().toString());
imageStore.setUuid(UUID.randomUUID().toString());
imageStore.setProtocol("nfs");
imageStore = imageStoreDao.persist(imageStore);
when(primaryDataStoreProvider.configure(Matchers.anyMap())).thenReturn(true);
Set<DataStoreProvider.DataStoreProviderType> types = new HashSet<DataStoreProvider.DataStoreProviderType>();
types.add(DataStoreProvider.DataStoreProviderType.PRIMARY);
when(primaryDataStoreProvider.getTypes()).thenReturn(types);
when(primaryDataStoreProvider.getName()).thenReturn(DataStoreProvider.DEFAULT_PRIMARY);
when(primaryDataStoreProvider.getDataStoreDriver()).thenReturn(driver);
User user = mock(User.class);
when(user.getId()).thenReturn(1L);
Account account = mock(Account.class);
when(account.getId()).thenReturn(1L);
when(accountManager.getSystemAccount()).thenReturn(account);
when(accountManager.getSystemUser()).thenReturn(user);
if (Merovingian2.getLockController() == null) {
_lockController = Merovingian2.createLockController(1234);
} else {
_lockController = Merovingian2.getLockController();
}
_lockController.cleanupThisServer();
ComponentContext.initComponentsLifeCycle();
}
use of com.cloud.user.Account in project cloudstack by apache.
the class DedicatedResourceManagerImpl method listDedicatedClusters.
@Override
public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedClusters(ListDedicatedClustersCmd cmd) {
Long clusterId = cmd.getClusterId();
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
Long accountId = null;
Long affinityGroupId = cmd.getAffinityGroupId();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
if (accountName != null) {
if (domainId != null) {
Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account != null) {
accountId = account.getId();
}
} else {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
}
}
Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize);
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId, searchFilter);
return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second());
}
use of com.cloud.user.Account in project cloudstack by apache.
the class DedicatedResourceManagerImpl method listDedicatedHosts.
@Override
public Pair<List<? extends DedicatedResourceVO>, Integer> listDedicatedHosts(ListDedicatedHostsCmd cmd) {
Long hostId = cmd.getHostId();
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
Long affinityGroupId = cmd.getAffinityGroupId();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
Long accountId = null;
if (accountName != null) {
if (domainId != null) {
Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account != null) {
accountId = account.getId();
}
} else {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
}
}
Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize);
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedHosts(hostId, domainId, accountId, affinityGroupId, searchFilter);
return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second());
}
use of com.cloud.user.Account in project cloudstack by apache.
the class QuotaResponseBuilderImpl method createQuotaSummaryResponse.
@Override
public Pair<List<QuotaSummaryResponse>, Integer> createQuotaSummaryResponse(final String accountName, final Long domainId) {
List<QuotaSummaryResponse> result = new ArrayList<QuotaSummaryResponse>();
if (accountName != null && domainId != null) {
Account account = _accountDao.findActiveAccount(accountName, domainId);
QuotaSummaryResponse qr = getQuotaSummaryResponse(account);
result.add(qr);
}
return new Pair<>(result, result.size());
}
Aggregations