Search in sources :

Example 11 with HypervisorType

use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.

the class ResourceManagerImpl method updateCluster.

@Override
@DB
public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) {
    final ClusterVO cluster = (ClusterVO) clusterToUpdate;
    // Verify cluster information and update the cluster if needed
    boolean doUpdate = false;
    if (hypervisor != null && !hypervisor.isEmpty()) {
        final Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor);
        if (hypervisorType == null) {
            s_logger.error("Unable to resolve " + hypervisor + " to a valid supported hypervisor type");
            throw new InvalidParameterValueException("Unable to resolve " + hypervisor + " to a supported type");
        } else {
            cluster.setHypervisorType(hypervisor);
            doUpdate = true;
        }
    }
    Cluster.ClusterType newClusterType = null;
    if (clusterType != null && !clusterType.isEmpty()) {
        try {
            newClusterType = Cluster.ClusterType.valueOf(clusterType);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
        }
        if (newClusterType == null) {
            s_logger.error("Unable to resolve " + clusterType + " to a valid supported cluster type");
            throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
        } else {
            cluster.setClusterType(newClusterType);
            doUpdate = true;
        }
    }
    Grouping.AllocationState newAllocationState = null;
    if (allocationState != null && !allocationState.isEmpty()) {
        try {
            newAllocationState = Grouping.AllocationState.valueOf(allocationState);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationState + "' to a supported state");
        }
        if (newAllocationState == null) {
            s_logger.error("Unable to resolve " + allocationState + " to a valid supported allocation State");
            throw new InvalidParameterValueException("Unable to resolve " + allocationState + " to a supported state");
        } else {
            cluster.setAllocationState(newAllocationState);
            doUpdate = true;
        }
    }
    Managed.ManagedState newManagedState = null;
    final Managed.ManagedState oldManagedState = cluster.getManagedState();
    if (managedstate != null && !managedstate.isEmpty()) {
        try {
            newManagedState = Managed.ManagedState.valueOf(managedstate);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
        }
        if (newManagedState == null) {
            s_logger.error("Unable to resolve Managed State '" + managedstate + "' to a supported state");
            throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
        } else {
            doUpdate = true;
        }
    }
    if (doUpdate) {
        _clusterDao.update(cluster.getId(), cluster);
    }
    if (newManagedState != null && !newManagedState.equals(oldManagedState)) {
        if (newManagedState.equals(Managed.ManagedState.Unmanaged)) {
            boolean success = false;
            try {
                cluster.setManagedState(Managed.ManagedState.PrepareUnmanaged);
                _clusterDao.update(cluster.getId(), cluster);
                List<HostVO> hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
                for (final HostVO host : hosts) {
                    if (host.getType().equals(Host.Type.Routing) && !host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Up) && !host.getStatus().equals(Status.Alert)) {
                        final String msg = "host " + host.getPrivateIpAddress() + " should not be in " + host.getStatus().toString() + " status";
                        throw new CloudRuntimeException("PrepareUnmanaged Failed due to " + msg);
                    }
                }
                for (final HostVO host : hosts) {
                    if (host.getStatus().equals(Status.Up)) {
                        umanageHost(host.getId());
                    }
                }
                final int retry = 40;
                boolean lsuccess = true;
                for (int i = 0; i < retry; i++) {
                    lsuccess = true;
                    try {
                        Thread.sleep(5 * 1000);
                    } catch (final Exception e) {
                    }
                    hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
                    for (final HostVO host : hosts) {
                        if (!host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Alert)) {
                            lsuccess = false;
                            break;
                        }
                    }
                    if (lsuccess == true) {
                        success = true;
                        break;
                    }
                }
                if (success == false) {
                    throw new CloudRuntimeException("PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later ");
                }
            } finally {
                cluster.setManagedState(success ? Managed.ManagedState.Unmanaged : Managed.ManagedState.PrepareUnmanagedError);
                _clusterDao.update(cluster.getId(), cluster);
            }
        } else if (newManagedState.equals(Managed.ManagedState.Managed)) {
            cluster.setManagedState(Managed.ManagedState.Managed);
            _clusterDao.update(cluster.getId(), cluster);
        }
    }
    return cluster;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Hypervisor(com.cloud.hypervisor.Hypervisor) PodCluster(com.cloud.dc.PodCluster) Cluster(com.cloud.org.Cluster) Grouping(com.cloud.org.Grouping) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) SshException(com.cloud.utils.ssh.SshException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Managed(com.cloud.org.Managed) DB(com.cloud.utils.db.DB)

Example 12 with HypervisorType

use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.

the class ResourceManagerImpl method getAvailableHypervisor.

@Override
public HypervisorType getAvailableHypervisor(final long zoneId) {
    HypervisorType defaultHype = getDefaultHypervisor(zoneId);
    if (defaultHype == HypervisorType.None) {
        final List<HypervisorType> supportedHypes = getSupportedHypervisorTypes(zoneId, false, null);
        if (supportedHypes.size() > 0) {
            Collections.shuffle(supportedHypes);
            defaultHype = supportedHypes.get(0);
        }
    }
    if (defaultHype == HypervisorType.None) {
        defaultHype = HypervisorType.Any;
    }
    return defaultHype;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType)

Example 13 with HypervisorType

use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.

the class CloudOrchestrator method createVirtualMachineFromScratch.

@Override
public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, NicProfile> networkNicMap, DeploymentPlan plan) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    //load vm instance and offerings and call virtualMachineManagerImpl
    VMInstanceVO vm = _vmDao.findByUuid(id);
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    rootDiskOfferingInfo.setDiskOffering(computeOffering);
    Long diskOfferingId = vm.getDiskOfferingId();
    if (diskOfferingId == null) {
        throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
    }
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
    if (diskOffering == null) {
        throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
    }
    Long size = null;
    if (diskOffering.getDiskSize() == 0) {
        size = diskSize;
        if (size == null) {
            throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter.");
        }
        _volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
    }
    rootDiskOfferingInfo.setDiskOffering(diskOffering);
    rootDiskOfferingInfo.setSize(size);
    if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIopsDo");
            String maxIops = userVmDetails.get("maxIopsDo");
            rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
            rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
        }
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<Network, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, new ArrayList<NicProfile>(Arrays.asList(networkNicMap.get(uuid))));
        }
    }
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    _itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<DiskOfferingInfo>(), networkIpMap, plan, hypervisorType);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) VirtualMachineEntityImpl(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl) LinkedHashMap(java.util.LinkedHashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Example 14 with HypervisorType

use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.

the class NetworkHelperImpl method deployRouter.

@Override
public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter) throws InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
    final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getServiceOfferingId());
    final Account owner = routerDeploymentDefinition.getOwner();
    // Router is the network element, we don't know the hypervisor type yet.
    // Try to allocate the domR twice using diff hypervisors, and when
    // failed both times, throw the exception up
    final List<HypervisorType> hypervisors = getHypervisors(routerDeploymentDefinition);
    int allocateRetry = 0;
    int startRetry = 0;
    DomainRouterVO router = null;
    for (final Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext(); ) {
        final HypervisorType hType = iter.next();
        try {
            final long id = _routerDao.getNextInSequence(Long.class, "id");
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(String.format("Allocating the VR with id=%s in datacenter %s with the hypervisor type %s", id, routerDeploymentDefinition.getDest().getDataCenter(), hType));
            }
            final String templateName = retrieveTemplateName(hType, routerDeploymentDefinition.getDest().getDataCenter().getId());
            final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
            if (template == null) {
                s_logger.debug(hType + " won't support system vm, skip it");
                continue;
            }
            final boolean offerHA = routerOffering.getOfferHA();
            // routerDeploymentDefinition.getVpc().getId() ==> do not use
            // VPC because it is not a VPC offering.
            final Long vpcId = routerDeploymentDefinition.getVpc() != null ? routerDeploymentDefinition.getVpc().getId() : null;
            long userId = CallContext.current().getCallingUserId();
            if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
                final List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
                if (!userVOs.isEmpty()) {
                    userId = userVOs.get(0).getId();
                }
            }
            router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id, s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, routerDeploymentDefinition.isRedundant(), RedundantState.UNKNOWN, offerHA, false, vpcId);
            router.setDynamicallyScalable(template.isDynamicallyScalable());
            router.setRole(Role.VIRTUAL_ROUTER);
            router = _routerDao.persist(router);
            reallocateRouterNetworks(routerDeploymentDefinition, router, template, null);
            router = _routerDao.findById(router.getId());
        } catch (final InsufficientCapacityException ex) {
            if (allocateRetry < 2 && iter.hasNext()) {
                s_logger.debug("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time");
                continue;
            } else {
                throw ex;
            }
        } finally {
            allocateRetry++;
        }
        if (startRouter) {
            try {
                router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), routerDeploymentDefinition.getParams());
                break;
            } catch (final InsufficientCapacityException ex) {
                if (startRetry < 2 && iter.hasNext()) {
                    s_logger.debug("Failed to start the VR  " + router + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time");
                    // destroy the router
                    destroyRouter(router.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM);
                    continue;
                } else {
                    throw ex;
                }
            } finally {
                startRetry++;
            }
        } else {
            // return stopped router
            return router;
        }
    }
    return router;
}
Also used : Account(com.cloud.user.Account) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) UserVO(com.cloud.user.UserVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 15 with HypervisorType

use of com.cloud.hypervisor.Hypervisor.HypervisorType in project cloudstack by apache.

the class TemplateManagerImpl method createPrivateTemplateRecord.

@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", create = true)
public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account templateOwner) throws ResourceAllocationException {
    Account caller = CallContext.current().getCallingAccount();
    boolean isAdmin = (_accountMgr.isAdmin(caller.getId()));
    _accountMgr.checkAccess(caller, null, true, templateOwner);
    String name = cmd.getTemplateName();
    if ((name == null) || (name.length() > 32)) {
        throw new InvalidParameterValueException("Template name cannot be null and should be less than 32 characters");
    }
    if (cmd.getTemplateTag() != null) {
        if (!_accountService.isRootAdmin(caller.getId())) {
            throw new PermissionDeniedException("Parameter templatetag can only be specified by a Root Admin, permission denied");
        }
    }
    // do some parameter defaulting
    Integer bits = cmd.getBits();
    Boolean requiresHvm = cmd.getRequiresHvm();
    Boolean passwordEnabled = cmd.isPasswordEnabled();
    Boolean isPublic = cmd.isPublic();
    Boolean featured = cmd.isFeatured();
    int bitsValue = ((bits == null) ? 64 : bits.intValue());
    boolean requiresHvmValue = ((requiresHvm == null) ? true : requiresHvm.booleanValue());
    boolean passwordEnabledValue = ((passwordEnabled == null) ? false : passwordEnabled.booleanValue());
    if (isPublic == null) {
        isPublic = Boolean.FALSE;
    }
    boolean isDynamicScalingEnabled = cmd.isDynamicallyScalable();
    // check whether template owner can create public templates
    boolean allowPublicUserTemplates = AllowPublicUserTemplates.valueIn(templateOwner.getId());
    if (!isAdmin && !allowPublicUserTemplates && isPublic) {
        throw new PermissionDeniedException("Failed to create template " + name + ", only private templates can be created.");
    }
    Long volumeId = cmd.getVolumeId();
    Long snapshotId = cmd.getSnapshotId();
    if ((volumeId == null) && (snapshotId == null)) {
        throw new InvalidParameterValueException("Failed to create private template record, neither volume ID nor snapshot ID were specified.");
    }
    if ((volumeId != null) && (snapshotId != null)) {
        throw new InvalidParameterValueException("Failed to create private template record, please specify only one of volume ID (" + volumeId + ") and snapshot ID (" + snapshotId + ")");
    }
    HypervisorType hyperType;
    VolumeVO volume = null;
    SnapshotVO snapshot = null;
    VMTemplateVO privateTemplate = null;
    if (volumeId != null) {
        // create template from volume
        volume = _volumeDao.findById(volumeId);
        if (volume == null) {
            throw new InvalidParameterValueException("Failed to create private template record, unable to find volume " + volumeId);
        }
        // check permissions
        _accountMgr.checkAccess(caller, null, true, volume);
        // created
        if (!_volumeMgr.volumeInactive(volume)) {
            String msg = "Unable to create private template for volume: " + volume.getName() + "; volume is attached to a non-stopped VM, please stop the VM first";
            if (s_logger.isInfoEnabled()) {
                s_logger.info(msg);
            }
            throw new CloudRuntimeException(msg);
        }
        hyperType = _volumeDao.getHypervisorType(volumeId);
        if (HypervisorType.LXC.equals(hyperType)) {
            throw new InvalidParameterValueException("Template creation is not supported for LXC volume: " + volumeId);
        }
    } else {
        // create template from snapshot
        snapshot = _snapshotDao.findById(snapshotId);
        if (snapshot == null) {
            throw new InvalidParameterValueException("Failed to create private template record, unable to find snapshot " + snapshotId);
        }
        // Volume could be removed so find including removed to record source template id.
        volume = _volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId());
        // check permissions
        _accountMgr.checkAccess(caller, null, true, snapshot);
        if (snapshot.getState() != Snapshot.State.BackedUp) {
            throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.State.BackedUp + " state yet and can't be used for template creation");
        }
        /*
             * // bug #11428. Operation not supported if vmware and snapshots
             * parent volume = ROOT if(snapshot.getHypervisorType() ==
             * HypervisorType.VMware && snapshotVolume.getVolumeType() ==
             * Type.DATADISK){ throw new UnsupportedServiceException(
             * "operation not supported, snapshot with id " + snapshotId +
             * " is created from Data Disk"); }
             */
        hyperType = snapshot.getHypervisorType();
    }
    _resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.template);
    _resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.secondary_storage, new Long(volume != null ? volume.getSize() : snapshot.getSize()).longValue());
    if (!isAdmin || featured == null) {
        featured = Boolean.FALSE;
    }
    Long guestOSId = cmd.getOsTypeId();
    GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
    if (guestOS == null) {
        throw new InvalidParameterValueException("GuestOS with ID: " + guestOSId + " does not exist.");
    }
    Long nextTemplateId = _tmpltDao.getNextInSequence(Long.class, "id");
    String description = cmd.getDisplayText();
    boolean isExtractable = false;
    Long sourceTemplateId = null;
    if (volume != null) {
        VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
        isExtractable = template != null && template.isExtractable() && template.getTemplateType() != Storage.TemplateType.SYSTEM;
        if (volume.getIsoId() != null && volume.getIsoId() != 0) {
            sourceTemplateId = volume.getIsoId();
        } else if (volume.getTemplateId() != null) {
            sourceTemplateId = volume.getTemplateId();
        }
    }
    String templateTag = cmd.getTemplateTag();
    if (templateTag != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Adding template tag: " + templateTag);
        }
    }
    privateTemplate = new VMTemplateVO(nextTemplateId, name, ImageFormat.RAW, isPublic, featured, isExtractable, TemplateType.USER, null, requiresHvmValue, bitsValue, templateOwner.getId(), null, description, passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails(), false, isDynamicScalingEnabled);
    if (sourceTemplateId != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("This template is getting created from other template, setting source template Id to: " + sourceTemplateId);
        }
    }
    // for region wide storage, set cross zones flag
    List<ImageStoreVO> stores = _imgStoreDao.findRegionImageStores();
    if (!CollectionUtils.isEmpty(stores)) {
        privateTemplate.setCrossZones(true);
    }
    privateTemplate.setSourceTemplateId(sourceTemplateId);
    VMTemplateVO template = _tmpltDao.persist(privateTemplate);
    // Increment the number of templates
    if (template != null) {
        Map<String, String> details = new HashMap<String, String>();
        if (sourceTemplateId != null) {
            VMTemplateVO sourceTemplate = _tmpltDao.findById(sourceTemplateId);
            if (sourceTemplate != null && sourceTemplate.getDetails() != null) {
                details.putAll(sourceTemplate.getDetails());
            }
        }
        if (volume != null) {
            Long vmId = volume.getInstanceId();
            if (vmId != null) {
                UserVmVO userVm = _userVmDao.findById(vmId);
                if (userVm != null) {
                    _userVmDao.loadDetails(userVm);
                    details.putAll(userVm.getDetails());
                }
            }
        }
        if (cmd.getDetails() != null) {
            // new password will be generated during vm deployment from password enabled template
            details.remove("Encrypted.Password");
            details.putAll(cmd.getDetails());
        }
        if (!details.isEmpty()) {
            privateTemplate.setDetails(details);
            _tmpltDao.saveDetails(privateTemplate);
        }
        _resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.template);
        _resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.secondary_storage, new Long(volume != null ? volume.getSize() : snapshot.getSize()));
    }
    if (template != null) {
        return template;
    } else {
        throw new CloudRuntimeException("Failed to create a template");
    }
}
Also used : Account(com.cloud.user.Account) UserVmVO(com.cloud.vm.UserVmVO) HashMap(java.util.HashMap) VMTemplateVO(com.cloud.storage.VMTemplateVO) GuestOSVO(com.cloud.storage.GuestOSVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)57 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)25 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 ArrayList (java.util.ArrayList)19 Account (com.cloud.user.Account)15 VMTemplateVO (com.cloud.storage.VMTemplateVO)12 ClusterVO (com.cloud.dc.ClusterVO)10 HostVO (com.cloud.host.HostVO)8 UserVmVO (com.cloud.vm.UserVmVO)8 HashMap (java.util.HashMap)8 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8 DataCenterVO (com.cloud.dc.DataCenterVO)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)7 Answer (com.cloud.agent.api.Answer)6 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)6 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)6 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)5