Search in sources :

Example 6 with DiskOffering

use of com.cloud.offering.DiskOffering in project CloudStack-archive by CloudStack-extras.

the class CreateDiskOfferingCmd method execute.

@Override
public void execute() {
    DiskOffering offering = _configService.createDiskOffering(this);
    if (offering != null) {
        DiskOfferingResponse response = _responseGenerator.createDiskOfferingResponse(offering);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering");
    }
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) ServerApiException(com.cloud.api.ServerApiException) DiskOfferingResponse(com.cloud.api.response.DiskOfferingResponse)

Example 7 with DiskOffering

use of com.cloud.offering.DiskOffering in project CloudStack-archive by CloudStack-extras.

the class ListDiskOfferingsCmd method execute.

@Override
public void execute() {
    List<? extends DiskOffering> result = _mgr.searchForDiskOfferings(this);
    ListResponse<DiskOfferingResponse> response = new ListResponse<DiskOfferingResponse>();
    List<DiskOfferingResponse> diskOfferingResponses = new ArrayList<DiskOfferingResponse>();
    for (DiskOffering offering : result) {
        DiskOfferingResponse diskOffResp = _responseGenerator.createDiskOfferingResponse(offering);
        diskOffResp.setObjectName("diskoffering");
        diskOfferingResponses.add(diskOffResp);
    }
    response.setResponses(diskOfferingResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) DiskOfferingResponse(com.cloud.api.response.DiskOfferingResponse)

Example 8 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class UserVmManagerImpl method createVirtualMachine.

@Override
public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
    //Verify that all objects exist before passing them to the service
    Account owner = _accountService.getActiveAccountById(cmd.getEntityOwnerId());
    verifyDetails(cmd.getDetails());
    Long zoneId = cmd.getZoneId();
    DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
    }
    Long serviceOfferingId = cmd.getServiceOfferingId();
    ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (serviceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
    }
    Long templateId = cmd.getTemplateId();
    if (!serviceOffering.isDynamic()) {
        for (String detail : cmd.getDetails().keySet()) {
            if (detail.equalsIgnoreCase("cpuNumber") || detail.equalsIgnoreCase("cpuSpeed") || detail.equalsIgnoreCase("memory")) {
                throw new InvalidParameterValueException("cpuNumber or cpuSpeed or memory should not be specified for static service offering");
            }
        }
    }
    VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
    // Make sure a valid template ID was specified
    if (template == null) {
        throw new InvalidParameterValueException("Unable to use template " + templateId);
    }
    Long diskOfferingId = cmd.getDiskOfferingId();
    DiskOffering diskOffering = null;
    if (diskOfferingId != null) {
        diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId);
        if (diskOffering == null) {
            throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
        }
    }
    if (!zone.isLocalStorageEnabled()) {
        if (serviceOffering.getUseLocalStorage()) {
            throw new InvalidParameterValueException("Zone is not configured to use local storage but service offering " + serviceOffering.getName() + " uses it");
        }
        if (diskOffering != null && diskOffering.getUseLocalStorage()) {
            throw new InvalidParameterValueException("Zone is not configured to use local storage but disk offering " + diskOffering.getName() + " uses it");
        }
    }
    String ipAddress = cmd.getIpAddress();
    String ip6Address = cmd.getIp6Address();
    String name = cmd.getName();
    String displayName = cmd.getDisplayName();
    UserVm vm = null;
    IpAddresses addrs = new IpAddresses(ipAddress, ip6Address);
    Long size = cmd.getSize();
    String group = cmd.getGroup();
    String userData = cmd.getUserData();
    String sshKeyPairName = cmd.getSSHKeyPairName();
    Boolean displayVm = cmd.getDisplayVm();
    String keyboard = cmd.getKeyboard();
    if (zone.getNetworkType() == NetworkType.Basic) {
        if (cmd.getNetworkIds() != null) {
            throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
        } else {
            vm = createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId());
        }
    } else {
        if (zone.isSecurityGroupEnabled()) {
            vm = createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, cmd.getNetworkIds(), getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId());
        } else {
            if (cmd.getSecurityGroupIdList() != null && !cmd.getSecurityGroupIdList().isEmpty()) {
                throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
            }
            vm = createAdvancedVirtualMachine(zone, serviceOffering, template, cmd.getNetworkIds(), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId());
        }
    }
    return vm;
}
Also used : IpAddresses(com.cloud.network.Network.IpAddresses) Account(com.cloud.user.Account) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering)

Example 9 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class StorageManagerImpl method getDiskWithThrottling.

@Override
public DiskTO getDiskWithThrottling(final DataTO volTO, final Volume.Type volumeType, final long deviceId, final String path, final long offeringId, final long diskOfferingId) {
    DiskTO disk = null;
    if (volTO != null && volTO instanceof VolumeObjectTO) {
        VolumeObjectTO volumeTO = (VolumeObjectTO) volTO;
        ServiceOffering offering = _entityMgr.findById(ServiceOffering.class, offeringId);
        DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId);
        if (volumeType == Volume.Type.ROOT) {
            setVolumeObjectTOThrottling(volumeTO, offering, diskOffering);
        } else {
            setVolumeObjectTOThrottling(volumeTO, null, diskOffering);
        }
        disk = new DiskTO(volumeTO, deviceId, path, volumeType);
    } else {
        disk = new DiskTO(volTO, deviceId, path, volumeType);
    }
    return disk;
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) ServiceOffering(com.cloud.offering.ServiceOffering) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 10 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class VolumeOrchestrator method createVolumeFromSnapshot.

@DB
@Override
public VolumeInfo createVolumeFromSnapshot(Volume volume, Snapshot snapshot, UserVm vm) throws StorageUnavailableException {
    Account account = _entityMgr.findById(Account.class, volume.getAccountId());
    final HashSet<StoragePool> poolsToAvoid = new HashSet<StoragePool>();
    StoragePool pool = null;
    Set<Long> podsToAvoid = new HashSet<Long>();
    Pair<Pod, Long> pod = null;
    DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    DataCenter dc = _entityMgr.findById(DataCenter.class, volume.getDataCenterId());
    DiskProfile dskCh = new DiskProfile(volume, diskOffering, snapshot.getHypervisorType());
    String msg = "There are no available storage pools to store the volume in";
    if (vm != null) {
        Pod podofVM = _entityMgr.findById(Pod.class, vm.getPodIdToDeployIn());
        if (podofVM != null) {
            pod = new Pair<Pod, Long>(podofVM, podofVM.getId());
        }
    }
    if (vm != null && pod != null) {
        //if VM is running use the hostId to find the clusterID. If it is stopped, refer the cluster where the ROOT volume of the VM exists.
        Long hostId = null;
        Long clusterId = null;
        if (vm.getState() == State.Running) {
            hostId = vm.getHostId();
            if (hostId != null) {
                Host vmHost = _entityMgr.findById(Host.class, hostId);
                clusterId = vmHost.getClusterId();
            }
        } else {
            List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
            if (rootVolumesOfVm.size() != 1) {
                throw new CloudRuntimeException("The VM " + vm.getHostName() + " has more than one ROOT volume and is in an invalid state. Please contact Cloud Support.");
            } else {
                VolumeVO rootVolumeOfVm = rootVolumesOfVm.get(0);
                StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
                clusterId = (rootDiskPool == null ? null : rootDiskPool.getClusterId());
            }
        }
        // Determine what storage pool to store the volume in
        while ((pool = findStoragePool(dskCh, dc, pod.first(), clusterId, hostId, vm, poolsToAvoid)) != null) {
            break;
        }
        if (pool == null) {
            //pool could not be found in the VM's pod/cluster.
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Could not find any storage pool to create Volume in the pod/cluster of the provided VM " + vm.getUuid());
            }
            StringBuilder addDetails = new StringBuilder(msg);
            addDetails.append(", Could not find any storage pool to create Volume in the pod/cluster of the VM ");
            addDetails.append(vm.getUuid());
            msg = addDetails.toString();
        }
    } else {
        // Determine what pod to store the volume in
        while ((pod = findPod(null, null, dc, account.getId(), podsToAvoid)) != null) {
            podsToAvoid.add(pod.first().getId());
            // Determine what storage pool to store the volume in
            while ((pool = findStoragePool(dskCh, dc, pod.first(), null, null, null, poolsToAvoid)) != null) {
                break;
            }
            if (pool != null) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Found a suitable pool for create volume: " + pool.getId());
                }
                break;
            }
        }
    }
    if (pool == null) {
        s_logger.info(msg);
        throw new StorageUnavailableException(msg, -1);
    }
    VolumeInfo vol = volFactory.getVolume(volume.getId());
    DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    DataStoreRole dataStoreRole = getDataStoreRole(snapshot);
    SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
    if (snapInfo == null && dataStoreRole == DataStoreRole.Image) {
        // snapshot is not backed up to secondary, let's do that now.
        snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
        if (snapInfo == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId());
        }
        // We need to copy the snapshot onto secondary.
        SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.BACKUP);
        snapshotStrategy.backupSnapshot(snapInfo);
        // Attempt to grab it again.
        snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
        if (snapInfo == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId() + " on secondary and could not create backup");
        }
    }
    // don't try to perform a sync if the DataStoreRole of the snapshot is equal to DataStoreRole.Primary
    if (!DataStoreRole.Primary.equals(dataStoreRole)) {
        try {
            // sync snapshot to region store if necessary
            DataStore snapStore = snapInfo.getDataStore();
            long snapVolId = snapInfo.getVolumeId();
            _snapshotSrv.syncVolumeSnapshotsToRegionStore(snapVolId, snapStore);
        } catch (Exception ex) {
            // log but ignore the sync error to avoid any potential S3 down issue, it should be sync next time
            s_logger.warn(ex.getMessage(), ex);
        }
    }
    // create volume on primary from snapshot
    AsyncCallFuture<VolumeApiResult> future = volService.createVolumeFromSnapshot(vol, store, snapInfo);
    try {
        VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to create volume from snapshot:" + result.getResult());
            throw new CloudRuntimeException("Failed to create volume from snapshot:" + result.getResult());
        }
        return result.getVolume();
    } catch (InterruptedException e) {
        s_logger.debug("Failed to create volume from snapshot", e);
        throw new CloudRuntimeException("Failed to create volume from snapshot", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to create volume from snapshot", e);
        throw new CloudRuntimeException("Failed to create volume from snapshot", e);
    }
}
Also used : Account(com.cloud.user.Account) StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) DataStoreRole(com.cloud.storage.DataStoreRole) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) SnapshotStrategy(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy) HashSet(java.util.HashSet) Pod(com.cloud.dc.Pod) Host(com.cloud.host.Host) DiskProfile(com.cloud.vm.DiskProfile) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientStorageCapacityException(com.cloud.exception.InsufficientStorageCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataCenter(com.cloud.dc.DataCenter) DB(com.cloud.utils.db.DB)

Aggregations

DiskOffering (com.cloud.offering.DiskOffering)14 DataCenter (com.cloud.dc.DataCenter)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 ServiceOffering (com.cloud.offering.ServiceOffering)4 StoragePool (com.cloud.storage.StoragePool)4 VolumeVO (com.cloud.storage.VolumeVO)4 Account (com.cloud.user.Account)4 ServerApiException (com.cloud.api.ServerApiException)3 DiskOfferingResponse (com.cloud.api.response.DiskOfferingResponse)3 Pod (com.cloud.dc.Pod)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)3 ArrayList (java.util.ArrayList)3 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)3 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 Host (com.cloud.host.Host)2 Volume (com.cloud.storage.Volume)2 UserVm (com.cloud.uservm.UserVm)2