Search in sources :

Example 1 with ClusterVO

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

the class SimulatorDiscoverer method find.

/**
	 * Finds ServerResources of an in-process simulator
	 * 
	 * @see com.cloud.resource.Discoverer#find(long, java.lang.Long,
	 *      java.lang.Long, java.net.URI, java.lang.String, java.lang.String)
	 */
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI uri, String username, String password, List<String> hostTags) throws DiscoveryException {
    Map<AgentResourceBase, Map<String, String>> resources;
    try {
        //http://sim/count=$count, it will add $count number of hosts into the cluster
        String scheme = uri.getScheme();
        String host = uri.getAuthority();
        String commands = URLDecoder.decode(uri.getPath());
        long cpuSpeed = _mockAgentMgr.DEFAULT_HOST_SPEED_MHZ;
        long cpuCores = _mockAgentMgr.DEFAULT_HOST_CPU_CORES;
        long memory = _mockAgentMgr.DEFAULT_HOST_MEM_SIZE;
        long localstorageSize = _mockStorageMgr.DEFAULT_HOST_STORAGE_SIZE;
        if (scheme.equals("http")) {
            if (host == null || !host.startsWith("sim")) {
                String msg = "uri is not of simulator type so we're not taking care of the discovery for this: " + uri;
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(msg);
                }
                return null;
            }
            if (commands != null) {
                int index = commands.lastIndexOf("/");
                if (index != -1) {
                    commands = commands.substring(index + 1);
                    String[] cmds = commands.split("&");
                    for (String cmd : cmds) {
                        String[] parameter = cmd.split("=");
                        if (parameter[0].equalsIgnoreCase("cpuspeed") && parameter[1] != null) {
                            cpuSpeed = Long.parseLong(parameter[1]);
                        } else if (parameter[0].equalsIgnoreCase("cpucore") && parameter[1] != null) {
                            cpuCores = Long.parseLong(parameter[1]);
                        } else if (parameter[0].equalsIgnoreCase("memory") && parameter[1] != null) {
                            memory = Long.parseLong(parameter[1]);
                        } else if (parameter[0].equalsIgnoreCase("localstorage") && parameter[1] != null) {
                            localstorageSize = Long.parseLong(parameter[1]);
                        }
                    }
                }
            }
        } else {
            String msg = "uriString is not http so we're not taking care of the discovery for this: " + uri;
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(msg);
            }
            return null;
        }
        String cluster = null;
        if (clusterId == null) {
            String msg = "must specify cluster Id when adding host";
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(msg);
            }
            throw new RuntimeException(msg);
        } else {
            ClusterVO clu = _clusterDao.findById(clusterId);
            if (clu == null || (clu.getHypervisorType() != HypervisorType.Simulator)) {
                if (s_logger.isInfoEnabled())
                    s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors");
                return null;
            }
            cluster = Long.toString(clusterId);
            if (clu.getGuid() == null) {
                clu.setGuid(UUID.randomUUID().toString());
            }
            _clusterDao.update(clusterId, clu);
        }
        String pod;
        if (podId == null) {
            String msg = "must specify pod Id when adding host";
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(msg);
            }
            throw new RuntimeException(msg);
        } else {
            pod = Long.toString(podId);
        }
        Map<String, String> details = new HashMap<String, String>();
        Map<String, Object> params = new HashMap<String, Object>();
        details.put("username", username);
        params.put("username", username);
        details.put("password", password);
        params.put("password", password);
        params.put("zone", Long.toString(dcId));
        params.put("pod", pod);
        params.put("cluster", cluster);
        params.put("cpuspeed", Long.toString(cpuSpeed));
        params.put("cpucore", Long.toString(cpuCores));
        params.put("memory", Long.toString(memory));
        params.put("localstorage", Long.toString(localstorageSize));
        resources = createAgentResources(params);
        return resources;
    } catch (Exception ex) {
        s_logger.error("Exception when discovering simulator hosts: " + ex.getMessage());
    }
    return null;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) DiscoveryException(com.cloud.exception.DiscoveryException) ConfigurationException(javax.naming.ConfigurationException) ConnectionException(com.cloud.exception.ConnectionException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ClusterVO

use of com.cloud.dc.ClusterVO 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 3 with ClusterVO

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

the class DeploymentPlanningManagerImplTest method testSetUp.

@Before
public void testSetUp() {
    MockitoAnnotations.initMocks(this);
    ComponentContext.initComponentsLifeCycle();
    PlannerHostReservationVO reservationVO = new PlannerHostReservationVO(200L, 1L, 2L, 3L, PlannerResourceUsage.Shared);
    Mockito.when(_plannerHostReserveDao.persist(Matchers.any(PlannerHostReservationVO.class))).thenReturn(reservationVO);
    Mockito.when(_plannerHostReserveDao.findById(Matchers.anyLong())).thenReturn(reservationVO);
    Mockito.when(_affinityGroupVMMapDao.countAffinityGroupsForVm(Matchers.anyLong())).thenReturn(0L);
    VMInstanceVO vm = new VMInstanceVO();
    Mockito.when(vmProfile.getVirtualMachine()).thenReturn(vm);
    Mockito.when(vmDetailsDao.listDetailsKeyPairs(Matchers.anyLong())).thenReturn(null);
    Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc);
    Mockito.when(dc.getId()).thenReturn(dataCenterId);
    ClusterVO clusterVO = new ClusterVO();
    clusterVO.setHypervisorType(HypervisorType.XenServer.toString());
    Mockito.when(_clusterDao.findById(Matchers.anyLong())).thenReturn(clusterVO);
    Mockito.when(_planner.getName()).thenReturn("FirstFitPlanner");
    List<DeploymentPlanner> planners = new ArrayList<DeploymentPlanner>();
    planners.add(_planner);
    _dpm.setPlanners(planners);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) DeploymentPlanner(com.cloud.deploy.DeploymentPlanner) PlannerHostReservationVO(com.cloud.deploy.PlannerHostReservationVO) Before(org.junit.Before)

Example 4 with ClusterVO

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

the class EndpointSelectorTest method setUp.

@Before
public void setUp() {
    // 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, DataCenter.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(), "10.223.0.1", "10.233.2.2/25", 8, "test");
    pod = podDao.persist(pod);
    podId = pod.getId();
    // create xenserver cluster
    ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
    cluster.setHypervisorType(Hypervisor.HypervisorType.XenServer.toString());
    cluster.setClusterType(Cluster.ClusterType.CloudManaged);
    cluster.setManagedState(Managed.ManagedState.Managed);
    cluster = clusterDao.persist(cluster);
    clusterId = cluster.getId();
    imageStore = new ImageStoreVO();
    imageStore.setName(UUID.randomUUID().toString());
    imageStore.setDataCenterId(dcId);
    imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
    imageStore.setRole(DataStoreRole.Image);
    imageStore.setUrl(UUID.randomUUID().toString());
    imageStore.setUuid(UUID.randomUUID().toString());
    imageStore.setProtocol("nfs");
    imageStore = imageStoreDao.persist(imageStore);
    when(primaryDataStoreProvider.configure(Matchers.anyMap())).thenReturn(true);
    Set<DataStoreProvider.DataStoreProviderType> types = new HashSet<DataStoreProvider.DataStoreProviderType>();
    types.add(DataStoreProvider.DataStoreProviderType.PRIMARY);
    when(primaryDataStoreProvider.getTypes()).thenReturn(types);
    when(primaryDataStoreProvider.getName()).thenReturn(DataStoreProvider.DEFAULT_PRIMARY);
    when(primaryDataStoreProvider.getDataStoreDriver()).thenReturn(driver);
    User user = mock(User.class);
    when(user.getId()).thenReturn(1L);
    Account account = mock(Account.class);
    when(account.getId()).thenReturn(1L);
    when(accountManager.getSystemAccount()).thenReturn(account);
    when(accountManager.getSystemUser()).thenReturn(user);
    if (Merovingian2.getLockController() == null) {
        _lockController = Merovingian2.createLockController(1234);
    } else {
        _lockController = Merovingian2.getLockController();
    }
    _lockController.cleanupThisServer();
    ComponentContext.initComponentsLifeCycle();
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) User(com.cloud.user.User) PrimaryDataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HostPodVO(com.cloud.dc.HostPodVO) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 5 with ClusterVO

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

the class StorageAllocatorTest method createDb.

protected void createDb() {
    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();
    HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "255.255.255.255", "", 8, "test");
    pod = podDao.persist(pod);
    podId = pod.getId();
    ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
    cluster.setHypervisorType(HypervisorType.XenServer.toString());
    cluster.setClusterType(ClusterType.CloudManaged);
    cluster.setManagedState(ManagedState.Managed);
    cluster = clusterDao.persist(cluster);
    clusterId = cluster.getId();
    DataStoreProvider provider = providerMgr.getDataStoreProvider(DataStoreProvider.DEFAULT_PRIMARY);
    storage = new StoragePoolVO();
    storage.setDataCenterId(dcId);
    storage.setPodId(podId);
    storage.setPoolType(StoragePoolType.NetworkFilesystem);
    storage.setClusterId(clusterId);
    storage.setStatus(StoragePoolStatus.Up);
    storage.setScope(ScopeType.CLUSTER);
    storage.setUsedBytes(1000);
    storage.setCapacityBytes(20000);
    storage.setHostAddress(UUID.randomUUID().toString());
    storage.setPath(UUID.randomUUID().toString());
    storage.setStorageProviderName(provider.getName());
    storage = storagePoolDao.persist(storage);
    storagePoolId = storage.getId();
    storageMgr.createCapacityEntry(storage.getId());
    diskOffering = new DiskOfferingVO();
    diskOffering.setDiskSize(500);
    diskOffering.setName("test-disk");
    diskOffering.setSystemUse(false);
    diskOffering.setUseLocalStorage(false);
    diskOffering.setCustomized(false);
    diskOffering.setRecreatable(false);
    diskOffering = diskOfferingDao.persist(diskOffering);
    diskOfferingId = diskOffering.getId();
    volume = new VolumeVO(Volume.Type.ROOT, "volume", dcId, 1, 1, diskOffering.getId(), Storage.ProvisioningType.THIN, diskOffering.getDiskSize(), diskOffering.getMinIops(), diskOffering.getMaxIops(), "");
    volume = volumeDao.persist(volume);
    volumeId = volume.getId();
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) VolumeVO(com.cloud.storage.VolumeVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) HostPodVO(com.cloud.dc.HostPodVO)

Aggregations

ClusterVO (com.cloud.dc.ClusterVO)151 HostVO (com.cloud.host.HostVO)72 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)66 ArrayList (java.util.ArrayList)55 HostPodVO (com.cloud.dc.HostPodVO)46 DataCenterVO (com.cloud.dc.DataCenterVO)38 ConfigurationException (javax.naming.ConfigurationException)37 HashMap (java.util.HashMap)28 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)24 Map (java.util.Map)24 DiscoveryException (com.cloud.exception.DiscoveryException)21 DB (com.cloud.utils.db.DB)21 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)20 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 Account (com.cloud.user.Account)17 List (java.util.List)17 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)17 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)16 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)15 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)14