Search in sources :

Example 96 with Account

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());
    }
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) CreateSnapshotPayload(com.cloud.storage.CreateSnapshotPayload) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject) URISyntaxException(java.net.URISyntaxException) ExecutionException(java.util.concurrent.ExecutionException) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 97 with Account

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();
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) User(com.cloud.user.User) PrimaryDataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HostPodVO(com.cloud.dc.HostPodVO) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 98 with Account

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());
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Filter(com.cloud.utils.db.Filter) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair)

Example 99 with Account

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());
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Filter(com.cloud.utils.db.Filter) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair)

Example 100 with Account

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());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair)

Aggregations

Account (com.cloud.user.Account)1088 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)308 ArrayList (java.util.ArrayList)293 ActionEvent (com.cloud.event.ActionEvent)243 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)216 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)207 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)170 User (com.cloud.user.User)149 List (java.util.List)147 DB (com.cloud.utils.db.DB)130 Test (org.junit.Test)123 Pair (com.cloud.utils.Pair)115 AccountVO (com.cloud.user.AccountVO)113 Network (com.cloud.network.Network)104 Filter (com.cloud.utils.db.Filter)103 TransactionStatus (com.cloud.utils.db.TransactionStatus)95 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)94 DomainVO (com.cloud.domain.DomainVO)91 Domain (com.cloud.domain.Domain)87 UserVO (com.cloud.user.UserVO)86