Search in sources :

Example 21 with DataCenterVO

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

the class ResourceManagerImpl method fillRoutingHostVO.

@Override
public HostVO fillRoutingHostVO(final HostVO host, final StartupRoutingCommand ssCmd, final HypervisorType hyType, Map<String, String> details, final List<String> hostTags) {
    if (host.getPodId() == null) {
        s_logger.error("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
        throw new IllegalArgumentException("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
    }
    final ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
    if (clusterVO.getHypervisorType() != hyType) {
        throw new IllegalArgumentException("Can't add host whose hypervisor type is: " + hyType + " into cluster: " + clusterVO.getId() + " whose hypervisor type is: " + clusterVO.getHypervisorType());
    }
    final Map<String, String> hostDetails = ssCmd.getHostDetails();
    if (hostDetails != null) {
        if (details != null) {
            details.putAll(hostDetails);
        } else {
            details = hostDetails;
        }
    }
    final HostPodVO pod = _podDao.findById(host.getPodId());
    final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    checkIPConflicts(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicNetmask());
    host.setType(com.cloud.host.Host.Type.Routing);
    host.setDetails(details);
    host.setCaps(ssCmd.getCapabilities());
    host.setCpuSockets(ssCmd.getCpuSockets());
    host.setCpus(ssCmd.getCpus());
    host.setTotalMemory(ssCmd.getMemory());
    host.setSpeed(ssCmd.getSpeed());
    host.setHypervisorType(hyType);
    host.setHypervisorVersion(ssCmd.getHypervisorVersion());
    host.setGpuGroups(ssCmd.getGpuGroupDetails());
    return host;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) HostPodVO(com.cloud.dc.HostPodVO)

Example 22 with DataCenterVO

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

the class ConfigurationServerImpl method createDefaultNetworks.

private void createDefaultNetworks() {
    List<DataCenterVO> zones = _dataCenterDao.listAll();
    long id = 1;
    HashMap<TrafficType, String> guruNames = new HashMap<TrafficType, String>();
    guruNames.put(TrafficType.Public, PublicNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Management, PodBasedNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Control, ControlNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Storage, StorageNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Guest, DirectPodBasedNetworkGuru.class.getSimpleName());
    for (DataCenterVO zone : zones) {
        long zoneId = zone.getId();
        long accountId = 1L;
        Long domainId = zone.getDomainId();
        if (domainId == null) {
            domainId = 1L;
        }
        // Create default networks - system only
        List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
        for (NetworkOfferingVO offering : ntwkOff) {
            if (offering.isSystemOnly()) {
                long related = id;
                long networkOfferingId = offering.getId();
                Mode mode = Mode.Static;
                String networkDomain = null;
                BroadcastDomainType broadcastDomainType = null;
                TrafficType trafficType = offering.getTrafficType();
                boolean specifyIpRanges = false;
                if (trafficType == TrafficType.Management) {
                    broadcastDomainType = BroadcastDomainType.Native;
                } else if (trafficType == TrafficType.Storage) {
                    broadcastDomainType = BroadcastDomainType.Native;
                    specifyIpRanges = true;
                } else if (trafficType == TrafficType.Control) {
                    broadcastDomainType = BroadcastDomainType.LinkLocal;
                } else if (offering.getTrafficType() == TrafficType.Public) {
                    if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) || zone.getNetworkType() == NetworkType.Basic) {
                        specifyIpRanges = true;
                        broadcastDomainType = BroadcastDomainType.Vlan;
                    } else {
                        continue;
                    }
                }
                if (broadcastDomainType != null) {
                    NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null, offering.getRedundantRouter());
                    network.setGuruName(guruNames.get(network.getTrafficType()));
                    network.setDns1(zone.getDns1());
                    network.setDns2(zone.getDns2());
                    network.setState(State.Implemented);
                    _networkDao.persist(network, false, getServicesAndProvidersForNetwork(networkOfferingId));
                    id++;
                }
            }
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) HashMap(java.util.HashMap) Mode(com.cloud.network.Networks.Mode) StorageNetworkGuru(com.cloud.network.guru.StorageNetworkGuru) PublicNetworkGuru(com.cloud.network.guru.PublicNetworkGuru) ControlNetworkGuru(com.cloud.network.guru.ControlNetworkGuru) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) PodBasedNetworkGuru(com.cloud.network.guru.PodBasedNetworkGuru) DirectPodBasedNetworkGuru(com.cloud.network.guru.DirectPodBasedNetworkGuru) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) DirectPodBasedNetworkGuru(com.cloud.network.guru.DirectPodBasedNetworkGuru) TrafficType(com.cloud.network.Networks.TrafficType)

Example 23 with DataCenterVO

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

the class NetworkOrchestrator method shutdownNetwork.

@Override
@DB
public boolean shutdownNetwork(final long networkId, final ReservationContext context, final boolean cleanupElements) {
    NetworkVO network = _networksDao.findById(networkId);
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("Network is already shutdown: " + network);
        return true;
    }
    if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
        s_logger.debug("Network is not implemented: " + network);
        return false;
    }
    try {
        //do global lock for the network
        network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
        if (network == null) {
            s_logger.warn("Unable to acquire lock for the network " + network + " as a part of network shutdown");
            return false;
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown");
        }
        if (network.getState() == Network.State.Allocated) {
            s_logger.debug("Network is already shutdown: " + network);
            return true;
        }
        if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
            s_logger.debug("Network is not implemented: " + network);
            return false;
        }
        if (isSharedNetworkWithServices(network)) {
            network.setState(Network.State.Shutdown);
            _networksDao.update(network.getId(), network);
        } else {
            try {
                stateTransitTo(network, Event.DestroyNetwork);
            } catch (final NoTransitionException e) {
                network.setState(Network.State.Shutdown);
                _networksDao.update(network.getId(), network);
            }
        }
        final boolean success = shutdownNetworkElementsAndResources(context, cleanupElements, network);
        final NetworkVO networkFinal = network;
        final boolean result = Transaction.execute(new TransactionCallback<Boolean>() {

            @Override
            public Boolean doInTransaction(final TransactionStatus status) {
                boolean result = false;
                if (success) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
                    }
                    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, networkFinal.getGuruName());
                    final NetworkProfile profile = convertNetworkToNetworkProfile(networkFinal.getId());
                    guru.shutdown(profile, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
                    applyProfileToNetwork(networkFinal, profile);
                    final DataCenterVO zone = _dcDao.findById(networkFinal.getDataCenterId());
                    if (isSharedNetworkOfferingWithServices(networkFinal.getNetworkOfferingId()) && zone.getNetworkType() == NetworkType.Advanced) {
                        networkFinal.setState(Network.State.Setup);
                    } else {
                        try {
                            stateTransitTo(networkFinal, Event.OperationSucceeded);
                        } catch (final NoTransitionException e) {
                            networkFinal.setState(Network.State.Allocated);
                            networkFinal.setRestartRequired(false);
                        }
                    }
                    _networksDao.update(networkFinal.getId(), networkFinal);
                    _networksDao.clearCheckForGc(networkId);
                    result = true;
                } else {
                    try {
                        stateTransitTo(networkFinal, Event.OperationFailed);
                    } catch (final NoTransitionException e) {
                        networkFinal.setState(Network.State.Implemented);
                        _networksDao.update(networkFinal.getId(), networkFinal);
                    }
                    result = false;
                }
                return result;
            }
        });
        return result;
    } finally {
        if (network != null) {
            _networksDao.releaseFromLockTable(network.getId());
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Lock is released for network " + network + " as a part of network shutdown");
            }
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkProfile(com.cloud.network.NetworkProfile) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) NetworkGuru(com.cloud.network.guru.NetworkGuru) TransactionStatus(com.cloud.utils.db.TransactionStatus) DB(com.cloud.utils.db.DB)

Example 24 with DataCenterVO

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

the class NetworkOrchestrator method reallocate.

@DB
@Override
public boolean reallocate(final VirtualMachineProfile vm, final DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException {
    final VMInstanceVO vmInstance = _vmDao.findById(vm.getId());
    final DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId());
    if (dc.getNetworkType() == NetworkType.Basic) {
        final List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
        final NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
        final LinkedHashMap<Network, List<? extends NicProfile>> profiles = new LinkedHashMap<Network, List<? extends NicProfile>>();
        profiles.put(network, new ArrayList<NicProfile>());
        Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientCapacityException {
                cleanupNics(vm);
                allocate(vm, profiles);
            }
        });
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NicVO(com.cloud.vm.NicVO) DB(com.cloud.utils.db.DB)

Example 25 with DataCenterVO

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

the class TemplateTest method setUp.

@Test(priority = -1)
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    // 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();
    imageStore = new ImageStoreVO();
    imageStore.setName("test");
    imageStore.setDataCenterId(dcId);
    imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
    imageStore.setRole(DataStoreRole.Image);
    imageStore.setUrl(this.getSecondaryStorage());
    imageStore.setUuid(UUID.randomUUID().toString());
    imageStore.setProtocol("nfs");
    imageStore = imageStoreDao.persist(imageStore);
    VMTemplateVO 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.setImageDataStoreId(storeId);
    image = templateDao.persist(image);
    templateId = image.getId();
    // inject mockito
    LocalHostEndpoint ep = new LocalHostEndpoint();
    ep.setResource(new MockLocalNfsSecondaryStorageResource());
    Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
    Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LocalHostEndpoint(org.apache.cloudstack.storage.LocalHostEndpoint) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) MockLocalNfsSecondaryStorageResource(org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) Test(org.testng.annotations.Test)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)214 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)53 HostVO (com.cloud.host.HostVO)42 Account (com.cloud.user.Account)37 NetworkVO (com.cloud.network.dao.NetworkVO)35 DomainRouterVO (com.cloud.vm.DomainRouterVO)33 HostPodVO (com.cloud.dc.HostPodVO)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 ClusterVO (com.cloud.dc.ClusterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 DB (com.cloud.utils.db.DB)26 Network (com.cloud.network.Network)25 HashMap (java.util.HashMap)25 ConfigurationException (javax.naming.ConfigurationException)25 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)20 Test (org.junit.Test)20 NicProfile (com.cloud.vm.NicProfile)19 ActionEvent (com.cloud.event.ActionEvent)18