Search in sources :

Example 36 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cosmic by MissionCriticalCloud.

the class SecondaryStorageManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    final CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh");
    if (!answer.getResult()) {
        logger.warn("Unable to ssh to the VM: " + answer.getDetails());
        return false;
    }
    try {
        // get system ip and create static nat rule for the vm in case of basic networking with EIP/ELB
        _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
        final IPAddressVO ipaddr = _ipAddressDao.findByAssociatedVmId(profile.getVirtualMachine().getId());
        if (ipaddr != null && ipaddr.getSystem()) {
            final SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
            // override SSVM guest IP with EIP, so that download url's with be prepared with EIP
            secVm.setPublicIpAddress(ipaddr.getAddress().addr());
            _secStorageVmDao.update(secVm.getId(), secVm);
        }
    } catch (final Exception e) {
        logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", e);
        return false;
    }
    return true;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URISyntaxException(java.net.URISyntaxException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException)

Example 37 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cosmic by MissionCriticalCloud.

the class SecondaryStorageManagerImpl method destroySecStorageVm.

@Override
public boolean destroySecStorageVm(final long vmId) {
    final SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId);
    try {
        _itMgr.expunge(ssvm.getUuid());
        _secStorageVmDao.remove(ssvm.getId());
        final HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterId(), ssvm.getHostName(), Host.Type.SecondaryStorageVM);
        if (host != null) {
            logger.debug("Removing host entry for ssvm id=" + vmId);
            _hostDao.remove(host.getId());
            // Expire the download urls in the entire zone for templates and volumes.
            _tmplStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
            _volumeStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
            return true;
        }
        return false;
    } catch (final ResourceUnavailableException e) {
        logger.warn("Unable to expunge " + ssvm, e);
        return false;
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) HostVO(com.cloud.host.HostVO)

Example 38 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class VMwareGuru method getCommandHostDelegation.

@Override
@DB
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
    boolean needDelegation = false;
    if (cmd instanceof StorageSubSystemCommand) {
        Boolean fullCloneEnabled = VmwareFullClone.value();
        StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
        c.setExecuteInSequence(fullCloneEnabled);
    }
    if (cmd instanceof DownloadCommand) {
        cmd.setContextParam(VmwareManager.s_vmwareOVAPackageTimeout.key(), String.valueOf(VmwareManager.s_vmwareOVAPackageTimeout.value()));
    }
    // type is empty, so we need to check the format of volume at first.
    if (cmd instanceof CopyCommand) {
        CopyCommand cpyCommand = (CopyCommand) cmd;
        DataTO srcData = cpyCommand.getSrcTO();
        DataStoreTO srcStoreTO = srcData.getDataStore();
        DataTO destData = cpyCommand.getDestTO();
        DataStoreTO destStoreTO = destData.getDataStore();
        boolean inSeq = true;
        if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) || (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
            inSeq = false;
        } else if ((destStoreTO.getRole() == DataStoreRole.Image) || (destStoreTO.getRole() == DataStoreRole.ImageCache)) {
            inSeq = false;
        } else if (!VmwareFullClone.value()) {
            inSeq = false;
        }
        cpyCommand.setExecuteInSequence(inSeq);
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
        if (!needDelegation && !(HypervisorType.VMware == srcData.getHypervisorType() || HypervisorType.VMware == destData.getHypervisorType())) {
            return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
        }
        if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
            needDelegation = false;
        } else {
            needDelegation = true;
        }
    } else if (cmd instanceof CreateEntityDownloadURLCommand) {
        DataTO srcData = ((CreateEntityDownloadURLCommand) cmd).getData();
        if ((HypervisorType.VMware == srcData.getHypervisorType())) {
            needDelegation = true;
        }
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
    }
    if (!needDelegation) {
        return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
    }
    HostVO host = _hostDao.findById(hostId);
    long dcId = host.getDataCenterId();
    Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
    if (cmdTarget != null) {
        // TODO, we need to make sure agent is actually connected too
        cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
        if (host.getType() == Host.Type.Routing) {
            Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
            cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
            cmd.setContextParam("username", hostDetails.get("username"));
            cmd.setContextParam("password", hostDetails.get("password"));
            cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
            cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
        }
        CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
        _cmdExecLogDao.persist(execLog);
        cmd.setContextParam("execid", String.valueOf(execLog.getId()));
        cmd.setContextParam("noderuninfo", String.format("%d-%d", _clusterMgr.getManagementNodeId(), _clusterMgr.getCurrentRunId()));
        cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
        cmd.setContextParam(VmwareManager.s_vmwareOVAPackageTimeout.key(), String.valueOf(VmwareManager.s_vmwareOVAPackageTimeout.value()));
        if (cmd instanceof BackupSnapshotCommand || cmd instanceof CreatePrivateTemplateFromVolumeCommand || cmd instanceof CreatePrivateTemplateFromSnapshotCommand || cmd instanceof CopyVolumeCommand || cmd instanceof CopyCommand || cmd instanceof CreateVolumeOVACommand || cmd instanceof PrepareOVAPackingCommand || cmd instanceof CreateVolumeFromSnapshotCommand) {
            String workerName = _vmwareMgr.composeWorkerName();
            long checkPointId = 1;
            // FIXME: Fix                    long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
            cmd.setContextParam("worker", workerName);
            cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
            // some commands use 2 workers
            String workerName2 = _vmwareMgr.composeWorkerName();
            long checkPointId2 = 1;
            // FIXME: Fix                    long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
            cmd.setContextParam("worker2", workerName2);
            cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
            cmd.setContextParam("searchexludefolders", _vmwareMgr.s_vmwareSearchExcludeFolder.value());
        }
        return new Pair<Boolean, Long>(Boolean.TRUE, cmdTarget.first().getId());
    }
    return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) CreateVolumeOVACommand(com.cloud.agent.api.storage.CreateVolumeOVACommand) DataTO(com.cloud.agent.api.to.DataTO) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) Pair(com.cloud.utils.Pair) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrepareOVAPackingCommand(com.cloud.agent.api.storage.PrepareOVAPackingCommand) HostVO(com.cloud.host.HostVO) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) DB(com.cloud.utils.db.DB)

Example 39 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class NetworkServiceImpl method addTrafficTypeToPhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_TRAFFIC_TYPE_CREATE, eventDescription = "Creating Physical Network TrafficType", create = true)
public PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficTypeStr, String isolationMethod, String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan, String hypervLabel, String ovm3Label) {
    // verify input parameters
    PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
    if (network == null) {
        throw new InvalidParameterValueException("Physical Network id=" + physicalNetworkId + "doesn't exist in the system");
    }
    Networks.TrafficType trafficType = null;
    if (trafficTypeStr != null && !trafficTypeStr.isEmpty()) {
        try {
            trafficType = Networks.TrafficType.valueOf(trafficTypeStr);
        } catch (IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve trafficType '" + trafficTypeStr + "' to a supported value");
        }
    }
    if (_pNTrafficTypeDao.isTrafficTypeSupported(physicalNetworkId, trafficType)) {
        throw new CloudRuntimeException("This physical network already supports the traffic type: " + trafficType);
    }
    if (TrafficType.isSystemNetwork(trafficType) || TrafficType.Public.equals(trafficType) || TrafficType.Storage.equals(trafficType)) {
        if (!_physicalNetworkDao.listByZoneAndTrafficType(network.getDataCenterId(), trafficType).isEmpty()) {
            throw new CloudRuntimeException("Fail to add the traffic type to physical network because Zone already has a physical network with this traffic type: " + trafficType);
        }
    }
    if (TrafficType.Storage.equals(trafficType)) {
        List<SecondaryStorageVmVO> ssvms = _stnwMgr.getSSVMWithNoStorageNetwork(network.getDataCenterId());
        if (!ssvms.isEmpty()) {
            StringBuilder sb = new StringBuilder("Cannot add " + trafficType + " traffic type as there are below secondary storage vm still running. Please stop them all and add Storage traffic type again, then destory them all to allow CloudStack recreate them with storage network(If you have added storage network ip range)");
            sb.append("SSVMs:");
            for (SecondaryStorageVmVO ssvm : ssvms) {
                sb.append(ssvm.getInstanceName()).append(":").append(ssvm.getState());
            }
            throw new CloudRuntimeException(sb.toString());
        }
    }
    try {
        // Create the new traffic type in the database
        if (xenLabel == null) {
            xenLabel = getDefaultXenNetworkLabel(trafficType);
        }
        PhysicalNetworkTrafficTypeVO pNetworktrafficType = new PhysicalNetworkTrafficTypeVO(physicalNetworkId, trafficType, xenLabel, kvmLabel, vmwareLabel, simulatorLabel, vlan, hypervLabel, ovm3Label);
        pNetworktrafficType = _pNTrafficTypeDao.persist(pNetworktrafficType);
        // each broadcast type will individually need to be qualified for support of public traffic
        if (TrafficType.Public.equals(trafficType)) {
            List<String> isolationMethods = network.getIsolationMethods();
            if ((isolationMethods.size() == 1 && isolationMethods.get(0).toLowerCase().equals("vxlan")) || (isolationMethod != null && isolationMethods.contains(isolationMethod) && isolationMethod.toLowerCase().equals("vxlan"))) {
                // find row in networks table that is defined as 'Public', created when zone was deployed
                NetworkVO publicNetwork = _networksDao.listByZoneAndTrafficType(network.getDataCenterId(), TrafficType.Public).get(0);
                if (publicNetwork != null) {
                    s_logger.debug("setting public network " + publicNetwork + " to broadcast type vxlan");
                    publicNetwork.setBroadcastDomainType(BroadcastDomainType.Vxlan);
                    _networksDao.persist(publicNetwork);
                }
            }
        }
        return pNetworktrafficType;
    } catch (Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new CloudRuntimeException("Fail to add a traffic type to physical network");
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) TrafficType(com.cloud.network.Networks.TrafficType) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 40 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class UploadMonitorImpl method createVolumeDownloadURL.

@Override
public void createVolumeDownloadURL(Long entityId, String path, Type type, Long dataCenterId, Long uploadId, ImageFormat format) {
    String errorString = "";
    boolean success = false;
    try {
        List<HostVO> storageServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.SecondaryStorage, dataCenterId);
        if (storageServers == null) {
            errorString = "No Storage Server found at the datacenter - " + dataCenterId;
            throw new CloudRuntimeException(errorString);
        }
        // Update DB for state = DOWNLOAD_URL_NOT_CREATED.
        UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
        uploadJob.setUploadState(Status.DOWNLOAD_URL_NOT_CREATED);
        uploadJob.setLastUpdated(new Date());
        _uploadDao.update(uploadJob.getId(), uploadJob);
        // Create Symlink at ssvm
        String uuid = UUID.randomUUID().toString() + "." + format.toString().toLowerCase();
        DataStore secStore = storeMgr.getDataStore(ApiDBUtils.findUploadById(uploadId).getDataStoreId(), DataStoreRole.Image);
        EndPoint ep = _epSelector.select(secStore);
        if (ep == null) {
            errorString = "There is no secondary storage VM for secondary storage host " + secStore.getName();
            throw new CloudRuntimeException(errorString);
        }
        CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity) secStore).getMountPoint(), path, uuid, null);
        Answer ans = ep.sendMessage(cmd);
        if (ans == null || !ans.getResult()) {
            errorString = "Unable to create a link for " + type + " id:" + entityId + "," + (ans == null ? "" : ans.getDetails());
            s_logger.warn(errorString);
            throw new CloudRuntimeException(errorString);
        }
        List<SecondaryStorageVmVO> ssVms = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running);
        if (ssVms.size() > 0) {
            SecondaryStorageVmVO ssVm = ssVms.get(0);
            if (ssVm.getPublicIpAddress() == null) {
                errorString = "A running secondary storage vm has a null public ip?";
                s_logger.error(errorString);
                throw new CloudRuntimeException(errorString);
            }
            // Construct actual URL locally now that the symlink exists at SSVM
            String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), uuid);
            UploadVO vo = _uploadDao.createForUpdate();
            vo.setLastUpdated(new Date());
            vo.setUploadUrl(extractURL);
            vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
            _uploadDao.update(uploadId, vo);
            success = true;
            return;
        }
        errorString = "Couldnt find a running SSVM in the zone" + dataCenterId + ". Couldnt create the extraction URL.";
        throw new CloudRuntimeException(errorString);
    } finally {
        if (!success) {
            UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
            uploadJob.setLastUpdated(new Date());
            uploadJob.setErrorString(errorString);
            uploadJob.setUploadState(Status.ERROR);
            _uploadDao.update(uploadId, uploadJob);
        }
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UploadVO(com.cloud.storage.UploadVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) Date(java.util.Date) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Aggregations

SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)53 HostVO (com.cloud.host.HostVO)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 Answer (com.cloud.agent.api.Answer)14 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)11 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)9 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)8 ArrayList (java.util.ArrayList)8 Account (com.cloud.user.Account)7 DB (com.cloud.utils.db.DB)6 NicProfile (com.cloud.vm.NicProfile)6 ConfigurationException (javax.naming.ConfigurationException)6 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)6 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)5 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)5 Pair (com.cloud.utils.Pair)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)4