Search in sources :

Example 21 with Pod

use of com.cloud.dc.Pod in project cloudstack by apache.

the class VolumeOrchestrator method createVolumeOnPrimaryStorage.

@Override
public VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm, VolumeInfo volume, HypervisorType rootDiskHyperType, StoragePool storagePool) throws NoTransitionException {
    VirtualMachineTemplate rootDiskTmplt = _entityMgr.findById(VirtualMachineTemplate.class, vm.getTemplateId());
    DataCenter dcVO = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
    Pod pod = _entityMgr.findById(Pod.class, storagePool.getPodId());
    ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId());
    DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    Long clusterId = storagePool.getClusterId();
    VolumeInfo vol = null;
    if (volume.getState() == Volume.State.Allocated) {
        vol = createVolume(volume, vm, rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO, new ArrayList<StoragePool>(), volume.getSize(), rootDiskHyperType);
    } else if (volume.getState() == Volume.State.Uploaded) {
        vol = copyVolume(storagePool, volume, vm, rootDiskTmplt, dcVO, pod, diskVO, svo, rootDiskHyperType);
        if (vol != null) {
            // Moving of Volume is successful, decrement the volume resource count from secondary for an account and increment it into primary storage under same account.
            _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, volume.getSize());
            _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.getSize());
        }
    }
    if (vol == null) {
        throw new CloudRuntimeException("Volume shouldn't be null " + volume.getId());
    }
    VolumeVO volVO = _volsDao.findById(vol.getId());
    if (volVO.getFormat() == null) {
        volVO.setFormat(getSupportedImageFormatForCluster(rootDiskHyperType));
    }
    _volsDao.update(volVO.getId(), volVO);
    return volFactory.getVolume(volVO.getId());
}
Also used : DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) Pod(com.cloud.dc.Pod) VolumeVO(com.cloud.storage.VolumeVO) ServiceOffering(com.cloud.offering.ServiceOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 22 with Pod

use of com.cloud.dc.Pod in project cloudstack by apache.

the class ListPodsByCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Pod>, Integer> result = _mgr.searchForPods(this);
    ListResponse<PodResponse> response = new ListResponse<PodResponse>();
    List<PodResponse> podResponses = new ArrayList<PodResponse>();
    for (Pod pod : result.first()) {
        PodResponse podResponse = _responseGenerator.createPodResponse(pod, showCapacities);
        podResponse.setObjectName("pod");
        podResponses.add(podResponse);
    }
    response.setResponses(podResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Pod(com.cloud.dc.Pod) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PodResponse(org.apache.cloudstack.api.response.PodResponse)

Example 23 with Pod

use of com.cloud.dc.Pod in project cloudstack by apache.

the class VirtualMachineManagerImpl method orchestrateReboot.

private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    // if there are active vm snapshots task, state change is not allowed
    if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
        s_logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
        throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
    }
    final DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
    final Host host = _hostDao.findById(vm.getHostId());
    if (host == null) {
        // Should findById throw an Exception is the host is not found?
        throw new CloudRuntimeException("Unable to retrieve host with id " + vm.getHostId());
    }
    final Cluster cluster = _entityMgr.findById(Cluster.class, host.getClusterId());
    final Pod pod = _entityMgr.findById(Pod.class, host.getPodId());
    final DeployDestination dest = new DeployDestination(dc, pod, cluster, host);
    try {
        final Commands cmds = new Commands(Command.OnError.Stop);
        cmds.addCommand(new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType())));
        _agentMgr.send(host.getId(), cmds);
        final Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
        if (rebootAnswer != null && rebootAnswer.getResult()) {
            return;
        }
        s_logger.info("Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? " no reboot answer" : rebootAnswer.getDetails()));
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e);
        throw new CloudRuntimeException("Failed to reboot the vm on host " + dest.getHost());
    }
}
Also used : AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenter(com.cloud.dc.DataCenter) RebootCommand(com.cloud.agent.api.RebootCommand) Pod(com.cloud.dc.Pod) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) Commands(com.cloud.agent.manager.Commands) Cluster(com.cloud.org.Cluster) Host(com.cloud.host.Host)

Aggregations

Pod (com.cloud.dc.Pod)23 DataCenter (com.cloud.dc.DataCenter)9 ArrayList (java.util.ArrayList)6 Host (com.cloud.host.Host)5 Cluster (com.cloud.org.Cluster)5 StoragePool (com.cloud.storage.StoragePool)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 DeployDestination (com.cloud.deploy.DeployDestination)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 Volume (com.cloud.storage.Volume)4 DB (com.cloud.utils.db.DB)4 List (java.util.List)4 PodResponse (com.cloud.api.response.PodResponse)3 DiskOffering (com.cloud.offering.DiskOffering)3 ServiceOffering (com.cloud.offering.ServiceOffering)3 HashMap (java.util.HashMap)3 ServerApiException (com.cloud.api.ServerApiException)2 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)2 ClusterVO (com.cloud.dc.ClusterVO)2 VlanVO (com.cloud.dc.VlanVO)2