use of com.cloud.domain.Domain in project CloudStack-archive by CloudStack-extras.
the class ListDomainChildrenCmd method execute.
@Override
public void execute() {
List<? extends Domain> result = _domainService.searchForDomainChildren(this);
ListResponse<DomainResponse> response = new ListResponse<DomainResponse>();
List<DomainResponse> domainResponses = new ArrayList<DomainResponse>();
for (Domain domain : result) {
DomainResponse domainResponse = _responseGenerator.createDomainResponse(domain);
domainResponse.setObjectName("domain");
domainResponses.add(domainResponse);
}
response.setResponses(domainResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.domain.Domain in project cloudstack by apache.
the class CiscoVnmcElementTest method implementTest.
@Test
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
URI uri = URI.create("vlan://123");
Network network = mock(Network.class);
when(network.getId()).thenReturn(1L);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
when(network.getDataCenterId()).thenReturn(1L);
when(network.getGateway()).thenReturn("1.1.1.1");
when(network.getBroadcastUri()).thenReturn(uri);
when(network.getCidr()).thenReturn("1.1.1.0/24");
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(1L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
DeployDestination dest = mock(DeployDestination.class);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("d1");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("a1");
ReservationContext context = mock(ReservationContext.class);
when(context.getDomain()).thenReturn(dom);
when(context.getAccount()).thenReturn(acc);
DataCenter dc = mock(DataCenter.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
when(_entityMgr.findById(DataCenter.class, network.getDataCenterId())).thenReturn(dc);
List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
devices.add(mock(CiscoVnmcControllerVO.class));
when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
CiscoAsa1000vDeviceVO asaVO = mock(CiscoAsa1000vDeviceVO.class);
when(asaVO.getInPortProfile()).thenReturn("foo");
when(asaVO.getManagementIp()).thenReturn("1.2.3.4");
List<CiscoAsa1000vDeviceVO> asaList = new ArrayList<CiscoAsa1000vDeviceVO>();
asaList.add(asaVO);
when(_ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(asaList);
when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
when(_networkAsa1000vMapDao.findByAsa1000vId(anyLong())).thenReturn(null);
when(_networkAsa1000vMapDao.persist(any(NetworkAsa1000vMapVO.class))).thenReturn(mock(NetworkAsa1000vMapVO.class));
when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)).thenReturn(true);
ClusterVSMMapVO clusterVsmMap = mock(ClusterVSMMapVO.class);
when(_clusterVsmMapDao.findByClusterId(anyLong())).thenReturn(clusterVsmMap);
CiscoNexusVSMDeviceVO vsmDevice = mock(CiscoNexusVSMDeviceVO.class);
when(vsmDevice.getUserName()).thenReturn("foo");
when(vsmDevice.getPassword()).thenReturn("bar");
when(vsmDevice.getipaddr()).thenReturn("1.2.3.4");
when(_vsmDeviceDao.findById(anyLong())).thenReturn(vsmDevice);
HostVO hostVO = mock(HostVO.class);
when(hostVO.getId()).thenReturn(1L);
when(_hostDao.findById(anyLong())).thenReturn(hostVO);
Ip ip = mock(Ip.class);
when(ip.addr()).thenReturn("1.2.3.4");
PublicIp publicIp = mock(PublicIp.class);
when(publicIp.getAddress()).thenReturn(ip);
when(publicIp.getState()).thenReturn(IpAddress.State.Releasing);
when(publicIp.getAccountId()).thenReturn(1L);
when(publicIp.isSourceNat()).thenReturn(true);
when(publicIp.getVlanTag()).thenReturn("123");
when(publicIp.getGateway()).thenReturn("1.1.1.1");
when(publicIp.getNetmask()).thenReturn("1.1.1.1");
when(publicIp.getMacAddress()).thenReturn(null);
when(publicIp.isOneToOneNat()).thenReturn(true);
when(_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(publicIp);
VlanVO vlanVO = mock(VlanVO.class);
when(vlanVO.getVlanGateway()).thenReturn("1.1.1.1");
List<VlanVO> vlanVOList = new ArrayList<VlanVO>();
when(_vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId())).thenReturn(vlanVOList);
Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(_agentMgr.easySend(anyLong(), any(CreateLogicalEdgeFirewallCommand.class))).thenReturn(answer);
when(_agentMgr.easySend(anyLong(), any(ConfigureNexusVsmForAsaCommand.class))).thenReturn(answer);
when(_agentMgr.easySend(anyLong(), any(SetSourceNatCommand.class))).thenReturn(answer);
when(_agentMgr.easySend(anyLong(), any(AssociateAsaWithLogicalEdgeFirewallCommand.class))).thenReturn(answer);
assertTrue(_element.implement(network, offering, dest, context));
}
use of com.cloud.domain.Domain in project cloudstack by apache.
the class NetworkProviderTest method dbSyncTest.
@Test
public void dbSyncTest() {
Network network = lookupTestNetwork("test-db-only-net");
if (network == null) {
network = createTestNetwork("test-db-only-net");
}
UserVm vm = _server.createVM("test-db-only-vm", network);
try {
createFloatingIp(network, vm);
} catch (Exception e) {
fail("unable to create floating ip");
}
/* reset ApiServer objects to default config only, so above created objects
* exists only in cludstack db but not in api server
*/
((ApiConnectorMock) _api).initConfig();
/* reset model cached objects */
_contrailMgr.getDatabase().initDb();
/* Create one object of each type directly in api-server - these objects does not exist in cloudstack */
net.juniper.contrail.api.types.Domain domain = new net.juniper.contrail.api.types.Domain();
domain.setName("test-vnc-only-domain--1");
domain.setUuid(UUID.randomUUID().toString());
try {
assertTrue(_api.create(domain));
} catch (IOException ex) {
fail(ex.getMessage());
}
Project project = new Project();
project.setName("test-vnc-only-project-1");
project.setUuid(UUID.randomUUID().toString());
project.setParent(domain);
try {
assertTrue(_api.create(project));
} catch (IOException ex) {
fail(ex.getMessage());
}
VirtualNetwork net = new VirtualNetwork();
net.setName("test-vnc-only-net-1");
net.setUuid(UUID.randomUUID().toString());
net.setParent(project);
NetworkIpam ipam = null;
try {
// Find default-network-ipam
String ipam_id = _api.findByName(NetworkIpam.class, null, "default-network-ipam");
assertNotNull(ipam_id);
ipam = (NetworkIpam) _api.findById(NetworkIpam.class, ipam_id);
assertNotNull(ipam);
} catch (IOException ex) {
fail(ex.getMessage());
}
VnSubnetsType subnet = new VnSubnetsType();
subnet.addIpamSubnets(new SubnetType("10.0.2.0", 24), "10.0.2.254");
net.addNetworkIpam(ipam, subnet);
VirtualMachine vncVm = new VirtualMachine();
vncVm.setName("test-vnc-only-vm-1");
try {
assertTrue(_api.create(vncVm));
} catch (IOException ex) {
fail(ex.getMessage());
}
VirtualMachineInterface vmi = new VirtualMachineInterface();
vmi.setParent(vncVm);
vmi.setName("test-vnc-only-vmi-1");
try {
assertTrue(_api.create(vmi));
assertTrue(_api.create(net));
} catch (IOException ex) {
fail(ex.getMessage());
}
InstanceIp ip_obj = new InstanceIp();
ip_obj.setName(net.getName() + ":0");
ip_obj.setVirtualNetwork(net);
ip_obj.setVirtualMachineInterface(vmi);
try {
assertTrue(_api.create(ip_obj));
// Must perform a GET in order to update the object contents.
assertTrue(_api.read(ip_obj));
assertNotNull(ip_obj.getAddress());
} catch (IOException ex) {
fail(ex.getMessage());
}
//now db sync
if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_UPDATE) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
s_logger.info("# Cloudstack DB & VNC are out of sync - resync done");
}
if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_CHECK) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
s_logger.info("# Cloudstack DB & VNC are still out of sync");
fail("DB Sync failed");
}
}
use of com.cloud.domain.Domain in project cloudstack by apache.
the class VxlanGuestNetworkGuruTest method testImplement.
@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById(anyLong())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
when(physnet.getId()).thenReturn(42L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(42L);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
//TODO(VXLAN): doesn't support VNI specified
//when(confsvr.getConfigValue((String) any(), (String) any(), anyLong())).thenReturn("true");
when(dcdao.allocateVnet(anyLong(), anyLong(), anyLong(), (String) any(), eq(true))).thenReturn("42");
doNothing().when(guru).allocateVnetComplete((Network) any(), (NetworkVO) any(), anyLong(), anyLong(), (String) any(), eq("42"));
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null);
}
use of com.cloud.domain.Domain in project cloudstack by apache.
the class ResourceLimitManagerImpl method searchForLimits.
@Override
public List<ResourceLimitVO> searchForLimits(Long id, Long accountId, Long domainId, Integer type, Long startIndex, Long pageSizeVal) {
Account caller = CallContext.current().getCallingAccount();
List<ResourceLimitVO> limits = new ArrayList<ResourceLimitVO>();
boolean isAccount = true;
if (!_accountMgr.isAdmin(caller.getId())) {
accountId = caller.getId();
domainId = null;
} else {
if (domainId != null) {
// verify domain information and permissions
Domain domain = _domainDao.findById(domainId);
if (domain == null) {
// return empty set
return limits;
}
_accountMgr.checkAccess(caller, domain);
if (accountId != null) {
// Verify account information and permissions
Account account = _accountDao.findById(accountId);
if (account == null) {
// return empty set
return limits;
}
_accountMgr.checkAccess(caller, null, true, account);
domainId = null;
}
}
}
// Map resource type
ResourceType resourceType = null;
if (type != null) {
try {
resourceType = ResourceType.values()[type];
} catch (ArrayIndexOutOfBoundsException e) {
throw new InvalidParameterValueException("Please specify a valid resource type.");
}
}
// If id is passed in, get the record and return it if permission check has passed
if (id != null) {
ResourceLimitVO vo = _resourceLimitDao.findById(id);
if (vo.getAccountId() != null) {
_accountMgr.checkAccess(caller, null, true, _accountDao.findById(vo.getAccountId()));
limits.add(vo);
} else if (vo.getDomainId() != null) {
_accountMgr.checkAccess(caller, _domainDao.findById(vo.getDomainId()));
limits.add(vo);
}
return limits;
}
// If account is not specified, default it to caller account
if (accountId == null) {
if (domainId == null) {
accountId = caller.getId();
isAccount = true;
} else {
isAccount = false;
}
} else {
isAccount = true;
}
SearchBuilder<ResourceLimitVO> sb = _resourceLimitDao.createSearchBuilder();
sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
SearchCriteria<ResourceLimitVO> sc = sb.create();
Filter filter = new Filter(ResourceLimitVO.class, "id", true, startIndex, pageSizeVal);
if (accountId != null) {
sc.setParameters("accountId", accountId);
}
if (domainId != null) {
sc.setParameters("domainId", domainId);
sc.setParameters("accountId", (Object[]) null);
}
if (resourceType != null) {
sc.setParameters("type", resourceType);
}
List<ResourceLimitVO> foundLimits = _resourceLimitDao.search(sc, filter);
if (resourceType != null) {
if (foundLimits.isEmpty()) {
if (isAccount) {
limits.add(new ResourceLimitVO(resourceType, findCorrectResourceLimitForAccount(_accountMgr.getAccount(accountId), resourceType), accountId, ResourceOwnerType.Account));
} else {
limits.add(new ResourceLimitVO(resourceType, findCorrectResourceLimitForDomain(_domainDao.findById(domainId), resourceType), domainId, ResourceOwnerType.Domain));
}
} else {
limits.addAll(foundLimits);
}
} else {
limits.addAll(foundLimits);
// see if any limits are missing from the table, and if yes - get it from the config table and add
ResourceType[] resourceTypes = ResourceCount.ResourceType.values();
if (foundLimits.size() != resourceTypes.length) {
List<String> accountLimitStr = new ArrayList<String>();
List<String> domainLimitStr = new ArrayList<String>();
for (ResourceLimitVO foundLimit : foundLimits) {
if (foundLimit.getAccountId() != null) {
accountLimitStr.add(foundLimit.getType().toString());
} else {
domainLimitStr.add(foundLimit.getType().toString());
}
}
// get default from config values
if (isAccount) {
if (accountLimitStr.size() < resourceTypes.length) {
for (ResourceType rt : resourceTypes) {
if (!accountLimitStr.contains(rt.toString()) && rt.supportsOwner(ResourceOwnerType.Account)) {
limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForAccount(_accountMgr.getAccount(accountId), rt), accountId, ResourceOwnerType.Account));
}
}
}
} else {
if (domainLimitStr.size() < resourceTypes.length) {
for (ResourceType rt : resourceTypes) {
if (!domainLimitStr.contains(rt.toString()) && rt.supportsOwner(ResourceOwnerType.Domain)) {
limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForDomain(_domainDao.findById(domainId), rt), domainId, ResourceOwnerType.Domain));
}
}
}
}
}
}
return limits;
}
Aggregations