Search in sources :

Example 16 with ClusterDetailsVO

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

the class SolidFireUtil method placeVolumeInVolumeAccessGroup.

public static long placeVolumeInVolumeAccessGroup(SolidFireConnection sfConnection, long sfVolumeId, long storagePoolId, String vagUuid, List<HostVO> hosts, ClusterDetailsDao clusterDetailsDao) {
    if (hosts == null || hosts.isEmpty()) {
        throw new CloudRuntimeException("There must be at least one host in the cluster.");
    }
    long lVagId;
    try {
        lVagId = SolidFireUtil.createVag(sfConnection, "CloudStack-" + vagUuid, SolidFireUtil.getIqnsFromHosts(hosts), new long[] { sfVolumeId });
    } catch (Exception ex) {
        String iqnInVagAlready1 = "Exceeded maximum number of Volume Access Groups per initiator";
        String iqnInVagAlready2 = "Exceeded maximum number of VolumeAccessGroups per Initiator";
        if (!ex.getMessage().contains(iqnInVagAlready1) && !ex.getMessage().contains(iqnInVagAlready2)) {
            throw new CloudRuntimeException(ex.getMessage());
        }
        // getCompatibleVag throws an exception if an existing VAG can't be located
        SolidFireUtil.SolidFireVag sfVag = getCompatibleVag(sfConnection, hosts);
        lVagId = sfVag.getId();
        long[] volumeIds = getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, true);
        SolidFireUtil.modifyVag(sfConnection, lVagId, sfVag.getInitiators(), volumeIds);
    }
    ClusterDetailsVO clusterDetail = new ClusterDetailsVO(hosts.get(0).getClusterId(), getVagKey(storagePoolId), String.valueOf(lVagId));
    clusterDetailsDao.persist(clusterDetail);
    return lVagId;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 17 with ClusterDetailsVO

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

the class SolidFireUtil method hostAddedToOrRemovedFromCluster.

public static void hostAddedToOrRemovedFromCluster(long hostId, long clusterId, boolean added, String storageProvider, ClusterDao clusterDao, ClusterDetailsDao clusterDetailsDao, PrimaryDataStoreDao storagePoolDao, StoragePoolDetailsDao storagePoolDetailsDao, HostDao hostDao) {
    ClusterVO cluster = clusterDao.findById(clusterId);
    GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
    if (!lock.lock(s_lockTimeInSeconds)) {
        String errMsg = "Couldn't lock the DB on the following string: " + cluster.getUuid();
        s_logger.debug(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    try {
        List<StoragePoolVO> storagePools = storagePoolDao.findPoolsByProvider(storageProvider);
        if (storagePools != null && storagePools.size() > 0) {
            List<SolidFireUtil.SolidFireConnection> sfConnections = new ArrayList<>();
            for (StoragePoolVO storagePool : storagePools) {
                ClusterDetailsVO clusterDetail = clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePool.getId()));
                String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
                if (vagId != null) {
                    SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePool.getId(), storagePoolDetailsDao);
                    if (!sfConnections.contains(sfConnection)) {
                        sfConnections.add(sfConnection);
                        SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getVag(sfConnection, Long.parseLong(vagId));
                        List<HostVO> hostsToAddOrRemove = new ArrayList<>();
                        HostVO hostToAddOrRemove = hostDao.findByIdIncludingRemoved(hostId);
                        hostsToAddOrRemove.add(hostToAddOrRemove);
                        String[] hostIqns = SolidFireUtil.getNewHostIqns(sfVag.getInitiators(), SolidFireUtil.getIqnsFromHosts(hostsToAddOrRemove), added);
                        SolidFireUtil.modifyVag(sfConnection, sfVag.getId(), hostIqns, sfVag.getVolumeIds());
                    }
                }
            }
        }
    } finally {
        lock.unlock();
        lock.releaseRef();
    }
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) GlobalLock(com.cloud.utils.db.GlobalLock) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO)

Example 18 with ClusterDetailsVO

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

the class VolumeTestVmware method setUp.

@Test(priority = -1)
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    host = hostDao.findByGuid(this.getHostGuid());
    if (host != null) {
        dcId = host.getDataCenterId();
        clusterId = host.getClusterId();
        podId = host.getPodId();
        imageStore = this.imageStoreDao.findByName(imageStoreName);
    } else {
        // create data center
        DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
        dc = dcDao.persist(dc);
        dcId = dc.getId();
        // create pod
        HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
        pod = podDao.persist(pod);
        podId = pod.getId();
        // create xen cluster
        ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
        cluster.setHypervisorType(HypervisorType.VMware.toString());
        cluster.setClusterType(ClusterType.ExternalManaged);
        cluster.setManagedState(ManagedState.Managed);
        cluster = clusterDao.persist(cluster);
        clusterId = cluster.getId();
        // setup vcenter
        ClusterDetailsVO clusterDetailVO = new ClusterDetailsVO(cluster.getId(), "url", null);
        this.clusterDetailsDao.persist(clusterDetailVO);
        clusterDetailVO = new ClusterDetailsVO(cluster.getId(), "username", null);
        this.clusterDetailsDao.persist(clusterDetailVO);
        clusterDetailVO = new ClusterDetailsVO(cluster.getId(), "password", null);
        this.clusterDetailsDao.persist(clusterDetailVO);
        // create xen host
        host = new HostVO(this.getHostGuid());
        host.setName("devcloud vmware host");
        host.setType(Host.Type.Routing);
        host.setPrivateIpAddress(this.getHostIp());
        host.setDataCenterId(dc.getId());
        host.setVersion("6.0.1");
        host.setAvailable(true);
        host.setSetup(true);
        host.setPodId(podId);
        host.setLastPinged(0);
        host.setResourceState(ResourceState.Enabled);
        host.setHypervisorType(HypervisorType.VMware);
        host.setClusterId(cluster.getId());
        host = hostDao.persist(host);
        imageStore = new ImageStoreVO();
        imageStore.setName(imageStoreName);
        imageStore.setDataCenterId(dcId);
        imageStore.setProviderName("CloudStack ImageStore Provider");
        imageStore.setRole(DataStoreRole.Image);
        imageStore.setUrl(this.getSecondaryStorage());
        imageStore.setUuid(UUID.randomUUID().toString());
        imageStore.setProtocol("nfs");
        imageStore = imageStoreDao.persist(imageStore);
    }
    image = new VMTemplateVO();
    image.setTemplateType(TemplateType.USER);
    image.setUrl(this.getTemplateUrl());
    image.setUniqueName(UUID.randomUUID().toString());
    image.setName(UUID.randomUUID().toString());
    image.setPublicTemplate(true);
    image.setFeatured(true);
    image.setRequiresHvm(true);
    image.setBits(64);
    image.setFormat(Storage.ImageFormat.VHD);
    image.setEnablePassword(true);
    image.setEnableSshKey(true);
    image.setGuestOSId(1);
    image.setBootable(true);
    image.setPrepopulate(true);
    image.setCrossZones(true);
    image.setExtractable(true);
    image = imageDataDao.persist(image);
    /*
         * TemplateDataStoreVO templateStore = new TemplateDataStoreVO();
         *
         * templateStore.setDataStoreId(imageStore.getId());
         * templateStore.setDownloadPercent(100);
         * templateStore.setDownloadState(Status.DOWNLOADED);
         * templateStore.setDownloadUrl(imageStore.getUrl());
         * templateStore.setInstallPath(this.getImageInstallPath());
         * templateStore.setTemplateId(image.getId());
         * templateStoreDao.persist(templateStore);
         */
    DataStore store = this.dataStoreMgr.getDataStore(imageStore.getId(), DataStoreRole.Image);
    TemplateInfo template = templateFactory.getTemplate(image.getId(), DataStoreRole.Image);
    DataObject templateOnStore = store.create(template);
    TemplateObjectTO to = new TemplateObjectTO();
    to.setPath(this.getImageInstallPath());
    CopyCmdAnswer answer = new CopyCmdAnswer(to);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    templateOnStore.processEvent(Event.OperationSuccessed, answer);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) ClusterVO(com.cloud.dc.ClusterVO) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) HostPodVO(com.cloud.dc.HostPodVO) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) HostVO(com.cloud.host.HostVO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) Test(org.testng.annotations.Test)

Aggregations

ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)18 ClusterVO (com.cloud.dc.ClusterVO)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 HostVO (com.cloud.host.HostVO)8 DataCenterVO (com.cloud.dc.DataCenterVO)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HostPodVO (com.cloud.dc.HostPodVO)3 ServiceOffering (com.cloud.offering.ServiceOffering)3 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)3 GlobalLock (com.cloud.utils.db.GlobalLock)3 SolidFireUtil (org.apache.cloudstack.storage.datastore.util.SolidFireUtil)3 DataCenter (com.cloud.dc.DataCenter)2 Pod (com.cloud.dc.Pod)2 DeployDestination (com.cloud.deploy.DeployDestination)2 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Cluster (com.cloud.org.Cluster)2 Account (com.cloud.user.Account)2