Search in sources :

Example 56 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testTrashFail.

@Test
public void testTrashFail() {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsNetworkVlanMappingVO mapping = mock(BrocadeVcsNetworkVlanMappingVO.class);
    when(mapping.getVlanId()).thenReturn(14);
    when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
    when(vcsmapdao.remove(anyLong())).thenReturn(true);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = mock(List.class);
    when(devices.isEmpty()).thenReturn(true);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final boolean result = guru.trash(network, offering);
    assertTrue(result == false);
    verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) Test(org.junit.Test)

Example 57 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testReserve.

@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, URISyntaxException, InsufficientAddressCapacityException {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    final NicProfile nic = mock(NicProfile.class);
    when(nic.getMacAddress()).thenReturn("macaddress");
    when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
    final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenterVO dc = mock(DataCenterVO.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(dcdao.findById((long) anyInt())).thenReturn(dc);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final AssociateMacToNetworkAnswer answer = mock(AssociateMacToNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    guru.reserve(nic, network, vmProfile, dest, res);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) ReservationContext(com.cloud.vm.ReservationContext) AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) DeployDestination(com.cloud.deploy.DeployDestination) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 58 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testTrash.

@Test
public void testTrash() {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsNetworkVlanMappingVO mapping = mock(BrocadeVcsNetworkVlanMappingVO.class);
    when(mapping.getVlanId()).thenReturn(14);
    when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final DeleteNetworkAnswer answer = mock(DeleteNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    when(vcsdao.remove((long) anyInt())).thenReturn(true);
    final boolean result = guru.trash(network, offering);
    assertTrue(result == true);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DeleteNetworkAnswer(com.cloud.agent.api.DeleteNetworkAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) Test(org.junit.Test)

Example 59 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class NetscalerElement method deleteNetscalerControlCenter.

@DB
@Override
public boolean deleteNetscalerControlCenter(DeleteNetscalerControlCenterCmd cmd) throws CloudRuntimeException {
    NetScalerControlCenterVO result = _netscalerControlCenterDao.findByUuid(cmd.getId());
    if (result == null) {
        throw new CloudRuntimeException("External Netscaler Control Center Table does not contain record with this ID");
    } else {
        // ID list of Network Offering which are not removed and have service Package Uuid field not null.
        List<Long> servicePackageId_list = _networkOfferingDao.listNetworkOfferingID();
        if (servicePackageId_list.size() != 0) {
            // VO list of Networks  which are using Network Offering.
            List<NetworkVO> networkVO_list = _networkDao.listNetworkVO(servicePackageId_list);
            if (networkVO_list != null && networkVO_list.size() != 0) {
                throw new CloudRuntimeException("ServicePackages published by NetScalerControlCenter are being used by NetworkOfferings. Try deleting NetworkOffering with ServicePackages and then delete NetScalerControlCenter.");
            }
        }
    }
    try {
        _netscalerServicePackageDao.removeAll();
    } catch (CloudRuntimeException ce) {
        throw new CloudRuntimeException("Service Package is being used by Network Offering, Try deleting Network Offering and then delete Service Package.");
    }
    // delete Netscaler Control Center
    _netscalerControlCenterDao.remove(result.getId());
    // Removal of  NCC from Host Table
    List<HostVO> ncc_list = _hostDao.listAll();
    if (ncc_list == null) {
        throw new CloudRuntimeException("Could not find Netscaler Control Center in Database");
    }
    for (HostVO ncc : ncc_list) {
        if (ncc.getType().equals(Host.Type.NetScalerControlCenter)) {
            try {
                // put the host in maintenance state in order for it to be deleted
                ncc.setResourceState(ResourceState.Maintenance);
                _hostDao.update(ncc.getId(), ncc);
                _resourceMgr.deleteHost(ncc.getId(), false, false);
            } catch (Exception e) {
                s_logger.debug(e);
                return false;
            }
        }
    }
    return true;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) JSONException(org.json.JSONException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) DB(com.cloud.utils.db.DB)

Example 60 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class NetscalerElement method allocateNCCResourceForNetwork.

public HostVO allocateNCCResourceForNetwork(Network guestConfig) throws ConfigurationException {
    Map<String, String> _configs;
    List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll();
    HostVO hostVO = null;
    if (ncc.size() > 0) {
        NetScalerControlCenterVO nccVO = ncc.get(0);
        String ipAddress = nccVO.getNccip();
        Map hostDetails = new HashMap<String, String>();
        String hostName = "NetscalerControlCenter";
        hostDetails.put("name", hostName);
        hostDetails.put("guid", UUID.randomUUID().toString());
        hostDetails.put("zoneId", Long.toString(guestConfig.getDataCenterId()));
        hostDetails.put("ip", ipAddress);
        hostDetails.put("username", nccVO.getUsername());
        hostDetails.put("password", DBEncryptionUtil.decrypt(nccVO.getPassword()));
        hostDetails.put("deviceName", "netscaler control center");
        hostDetails.put("cmdTimeOut", Long.toString(NumbersUtil.parseInt(_configDao.getValue(Config.NCCCmdTimeOut.key()), 600000)));
        ServerResource resource = new NetScalerControlCenterResource();
        resource.configure(hostName, hostDetails);
        final Host host = _resourceMgr.addHost(guestConfig.getDataCenterId(), resource, Host.Type.NetScalerControlCenter, hostDetails);
        hostVO = _hostDao.findById(host.getId());
    }
    return hostVO;
}
Also used : HashMap(java.util.HashMap) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) Map(java.util.Map) HashMap(java.util.HashMap) NetScalerControlCenterResource(com.cloud.network.resource.NetScalerControlCenterResource) HostVO(com.cloud.host.HostVO)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46