Search in sources :

Example 31 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class DomainJoinDaoImpl method newDomainResponse.

@Override
public DomainResponse newDomainResponse(final ResponseView view, final DomainJoinVO domain) {
    final DomainResponse domainResponse = new DomainResponse();
    domainResponse.setDomainName(domain.getName());
    domainResponse.setId(domain.getUuid());
    domainResponse.setLevel(domain.getLevel());
    domainResponse.setNetworkDomain(domain.getNetworkDomain());
    domainResponse.setEmail(domain.getEmail());
    domainResponse.setSlackChannelName(domain.getSlackChannelName());
    final Domain parentDomain = ApiDBUtils.findDomainById(domain.getParent());
    if (parentDomain != null) {
        domainResponse.setParentDomainId(parentDomain.getUuid());
    }
    final StringBuilder domainPath = new StringBuilder("ROOT");
    (domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
    domainResponse.setPath(domainPath.toString());
    if (domain.getParent() != null) {
        domainResponse.setParentDomainName(ApiDBUtils.findDomainById(domain.getParent()).getName());
    }
    if (domain.getChildCount() > 0) {
        domainResponse.setHasChild(true);
    }
    domainResponse.setState(domain.getState().toString());
    domainResponse.setNetworkDomain(domain.getNetworkDomain());
    final boolean fullView = (view == ResponseView.Full && domain.getId() == Domain.ROOT_DOMAIN);
    setResourceLimits(domain, fullView, domainResponse);
    // get resource limits for projects
    final long projectLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getProjectLimit(), fullView, ResourceType.project, domain.getId());
    final String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
    final long projectTotal = (domain.getProjectTotal() == null) ? 0 : domain.getProjectTotal();
    final String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
    domainResponse.setProjectLimit(projectLimitDisplay);
    domainResponse.setProjectTotal(projectTotal);
    domainResponse.setProjectAvailable(projectAvail);
    domainResponse.setObjectName("domain");
    return domainResponse;
}
Also used : DomainResponse(com.cloud.api.response.DomainResponse) Domain(com.cloud.legacymodel.domain.Domain)

Example 32 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class LdapImportUsersCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    List<LdapUser> users;
    try {
        if (StringUtils.isNotBlank(groupName)) {
            users = _ldapManager.getUsersInGroup(groupName);
        } else {
            users = _ldapManager.getUsers();
        }
    } catch (final NoLdapUserMatchingQueryException ex) {
        users = new ArrayList<>();
        s_logger.info("No Ldap user matching query. " + " ::: " + ex.getMessage());
    }
    final List<LdapUser> addedUsers = new ArrayList<>();
    for (final LdapUser user : users) {
        final Domain domain = getDomain(user);
        try {
            createCloudstackUserAccount(user, getAccountName(user), domain);
            addedUsers.add(user);
        } catch (final InvalidParameterValueException ex) {
            s_logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage());
        }
    }
    final ListResponse<LdapUserResponse> response = new ListResponse<>();
    response.setResponses(createLdapUserResponse(addedUsers));
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : NoLdapUserMatchingQueryException(com.cloud.ldap.NoLdapUserMatchingQueryException) LdapUser(com.cloud.ldap.LdapUser) ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) Domain(com.cloud.legacymodel.domain.Domain) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 33 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class CreateDomainCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    CallContext.current().setEventDetails("Domain Name: " + getDomainName() + ((getParentDomainId() != null) ? ", Parent DomainId :" + getParentDomainId() : ""));
    final Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain(), getDomainUUID(), getEmail(), getSlackChannelName());
    if (domain != null) {
        final DomainResponse response = _responseGenerator.createDomainResponse(domain);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create domain");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) DomainResponse(com.cloud.api.response.DomainResponse) Domain(com.cloud.legacymodel.domain.Domain)

Example 34 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class UserVmManagerImpl method checkHostsDedication.

private void checkHostsDedication(final VMInstanceVO vm, final long srcHostId, final long destHostId) {
    final HostVO srcHost = _hostDao.findById(srcHostId);
    final HostVO destHost = _hostDao.findById(destHostId);
    final boolean srcExplDedicated = checkIfHostIsDedicated(srcHost);
    final boolean destExplDedicated = checkIfHostIsDedicated(destHost);
    // if srcHost is explicitly dedicated and destination Host is not
    if (srcExplDedicated && !destExplDedicated) {
        // raise an alert
        final String msg = "VM " + vm.getInstanceName() + " is being migrated from a explicitly dedicated host " + srcHost.getName() + " to non-dedicated host " + destHost.getName();
        s_logger.info(msg);
    }
    // if srcHost is non dedicated but destination Host is explicitly dedicated
    if (!srcExplDedicated && destExplDedicated) {
        // raise an alert
        final String msg = "VM " + vm.getInstanceName() + " is being migrated from a non dedicated host " + srcHost.getName() + " to a explicitly dedicated host " + destHost.getName();
        s_logger.info(msg);
    }
    // Don't allow it when hosts are dedicated to different account/domains
    if (srcExplDedicated && destExplDedicated) {
        if (!(accountOfDedicatedHost(srcHost) == null || accountOfDedicatedHost(srcHost).equals(accountOfDedicatedHost(destHost)))) {
            final String msg = "Cannot migrate VM " + vm.getInstanceName() + " from host " + srcHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(srcHost) + " to host " + destHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(destHost);
            s_logger.error(msg);
            throw new InvalidParameterValueException(msg);
        }
        if (!(domainOfDedicatedHost(srcHost) == null || domainOfDedicatedHost(srcHost).equals(domainOfDedicatedHost(destHost)))) {
            final Domain srcDomain = _domainDao.findById(domainOfDedicatedHost(srcHost));
            String srcDomainName = domainOfDedicatedHost(srcHost).toString();
            if (srcDomain != null) {
                srcDomainName = srcDomain.getName();
            }
            final Domain destDomain = _domainDao.findById(domainOfDedicatedHost(destHost));
            String destDomainName = domainOfDedicatedHost(destHost).toString();
            if (destDomain != null) {
                destDomainName = destDomain.getName();
            }
            final String msg = "Cannot migrate VM " + vm.getInstanceName() + " from host " + srcHost.getName() + " explicitly dedicated to domain " + srcDomainName + " to " + "host " + destHost.getName() + " explicitly dedicated to domain " + destDomainName;
            s_logger.error(msg);
            throw new InvalidParameterValueException(msg);
        }
    }
    // Checks for implicitly dedicated hosts
    final ServiceOfferingVO deployPlanner = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
    if (deployPlanner.getDeploymentPlanner() != null && deployPlanner.getDeploymentPlanner().equals("ImplicitDedicationPlanner")) {
        // VM is deployed using implicit planner
        final long accountOfVm = vm.getAccountId();
        String msg = "VM of account " + accountOfVm + " with implicit deployment planner being migrated to host " + destHost.getName();
        // Get all vms on destination host
        boolean emptyDestination = false;
        final List<VMInstanceVO> vmsOnDest = getVmsOnHost(destHostId);
        if (vmsOnDest == null || vmsOnDest.isEmpty()) {
            emptyDestination = true;
        }
        if (!emptyDestination) {
            // Check if vm is deployed using strict implicit planner
            if (!isServiceOfferingUsingPlannerInPreferredMode(vm.getServiceOfferingId())) {
                // Check if all vms on destination host are created using strict implicit mode
                if (!checkIfAllVmsCreatedInStrictMode(accountOfVm, vmsOnDest)) {
                    msg = "VM of account " + accountOfVm + " with strict implicit deployment planner being migrated to host " + destHost.getName() + " not having all vms strict implicitly dedicated to account " + accountOfVm;
                }
            } else {
                // using implicit planner and must belong to same account
                for (final VMInstanceVO vmsDest : vmsOnDest) {
                    final ServiceOfferingVO destPlanner = _offeringDao.findById(vm.getId(), vmsDest.getServiceOfferingId());
                    if (!(destPlanner.getDeploymentPlanner() != null && destPlanner.getDeploymentPlanner().equals("ImplicitDedicationPlanner") && vmsDest.getAccountId() == accountOfVm)) {
                        msg = "VM of account " + accountOfVm + " with preffered implicit deployment planner being migrated to host " + destHost.getName() + " not having all vms implicitly dedicated to account " + accountOfVm;
                    }
                }
            }
        }
        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
        s_logger.warn(msg);
    } else {
        // VM is not deployed using implicit planner, check if it migrated between dedicated hosts
        final List<PlannerHostReservationVO> reservedHosts = _plannerHostReservationDao.listAllDedicatedHosts();
        boolean srcImplDedicated = false;
        boolean destImplDedicated = false;
        final String msg;
        for (final PlannerHostReservationVO reservedHost : reservedHosts) {
            if (reservedHost.getHostId() == srcHostId) {
                srcImplDedicated = true;
            }
            if (reservedHost.getHostId() == destHostId) {
                destImplDedicated = true;
            }
        }
        if (srcImplDedicated) {
            if (destImplDedicated) {
                msg = "VM is being migrated from implicitly dedicated host " + srcHost.getName() + " to another implicitly dedicated host " + destHost.getName();
            } else {
                msg = "VM is being migrated from implicitly dedicated host " + srcHost.getName() + " to shared host " + destHost.getName();
            }
            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
            s_logger.warn(msg);
        } else {
            if (destImplDedicated) {
                msg = "VM is being migrated from shared host " + srcHost.getName() + " to implicitly dedicated host " + destHost.getName();
                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
                s_logger.warn(msg);
            }
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PlannerHostReservationVO(com.cloud.deploy.PlannerHostReservationVO) Domain(com.cloud.legacymodel.domain.Domain) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HostVO(com.cloud.host.HostVO)

Example 35 with Domain

use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.

the class NiciraNvpElementTest method implementTest.

@Test
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getId()).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);
    mock(DeployDestination.class);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
}
Also used : Account(com.cloud.legacymodel.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.legacymodel.network.Network) Domain(com.cloud.legacymodel.domain.Domain) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Aggregations

Domain (com.cloud.legacymodel.domain.Domain)55 Account (com.cloud.legacymodel.user.Account)37 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)20 UserAccount (com.cloud.legacymodel.user.UserAccount)19 ArrayList (java.util.ArrayList)16 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)11 Project (com.cloud.projects.Project)11 DomainVO (com.cloud.domain.DomainVO)10 Network (com.cloud.legacymodel.network.Network)10 DomainResponse (com.cloud.api.response.DomainResponse)8 Pair (com.cloud.legacymodel.utils.Pair)7 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)7 HostVO (com.cloud.host.HostVO)6 List (java.util.List)6 Filter (com.cloud.utils.db.Filter)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)4 CloudAuthenticationException (com.cloud.legacymodel.exceptions.CloudAuthenticationException)4 NetworkVO (com.cloud.network.dao.NetworkVO)4