Search in sources :

Example 31 with StoragePoolVO

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());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with StoragePoolVO

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());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStorageResourceAssoc(com.cloud.storage.VMTemplateStorageResourceAssoc) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with StoragePoolVO

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;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) VpcGatewayVO(com.cloud.network.vpc.VpcGatewayVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) User(com.cloud.user.User) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) StaticRouteVO(com.cloud.network.vpc.StaticRouteVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) VolumeVO(com.cloud.storage.VolumeVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 34 with StoragePoolVO

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);
}
Also used : VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 35 with StoragePoolVO

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;
}
Also used : StoragePool(com.cloud.storage.StoragePool) ArrayList(java.util.ArrayList) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8