Search in sources :

Example 11 with Pod

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

the class StorageNetworkGuru method reserve.

@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    if (!_sNwMgr.isStorageIpRangeAvailable(dest.getDataCenter().getId())) {
        super.reserve(nic, network, vm, dest, context);
        return;
    }
    Pod pod = dest.getPod();
    Integer vlan = null;
    StorageNetworkIpAddressVO ip = _sNwMgr.acquireIpAddress(pod.getId());
    if (ip == null) {
        throw new InsufficientAddressCapacityException("Unable to get a storage network ip address", Pod.class, pod.getId());
    }
    vlan = ip.getVlan();
    nic.setIPv4Address(ip.getIpAddress());
    nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac(), NetworkModel.MACIdentifier.value())));
    nic.setFormat(AddressFormat.Ip4);
    nic.setIPv4Netmask(ip.getNetmask());
    nic.setBroadcastType(BroadcastDomainType.Storage);
    nic.setIPv4Gateway(ip.getGateway());
    if (vlan != null) {
        nic.setBroadcastUri(BroadcastDomainType.Storage.toUri(vlan));
    } else {
        nic.setBroadcastUri(null);
    }
    nic.setIsolationUri(null);
    s_logger.debug("Allocated a storage nic " + nic + " for " + vm);
}
Also used : Pod(com.cloud.dc.Pod) StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Example 12 with Pod

use of com.cloud.dc.Pod in project CloudStack-archive by CloudStack-extras.

the class UpdatePodCmd method execute.

@Override
public void execute() {
    Pod result = _configService.editPod(this);
    if (result != null) {
        PodResponse response = _responseGenerator.createPodResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update pod");
    }
}
Also used : Pod(com.cloud.dc.Pod) ServerApiException(com.cloud.api.ServerApiException) PodResponse(com.cloud.api.response.PodResponse)

Example 13 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)

Example 14 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 15 with Pod

use of com.cloud.dc.Pod 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

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